Programming thread

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.
I was trying to do that but you still have to use a regular expression. Atleast, I'm pretty sure you do.

If I can't figure it out I'll probably just do something niggerlicious like making an entire array with the alphabet in it, and using a loop to check each character in the string against the array because fuck regexpressions.
Some interesting facts about characters. ASCII characters are just numbers. You can (usually) directly compare characters the same way you can numbers. For example:
Code:
('a' < 'c') && ('c'  < 'z')
So if you check that your input character in lower case is between a and z you don't have to do anything ugly with loops, or regex for that matter.

My experience has been that regex is generally overkill unless it's in an interface where the regex is part of your input, ie. grep, sed
 
I was trying to do that but you still have to use a regular expression. Atleast, I'm pretty sure you do.

If I can't figure it out I'll probably just do something niggerlicious like making an entire array with the alphabet in it, and using a loop to check each character in the string against the array because fuck regexpressions.

Edit: In fact. I might just sit down and write the niggerlicious array string function tomorrow as a shitpost.
in Python it's just: mylist=re.findall(r'([A-Za-z]+)', string)
Code:
>>> import re
>>> print (re.findall(r'([A-Za-z]+)',"moo cows moo wowowowo344rd4fde"))
['moo', 'cows', 'moo', 'wowowowo', 'rd', 'fde']

Looks like, maybe matchAll in JS?
 
  • Informative
Reactions: BIG BILL HELL'S
There is a videogame by Zach Barth(Zachtronics) called TIS-100 that would function as a great introduction to this concept which is why I'm not too worried about touching ASM.
TIS-100 is amusing but it's nothing like any real programming language even if the syntax is sort of assembler-like. You'll be shooting yourself in the foot if you actually try learning from it.
 
What language are you working in? You mentioned .innerText before so I will assume HTML/JavaScript. You can do as you have mentioned here and simply do a for loop over an array of 'accepted' characters.

You could also use a regex directly on the string.replace() function with
Code:
/[^a-zA-Z0-9 ]/g
as the pattern. That would match and replace (with nothing) anything that IS NOT a letter/character or number, including a " "/space character. This is from a quick google as no one should ever know how to do regex from memory as that would make them tainted.
Yeah, its Javascript. Also, I tried looking it up again and I saw string.replace() on stack overflow. This post as well as some of the other replies I got were pretty helpful, thank you.

I'm sippin a beer and winding down and I'll have another crack at it in the morning. I'm pretty new at coding and I pretty much just jumped into it completely blind so sometimes I run into stuff that's confusing and then I get imposter syndrome. On the bright side, the loop I made to check if its a palindrome worked on the first try so I shouldn't be too hard on myself lol.

JavaScript:
function reverse(str){
  let revStr = "";
  //reverse string
  for(let i = str.length -1; i >= 0; i--){
    if(revStr == ""){
      revStr = str[i];
    } else {
      revStr += str[i]
    }
  }
  return revStr
}

There is another function that calls this one. I'm not done with that yet. I could post it, but I'm worried someone else will finish writing the function for me and that feels like cheating. Getting pointers and advice is one thing but as a rule I never copy and paste code, because then I'll never actually get good at programming.

I think I'm gonna try to figure out the rest from here so I can really retain the knowledge but if anyone is interested I'll post the completed function when I'm done.
 
This is the exact sort of shit that makes it impossible to take Rust seriously.
The crates in question are not official rust crates and only have around 3000 total downloads ever on crates.io. This is a cherry-picked example of a troon doing weird stuff as they usually do and is not a representative example of crates that are actually used by real people. Cargo already has official benchmarking support built-in, this "diol" benchmarking library is just some troon doing things that already exist for no reason in a worse way than what is officially supported.

This is basically on-par with the countless packages, libraries and repositories online that nobody will ever seriously download and use because better options already exist, and their existence shouldn't be used as an example for why a programming language itself is good or bad. If you follow this to the logical extreme, it is impossible to take any programming language seriously because someone out there in the world wrote shit code, reimplemented things that already existed, injected their weird sexual fetish into their project, or all of those things in that programming language and then posted it online. This is obviously ridiculous.
 
it is impossible to take any programming language seriously because someone out there in the world ... injected their weird sexual fetish into their project
Yet Rust is the only language that frequently has people coding in it one-handed.
 
So I decided to redo Advent of Code, first time I did it was with C# and I heard that doing projects like this helps with learning a language. While doing this problem in C I discovered a solution that was 10x better easier and better than my first attempt. With C# I used a list to take every digit from each string, then concatenating the first and last element of the list. I realized that I could’ve just done two loops, one starting from the beginning of the string and one from the end of the string both stopping once they hit the digit in that direction. This both made me feel stupid and ecstatic at the same time.
C:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

static int pullNums(char *line){
    //purpose is to filter all the numbers in the line
    int f, b;
    char res[3] = {0};
    f=0;
    b = strlen(line) - 1;

    while(!isdigit(line[f]) && line[f] != '\0')
        f++;
    res[0] = line[f];

    while(!isdigit(line[b]) && b > 0)
        b--;
    res[1] = line[b];
    if(!isdigit(res[0]) || !isdigit(res[1]))
        res[0]=res[1]='0';

    res[2] = '\0';

    printf("Calibration number: %s\n", res);

    return atoi(res);
}

static void parseFile(FILE *f){
    //read lines held here
    char reading[100][100];
    int r, c, parseSum, l;

    r=c=parseSum=0;

    while((l = fgetc(f)) != EOF){
        reading[r][c++] = l;
        if((l == '\n')||(l == EOF)){
            if(l == '\n'){
                c-=1;
            }
            reading[r][c] = '\0';
            parseSum += pullNums(reading[r++]);
            //printf("%s\n", reading[r]);
            c=0;
            }//end if
    }//end while loop
    parseSum += pullNums(reading[r]); //<-- extra pullnums because the while
    //loop doesn't go through all of r
    printf("Final calibration is: %d\n", parseSum);
}

int main(void) {
   //printf("Hello, World!\n");
    FILE *ipfi;

    ipfi = fopen("InFile.txt", "r");

    if(ipfi == NULL){
        printf("No such file found. Try again.\n");
        return 1;
    }

    parseFile(ipfi);

    fclose(ipfi);
   return 0;
}
My only problem so far is that for some reason, the program won’t read the last line unless there’s a line after it. Can’t quite figure out why, if you have any guesses I’m happy to hear them.
 
My only problem so far is that for some reason, the program won’t read the last line unless there’s a line after it. Can’t quite figure out why, if you have any guesses I’m happy to hear them.
The while loop in parseFile stops when you reach EOF, even though the code inside of it expects to be executed when the char is EOF. You either need a do while or do another break condition for the loop.
 
  • Like
Reactions: Chiang Kai-shek
Yeah, its Javascript. Also, I tried looking it up again and I saw string.replace() on stack overflow. This post as well as some of the other replies I got were pretty helpful, thank you.
If I was doing it, I'd first convert the whole string to lowercase, then I'd use string.replace(/[^a-z]/g, '') to remove all the characters that are supposed to be ignored. Then I'd use a simple loop starting at both ends of the string, comparing the characters from both ends, and stepping in toward the middle.
 
  • Agree
Reactions: Benzo Samurai
Fucking regex is so confusing. I'm trying to make a palindrome checker that ignores special characters so my function only reads the letters in the string and I just can't figure out how it works because I'm so god damn fucking retarded.
I know from a later post that you solved your problem an other way, but I still wanted to add here that writing a palindrome checker in Regex is impossible, or if you allow some engines with heavy modifications at least super tedious.
StackOverflow answer explaining it's impossible
And here is a StackOverflow answer explaining how a modified engine can do this.
It's unnecessarily complicated and really better done in code.
I'm sippin a beer and winding down and I'll have another crack at it in the morning. I'm pretty new at coding and I pretty much just jumped into it completely blind so sometimes I run into stuff that's confusing and then I get imposter syndrome. On the bright side, the loop I made to check if its a palindrome worked on the first try so I shouldn't be too hard on myself lol.
It's only natural. Switching from "I'm a coding god" to "I have no idea" is very common in programming.
 
JavaScript:
const txtInput = document.querySelector('#text-input');
const resultTxt = document.getElementById('rslt-txt');
resultTxt.innerText = "Type anything you want into the box above and check if it is a palindrome!";

const checkBtn = document.querySelector('#check-btn');
checkBtn.onclick = check;

function check(value){
  value = txtInput.value;
  value = value.replace(/[^a-zA-Z0-9]/g,"")
  value = value.toLowerCase();
  console.log(value)
  if(value == ""){
    return alert('Please input a value');
  } else{
    if(value == reverse(value)){
      value = txtInput.value;
      resultTxt.innerText = `${value} is a palindrome.`
    } else {
      value = txtInput.value
      resultTxt.innerText = `${value} is not a palindrome.`
    }
  }
}

function reverse(str){
  let revStr = "";
  //reverse string
  for(let i = str.length -1; i >= 0; i--){
    if(revStr == ""){
      revStr = str[i];
    } else {
      revStr += str[i];
    }
  }
  return revStr;
}

Figured it out. Wasn't as complicated as I thought. Thanks for the tips guys.
 
  • Like
Reactions: Hall of Cost Payer
I know from a later post that you solved your problem an other way, but I still wanted to add here that writing a palindrome checker in Regex is impossible, or if you allow some engines with heavy modifications at least super tedious.
I initially read it the same way, but he was just trying to use regex to do some pre-parsing.

You'd need recursion to write a palindrome test in regex, if the string to test is arbitrary length. It's basically the same problem as balancing parentheses. Instead of parentheses, you're balancing identical characters at the beginning and end of the string.

If the string to test has a known max length, you could do something like /^([a-z]|)([a-z]|)([a-z]|)([a-z]|)\4?\3\2\1$/i (if you want it to ignore non-alpha, stick a bunch of [^a-z]* in it)
 
Last edited:
  • Agree
Reactions: y a t s
The crates in question are not official rust crates and only have around 3000 total downloads ever on crates.io. This is a cherry-picked example of a troon doing weird stuff as they usually do and is not a representative example of crates that are actually used by real people. Cargo already has official benchmarking support built-in, this "diol" benchmarking library is just some troon doing things that already exist for no reason in a worse way than what is officially supported.

This is basically on-par with the countless packages, libraries and repositories online that nobody will ever seriously download and use because better options already exist, and their existence shouldn't be used as an example for why a programming language itself is good or bad. If you follow this to the logical extreme, it is impossible to take any programming language seriously because someone out there in the world wrote shit code, reimplemented things that already existed, injected their weird sexual fetish into their project, or all of those things in that programming language and then posted it online. This is obviously ridiculous.
I agree with this point at face value, but my point was more that the crates in question are so archetypally Rust Community™ to the point of being identical to parody; it's all very on the nose. This is the community they foster, actively forcing the "real people" you mention, like ourselves, who aren't depraved coomers into silence. As such, it would be significantly less funny or noteworthy if it were done in literally any other language.

In other words: the "Rust tranny" stereotype exists so infamously for a reason.
 
I agree with this point at face value, but my point was more that the crates in question are so archetypally Rust Community™ to the point of being identical to parody; it's all very on the nose. This is the community they foster, actively forcing the "real people" you mention, like ourselves, who aren't depraved coomers into silence. As such, it would be significantly less funny or noteworthy if it were done in literally any other language.

In other words: the "Rust tranny" stereotype exists so infamously for a reason.
The language itself should not be dismissed as a useful tool on this basis.

I am convinced a lot of the tranny stuff surrounding both rust and programming in general is specifically designed to make normal people opt themselves out of certain good technologies such as rust. If you (god forbid) actually look into these "programming" communities, the gay shilling basically amounts to "Look at this heckin troon using $good_technology, you wouldn't wanna use that $good_technology too would you, chud?", using the very natural disgust reflex that most people have to opt themselves out of that $good_technology.

Seeing as the "lmao rust tranny" meme is quite popular online, this pattern has been a tremendously successful way to psyop the best tech into being culturally skewed towards them and their goals as well as getting the heckin' chuds to categorically opt themselves out of using otherwise good and often superior technologies, out of disgust for the "people" who """actually use""" (post loudly in discord communities) them.
 
I figured out something that I want to build in C.

I play or at least used to play a lot of Grand Strategy games by Paradox. One issue that comes up when you are playing multiplayer is rehosting where you have to transfer the save game to every person in the multiplayer lobby. This can sometimes take upwards of a minute or even longer as these save games can get up to 10 megabytes or 100 megabytes sometimes even close to a gigabyte if it is a big game and it has gone on for a long time. When this happens it means the process of rehosting can take 5-10 minutes especially if someone's connection is a bit slower.

These save game files are essentially just scripting files stored as a text file with variables written out with something like "{London craftsmen = 300123 }" to represent there being 300123 craftsmen in London but for every single entity in the game.

However these save games are essentially just text and they are the same every time meaning I can make something that parses this save game text file and then stores all that information extremely simply and then transfers it where it gets reverse parsed into the save game text file.


Thoughts, questions, and suggestions? This is your opportunity to wax poetically or wax autistically about any detail of this project I'd like to work on.

The language itself should not be dismissed as a useful tool on this basis.
But the Rust foundation has a lot of power over the language and has made some concerning moves. I have reasons to never write anything in Rust other than the community but the community does not help and it is a real problem.
 
Rust is theoretically a good language: Compile-time memory safety? I like that. Not much else though. Time to sperg illiterately and probably also somewhat wrongly: (Even if you correct me it's still hopeless because most rust code does this stupid shit and I hate it)

so: rust is theoretically usable but it has one of those gay AIDS-riddled language-specific package managers that you can't reasonably sidestep and i hate them so much i can't properly express my hatred for them without glowing brightly enough to blind everybody in this thread
the docs are like "YES JUST DOWNLOAD SHIT FROM CRATES.IO!" like FUCK YOU NIGGER THAT'S WHAT MY SYSTEM PACKAGE MANAGER IS FOR WHY CAN'T YOU HAVE A FUCKING SYSTEM PACKAGE FOR WHATEVER SHIT EVERYBODY USES BUT ISN'T IN THE STDLIB (like random numbers)
also it uses static linking all the goddamn time so you make a helloworld app and then it's 1.2 megabytes because "le storage space is cheap or something" like fuck you nigger maybe i wanted to use that space for something else than 47265695 copies of the same 3 libraries
also minor nitpick but the syntax at a glance looks nastier than C++ and you actually have to try really hard to make it that fucked up, just stop trying to pack stupid trendy shit into ALGOL-derived langauges it just doesn't end well (you heard it right: I'm saying that "learning curve" is just the time it takes to develop stockholm syndrome for the shit fucking language design)

good job guys (she/her pronouns) nice language 10/10 i fucking despise it and everything it stands for and i want to burn it to the ground and salt the hard drive platters where the toolchain was made so a horrid tragedy like this won't happen again anytime soon
 
rust is theoretically usable but it has one of those gay AIDS-riddled language-specific package managers that you can't reasonably sidestep
You can completely sidestep cargo and use rustc if you want, use a makefile, whatever. There's nothing stopping you and it is just as easy as with your C compiler of choice.

WHY CAN'T YOU HAVE A FUCKING SYSTEM PACKAGE FOR WHATEVER SHIT EVERYBODY USES BUT ISN'T IN THE STDLIB (like random numbers)
You were going to import a CSPRNG library for cryptographic stuff anyways also /dev/urandom and /dev/random

THAT'S WHAT MY SYSTEM PACKAGE MANAGER IS FOR WHY CAN'T YOU HAVE A FUCKING SYSTEM PACKAGE
Debian tried this and it was a failure, the reason you don't want dynamically linked system packages is because you want to be able to take advantage of the rich rust type system which includes using types from other libraries and passing trait impls across the boundary between libraries and programs. When you dynamic link, you have to conform to the lowest common denominator that the loader library provided by your OS supports, which is in every case the C ABI. You can't propagate rust's rich type system across the C ABI boundary between programs and libraries. This is also the reason for static linking. It is a reasonable tradeoff considering hard drive space is incredibly cheap and mmap is basically OS-level magic as far as the average systems programmer is concerned.

it uses static linking all the goddamn time so you make a helloworld app and then it's 1.2 megabytes
Static linking also solves the problem of relying on a dynamic linker when shipping your binaries, if you static link, all the stuff you need is already there. If you dynamic link, you have to pray that whoever consumes your binary has all the things your binary asks the loader for, and also pray they have an ABI-compatible version installed. This isn't an issue when you statically link your libraries. This again, is totally worth the tradeoff and streamlines deployment. Also, the option for dynamic linking is there for rust if you really really want it.

the syntax at a glance looks nastier than C++
Have you seen C++ template syntax? It's about as bad as rust's explicit lifetime syntax. Complaints about syntax, especially ones that concern aesthetics are purely a skill issue.

But the Rust foundation has a lot of power over the language and has made some concerning moves.
The behaviour of the rust foundation is a valid reason to not use rust. I don't particularly care about the few "controversies", they all amount to nothing regarding the technical aspects of the language and ecosystem.

the community does not help and it is a real problem
The great thing about """online communities""" is that you can completely ignore and disregard them. They don't exist outside of their horrific discord server(s), probably some fediverse instances somewhere and reddit. They don't exist in the real world outside of some annual conferences that you can just not attend.
 
I figured out something that I want to build in C.

I play or at least used to play a lot of Grand Strategy games by Paradox. One issue that comes up when you are playing multiplayer is rehosting where you have to transfer the save game to every person in the multiplayer lobby. This can sometimes take upwards of a minute or even longer as these save games can get up to 10 megabytes or 100 megabytes sometimes even close to a gigabyte if it is a big game and it has gone on for a long time. When this happens it means the process of rehosting can take 5-10 minutes especially if someone's connection is a bit slower.

These save game files are essentially just scripting files stored as a text file with variables written out with something like "{London craftsmen = 300123 }" to represent there being 300123 craftsmen in London but for every single entity in the game.

However these save games are essentially just text and they are the same every time meaning I can make something that parses this save game text file and then stores all that information extremely simply and then transfers it where it gets reverse parsed into the save game text file.


Thoughts, questions, and suggestions? This is your opportunity to wax poetically or wax autistically about any detail of this project I'd like to work on.
How is this any different from just transferring the text file to the client? Are you storing this data locally for some reason instead of downloading it? If you are storing it, why are you not just using a DBMS or document storage system to manage this data? I understand wanting to do C stuff at a low level, but maybe stay in your lane as a beginner and use working storage solutions like mongodb and SQLlite or H2.
 
Back