Programming thread


Is my code niggerlicious?

JavaScript:
let price = 3.26;

let cid = [
  ["PENNY", 1.01],
  ["NICKEL", 2.05,
  ["DIME", 3.1],
  ["QUARTER", 4.26],
  ["ONE", 90],
  ["FIVE", 55],
  ["TEN", 20],
  ["TWENTY", 60],
  ["ONE HUNDRED", 100]
];

let initCID = [
  ["PENNY", 0],
  ["NICKEL", 0],
  ["DIME", 0],
  ["QUARTER", 0],
  ["ONE", 0],
  ["FIVE", 0],
  ["TEN", 0],
  ["TWENTY", 0],
  ["ONE HUNDRED", 0]
]

function findInititalCID(){
  for(let i = 0; i < cid.length; i++){
    initCID[i][1] = cid[i][1]
  }
  console.log(initCID);
}
function initCash(){
  for(let i=0; i < cid.length; i++){
    cid[i][1] = initCID[i][1];
  }
  return cidDisplayUpdate();
}

let totalCID = 0;
function funds(){
  totalCID = 0
  let x = 0;
  totalCID = 0;
  for(let i = 0; i < cid.length; i++){
    let y = cid[i][1]
    x = parseFloat((x+y).toFixed(2));
  }
  return totalCID = x;
}

// number input
const cash = document.querySelector("#cash")

//purchase button
const purchaseButton = document.querySelector("#purchase-btn");
purchaseButton.onclick = purchase;

//price
const pDisplay = document.querySelector("#price");
pDisplay.innerText = `Price: $${price}`;

//change due
const displayChangeDue = document.querySelector("#change-due");

//Variables for the cid display
const penny = document.querySelector("#penny");
penny.innerText = `$${cid[0][1]}`;
const nickel = document.querySelector("#nickel");
nickel.innerText = `$${cid[1][1]}`;
const dime = document.querySelector("#dime");
dime.innerText = `$${cid[2][1]}`;
const quarter = document.querySelector("#quarter");
quarter.innerText = `$${cid[3][1]}`;
const one = document.querySelector("#one");
one.innerText = `$${cid[4][1]}`;
const five = document.querySelector("#five");
five.innerText = `$${cid[5][1]}`;
const ten = document.querySelector("#ten");
ten.innerText = `$${cid[6][1]}`;
const twenty = document.querySelector("#twenty");
twenty.innerText = `$${cid[7][1]}`;
const hundred = document.querySelector("#hundred");
hundred.innerText = `$${cid[8][1]}`;

//Variables for the change-due element
const open = "OPEN";
const close = "CLOSED"
const insufficientFunds = "<p>Status: INSUFFICIENT_FUNDS</p>"

//function to update cid display
function cidDisplayUpdate(){
  penny.innerText = `$${cid[0][1]}`;
  nickel.innerText = `$${cid[1][1]}`;
  dime.innerText = `$${cid[2][1]}`;
  quarter.innerText = `$${cid[3][1]}`;
  one.innerText = `$${cid[4][1]}`;
  five.innerText = `$${cid[5][1]}`;
  ten.innerText = `$${cid[6][1]}`;
  twenty.innerText = `$${cid[7][1]}`;
  hundred.innerText = `$${cid[8][1]}`;
}

//calculate change back function
function calculate(x){
  cidDisplayUpdate();
  let y = (x*1).toFixed(2);
  x = parseFloat(y);

  if(x == 0){
    return console.log('Complete')
  } else if (x < 0){
   return console.log(`ERROR! X: ${x}`)
  } else {
    if(cid[8][1] > 0 && x >= 100){ //ONE HUNDRED
      y = cid[8][1]/100
      x -= y*100
      cid[8][1] -= y*100;
      console.log(x, y, cid[8][1]);
      displayChangeDue.innerHTML += `<p>${cid[8][0]}: $${y*100}</p>`
      return calculate(x);
    }
    if(cid[7][1] > 0 && x >= 20){ //TWENTY
      if(Math.floor(x/20) > cid[7][1]/20){
        y = (cid[7][1] / 20)
      } else {
        y = Math.floor(x/20)
      }
      x -= y*20
      cid[7][1] -= y*20;
      console.log(x, y, cid[7][1]);
      displayChangeDue.innerHTML += `<p>${cid[7][0]}: $${y*20}</p>`
      return calculate(x);
    }
        if(cid[6][1] > 0 && x >= 10){ //TEN
      if(Math.floor(x/10) > cid[6][1]/10){
        y = (cid[6][1] / 10)
      } else {
        y = Math.floor(x/10)
      }
      x -= y*10
      cid[6][1] -= y*10;
      displayChangeDue.innerHTML += `<p>${cid[6][0]}: $${y*10}</p>`
      return calculate(x);
    }
    if(cid[5][1] > 0 && x >= 5){//FIVE
    if(Math.floor(x/5) > cid[5][1]/5){
      y = (cid[5][1] / 5)
    } else {
      y = Math.floor(x/5)
    }
    x -= y*5
    cid[5][1] -= y*5
    displayChangeDue.innerHTML += `<p>${cid[5][0]}: $${y*5}</p>`
    return calculate(x)
    }
    if(cid[4][1] > 0 && x >= 1){//One
      if(Math.floor(x) > cid[4][1]){
        y = cid[4][1];
      } else {
        y = Math.floor(x)
      }
      x -= y;
      cid[5][1] -= y;
      displayChangeDue.innerHTML += `<p>${cid[4][0]}: $${y}</p>`
      return calculate(x)
    }
    if(cid[3][1] > 0 && x >= 0.25){ //Quarter
      if(Math.floor(x/0.25) > (cid[3][1] /0.25)){
        y = cid[3][1]/0.25
      } else {
        y = Math.floor(x/0.25)
      }
      x -= parseFloat((y*0.25).toFixed(2))
      cid[3][1] -= parseFloat((y*0.25).toFixed(2))
      displayChangeDue.innerHTML += `<p>${cid[3][0]}: $${y*0.25}</p>`
      return calculate(x)
    }
    if(cid[2][1] > 0 && x >= 0.1){ //Dime
      if(Math.floor(x/0.1) > (cid[2][1] /0.1)){
        y = cid[2][1]/0.1
      } else {
        y = Math.floor(x/0.1)
      }
      x -= parseFloat((y*0.1).toFixed(2));
      cid[2][1] -= parseFloat((y*0.1).toFixed(2));
      displayChangeDue.innerHTML += `<p>${cid[2][0]}: $${y*0.1}</p>`
      return calculate(x)
    }
    if(cid[1][1] > 0 && x >= 0.05){ //NICKEL
      if(Math.floor(x/0.05) > (cid[1][1] / 0.05)){
        y = cid[1][1]/0.05
      } else {
        y = Math.floor(x/0.05)
      }
      x -= parseFloat((y*0.05).toFixed(2))
      cid[1][1] -= parseFloat((y*0.05).toFixed(2))
      displayChangeDue.innerHTML += `<p>${cid[1][0]}: $${y*0.05}</p>`
      return calculate(x)
    }
        if(cid[0][1] > 0 && x >= 0.01){ //PENNY
      if(Math.floor(x/0.01) > (cid[0][1] / 0.01)){
        y = cid[0][1]/0.01
      } else {
        y = Math.floor(x/0.01)
      }
      x -= parseFloat((y*0.01).toFixed(2))
      cid[0][1] -= parseFloat((y*0.01).toFixed(2))
      displayChangeDue.innerHTML += `<p>${cid[0][0]}: $${y*0.01}</p>`
      return calculate(x)
    } else {
      displayChangeDue.innerHTML = `${insufficientFunds}`;
      return initCash();
    }
  }
}

//purchase function
function purchase(){
  funds();
  console.log("CID:" + totalCID);

 let changeDue = (cash.value - price).toFixed(2);
 console.log("Change:" + changeDue)
 findInititalCID();
  if(cash.value < price){
    return alert("Customer does not have enough money to purchase the item");
  } else if(cash.value == price){
   return displayChangeDue.innerHTML = "<p> No change due - customer paid with exact cash </p>";
  } else if (totalCID < changeDue){
    return displayChangeDue.innerHTML = `${insufficientFunds}`;
  } else if(totalCID == changeDue){
      displayChangeDue.innerHTML = `<p>Status: Closed</p>`
      return calculate(changeDue);
    } else {
      displayChangeDue.innerHTML = `<p>Status: OPEN</p>`
      return calculate(changeDue);
    }
  }


JavaScript:
x = parseFloat((x+y).toFixed(2));
Also Mfw this actually worked.
 
Is my code niggerlicious?
I notice that the set of if statements could easily be turned into a loop to reduce the repetitive chunks. Any time you find yourself repeating the same sort of logic like that, look for ways you can write it as a function or loop.

Something like:
JavaScript:
var denoms = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01]; // No 50?

var cl = cid.length;
var dl = denoms.length;

if (cl < dl)
    handleThatShit();

for (var i = 0; i < dl; i++) {
    var ci = cl - i - 1;
    if (cid[ci][1] > 0 && x >= denoms[i]) {
        ...
    }
}

Also, I'm happy to see "niggerlicious" catching on here. It's my favorite Terry-ism.
 
Last edited:
Terry always makes me smile.
Terry.gif
 
Okay, now I'm trying to chuck that CRUD app that worked perfectly on my desktop onto Vercel and I don't fucking understand how to put a database into this thing. Vercel has its own database thing but I have no idea how to fucking use it or how to fucking connect it afterwards and all the tutorials are focused on some other random fucking shit and are useless. Great
 
  • Thunk-Provoking
Reactions: Belisarius Cawl
I feel like I'm missing something with C. It seems too easy and memory management doesn't seem to be as important of a factor as I thought it was. I understand Hexadecimal and memory addresses.

Understanding structs and pointers is not that difficult at all. I'm sure I'm missing some of the more complicated version of these things and I'll figure it when I build one of these things that is more complicated.

I heard all this massive stuff about memory management in C and I understand you want to prevent Buffer Overflows, memory leaks, and trying to call memory that has already been freed. But why does everyone freak out about memory management in C and does it come up/do you have to think about it except in those cases of the three things I mentioned?

It just feels like C is too easy and I fear I'm missing something important. C is not supposed to be easy and it feels only slightly more complicated than Python. I must be missing something.
 
I feel like I'm missing something with C. It seems too easy and memory management doesn't seem to be as important of a factor as I thought it was. I understand Hexadecimal and memory addresses.

Understanding structs and pointers is not that difficult at all. I'm sure I'm missing some of the more complicated version of these things and I'll figure it when I build one of these things that is more complicated.

I heard all this massive stuff about memory management in C and I understand you want to prevent Buffer Overflows, memory leaks, and trying to call memory that has already been freed. But why does everyone freak out about memory management in C and does it come up/do you have to think about it except in those cases of the three things I mentioned?

It just feels like C is too easy and I fear I'm missing something important. C is not supposed to be easy and it feels only slightly more complicated than Python. I must be missing something.
The general attack surface is overflows. Things like C strings usually being null terminated is a good one. In the beginning there was strcpy() which blindly copied a string, it never checked if the target was big enough. Now you have strncpy() where you tell it how many bytes. BUT if the source is too long it doesn't stick a \0 on the end for you. So if you blindly use the target string you're likely to walk off the end of the string into other data.

And there are hundreds of these little gotchas you can hit. Today's compilers MIGHT notice some of them but it's all on you. C's primary purpose is to load the gun and aim it at your foot.

Don't get me wrong, I love C when I need absolute performance or low level stuff, but when dealing with "Humans" and their "Inputs" I stick to stuff like Python.
 
I feel like I'm missing something with C. It seems too easy and memory management doesn't seem to be as important of a factor as I thought it was. I understand Hexadecimal and memory addresses.

Understanding structs and pointers is not that difficult at all. I'm sure I'm missing some of the more complicated version of these things and I'll figure it when I build one of these things that is more complicated.

I heard all this massive stuff about memory management in C and I understand you want to prevent Buffer Overflows, memory leaks, and trying to call memory that has already been freed. But why does everyone freak out about memory management in C and does it come up/do you have to think about it except in those cases of the three things I mentioned?

It just feels like C is too easy and I fear I'm missing something important. C is not supposed to be easy and it feels only slightly more complicated than Python. I must be missing something.
C is extremely simple and easy to write, but it's easy to introduce really weird bugs and security vulnerabilities through various kinds of UB, which can be triggered in an unending number of ways. It's always a very good idea to thoroughly test security-critical C code. There are methods to compile binaries with special instrumentation that finds possible issues in ways that static analysis can't. If you use this instrumentation in tandem with thorough tests that trigger a lot of code paths (regular test suites and/or fuzzing), you are quite unlikely to run into problems.

To reduce the potential for error, you could try writing only the most performance-critical subroutines in C and having the rest of the logic done in Lua (or another scripting language.) Lua is easy to embed (in fact, that is literally what it's designed for) and can be used for all of those complicated, error-prone-in-C tasks that don't use large amounts of CPU time.

I think there's a bit of Reddit-style cargo cult fear around C. Yes, you can fuck up and shoot yourself in the foot sometimes, but modern development tools can help you to find out how and where you shot yourself in the foot and then you can deal with the wound. People just like to treat it as the memory-management equivalent of Malbolge where you can literally never know if the next pointer will SIGSEGV when dereferenced.
 
Its not that hard to write good C. You can 'introduce attack surfaces' but I wouldn't say there are an unending number of ways. TBH usually the issue at this point is some library betrayed you or something. As far as buffer overflows yea thats bad and all but pretty easy to avoid, just check your array indexes are in bounds and don't use user input for a format string in printf and so-on.
 
And there are hundreds of these little gotchas you can hit.
I C #include <laughtrack.h>

No, jokes aside this makes sense anytime you have dynamic stuff you can get weird interactions that can mean stuff stops working correctly. This is not limited to software, stuff like this comes up all the time the obvious example(that everyone picks) is something like the Tacoma Narrows Bridge which worked fine except the wind interacted with the bridge in a bad way and caused it to collapse.

You have to think about the strange interactions that can happen at every point along the curve of every reasonably scenario. You can't design for the entire curve, because it would be too expensive, but you can design for enough of it to fulfill the design requirements.
C is extremely simple and easy to write, but it's easy to introduce really weird bugs and security vulnerabilities through various kinds of UB
Its not that hard to write good C.
That is good to know I had this massive fear that I was really missing something.

The building blocks are simple but can and will be assembled into a manner which is complicated. Terry Davis is, somehow, even more correct than I thought he was. A genius truly does admire simplicity and an idiot truly does admire complexity.
I think there's a bit of Reddit-style cargo cult fear around C.
I figured this was true, but I under corrected. I figured it was way overblown but there was a bit of truth to it. But it turns out it is incredibly overblown and you just need to pay attention and plan for it with some checks for certain things.
 
That is good to know I had this massive fear that I was really missing something.

The building blocks are simple but can and will be assembled into a manner which is complicated. Terry Davis is, somehow, even more correct than I thought he was. A genius truly does admire simplicity and an idiot truly does admire complexity.
99% of what Terry said about computers is exactly the fucking truth. He might have been a lolcow but he wasn't a retard. Focus on simplicity and you'll often get speed, robustness, safety, security, and quality for free.
I figured this was true, but I under corrected. I figured it was way overblown but there was a bit of truth to it. But it turns out it is incredibly overblown and you just need to pay attention and plan for it with some checks for certain things.
If C really was that bad, we would be writing all of our operating systems in languages like Ada. Instead, it's like 10% that bad and people use it more than other languages because it's generally better in many other ways.
Side note: I'd like to see a memory-safe systems programming language but every time people try to do it they make an overcomplicated shitty abomination from hell. (:_(
Redditors are the type of people that instead of checking inputs they just assume exception handling/try/catch will handle it all. They shouldn't be allowed any computing device more complicated than an etch-a-sketch.
Or they assume that because they're using a memory-safe language there will be no bugs. Then some dynamic typing shitshow happens and an exception propagates to the main loop. My Python programs crash a whole lot more than my C programs. Maybe it's a good thing to use a language that keeps you on your toes.
 
It just feels like C is too easy and I fear I'm missing something important. C is not supposed to be easy and it feels only slightly more complicated than Python. I must be missing something.
One of my search techniques is going on Google Books and using the ability to search for keywords within books to find relevant material before I pirate it. I remember using Valgrind many years ago to find memory leaks in C programs I was writing and went looking for 'valgrind c' on Google Books. 21st Century C was among the results and has great reviews:


"Similar items that may deliver to you quickly" (distance doesn't matter in this context but regardless) also turns up quite a few promising results.
 
  • Winner
Reactions: Napoleon III
1716110863956.png

I will say my project is working surprisingly well and building it has not taken nearly as long as I thought it would.

This is a test on a small test file with 8 lines of code. The file I want to eventually read has something like 5 million lines though a lot of it is boilerplate.
1716111035571.png


I'm not quite ready to scale up to 5 million lines. Trying to do so required too much memory and caused VScode to crash. You don't have to tell me how to fix this I'll figure it out, its just the problem I'm currently on.

I'm moving fast and because of that I feel like I'm learning a lot which is good and what I want. But I still run into issues which means I know that I'm really actually learning and not just copying what someone else has written.

Thanks for everyone's advice and help. It's been useful.
I have heard of Valgrind from a tutorial actually.

"Similar items that may deliver to you quickly" (distance doesn't matter in this context but regardless) also turns up quite a few promising results.
I will say programming textbooks are often extremely readable and easy to understand.

This is a good idea for some of the more complex ideas of things you can do with C. I'll probably grab this as an alternative to trying to find tutorials. I found a bunch of tutorials for the syntax of C but not a lot on some of the more advanced stuff.
 
  • Winner
Reactions: Belisarius Cawl
I also think people use potential safety issues as excuse not to admit that it assblasts them that it doesn't come with many convenience things that are a given in more modern languages and then it develops to that redditor thing where everyone just repeats what the other one said for updoots and the people saying these things end up not even understanding them. (This is how you breed rust cultists btw.) Many "approaches to coding" (really attitudes) that are potentially "dangerous" in C usually do not lead to good and bug free code in "safer" languages either. Also a lot of these modern conviniences come with paradigms intrinsic to the language in question you are then beholden to, paradigms I often find make the language not simple to use at all. That's the thing with complexity, you can't make it magically disappear.

It's often said that posix sh or bash is the first class citizen programming language in Linux. That's not true. It's actually C. With some basic C knowledge and a few lines of code, you can do some very advanced stuff with the Linux kernel.

That said - Forth, Lisp, maybe Smalltalk (if you can get past the alien approach). These are fun, simple (simpler than C, Cs syntax is actually quite complex if you think about it, although I suppose it is less abstract) and elegant languages you basically expand on the fly for the problem at hand, something you can't really do with C. Is it always necessary or does it lead to a better solution though? Probably not, otherwise we'd all read this on our lisp machines now.
 
I notice that the set of if statements could easily be turned into a loop to reduce the repetitive chunks. Any time you find yourself repeating the same sort of logic like that, look for ways you can write it as a function or loop.

Something like:
JavaScript:
var denoms = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01]; // No 50?

var cl = cid.length;
var dl = denoms.length;

if (cl < dl)
    handleThatShit();

for (var i = 0; i < dl; i++) {
    var ci = cl - i - 1;
    if (cid[ci][1] > 0 && x >= denoms[i]) {
        ...
    }
}

Also, I'm happy to see "niggerlicious" catching on here. It's my favorite Terry-ism.

Yeah, when I was writing the function I thought that the math was gonna be different for quarters dimes etc so I decided to use if statements and go over each denom one by one.
Once I realized I was wrong I said fuck it, I'm not gonna rewrite that function again.

I might try redoing it another time for some practice. But thank you for the advice. The more I code the harder it gets, and seeing as I'm mostly teaching myself and I never spent a day in college, I genuinely appreciate the help people offer me.
 
I'll excuse myself preemptively if this is not quite the right thread for this but I wanted to share a site I found and see if I am not insane for thinking this guy screams lolcow. It is a site for programming so I hope it fits well enough.

I have been looking for good information about reverse engineering or rather game hacking specifically and I found this site https://guidedhacking.com/ which seems to be a great resource about actually writing the things instead of buying them, all combined with a YT channel. Aside from the fact that it actually might be interesting for someone here for its contents, I want to direct your attention to the Admin, Rake, which gives of the same overly hostile vibes as the that GrapheneOS dev or DrewDevault of Wayland fame.
Take for example a look at the rules page
gh-1.png

Now, I am no stranger to people in some tech communities being overly direct or even somewhat dismissive so telling people to not be idiots seems alright enough but when you start to mention that you ban 3-5 paid users (there is a paywall) a day this starts to sound suspicious irrespective of the reasons given. Further then he goes on to call his community, which he seems to be rather proud of in places where he promotes the site, 99% pathetic losers which makes this even weirder. Why host this site then?
Notice the aggressive limiting of posts for "guests" which prevent you from even reading the rules before singing up.

Further, take note of the footer he has offering a glowing review of himself in 3rd person.
gh-2.png


Or as a last piece to justify my curiosity here another post about a seemingly cool and innocuous project where he then proceeds to mainly rant about other developers... seeking out his knowledge which he is so proud about.
gh-3.png

Now, maybe the community is indeed this garbage and he is just frustrated after years and years but if any of you know about the other tech personalities with this kind of attitude you will know that it is usually more due to them being borderline insane opposed to the community haunting them that much. I wanted to share this because not only does it feel like he could be belligerent enough to be interesting but also because maybe someone else here has had contact with him or the Forum at large. Sorry again if it doesn't exactly fit but this is the best thread I could find.
 
I have been looking for good information about reverse engineering
I don't have a ton of immediate thoughts about this Rake guy or his site, but I recognize the site name from my time in the cheat engine community many years ago.

If you want some good resources, check out https://exploit.education for a good primer on memory corruption and crafting your own exploits. For games specifically, Vector 35 has a CTF called Pwn Adventure, and there's also the CheatTheGame (RIP Chris) youtube channel. Cheat engine's built-in tutorial is really solid too. Cheat engine is a world class debugger, and you can learn a lot from fucking around in it. Once you're reasonably comfortable with assembly, you can do some really fun stuff like causing ammo to increase every time you reload.

While looking for the youtube channel, I ended up learning he (CheatTheGame) died about 2 years ago, and I found a page on the GuidedHacking site about his passing. They block my VPN, so I tried looking at a Wayback Machine cache, but the site appears to be manually excluded from archiving. Interesting.
 
Anyone have a tutorial on isolating unreal engine signatures. I am looking for FName_ToString for ue4SS
 
Last edited:
Back