Programming thread

I am starting to understand regex better and yeah its fucking complicated but the more I learn the more I realize that nothing is ever as complicated as it seems.

I ended up making a telephone validator for freecodecamp and regex was the most simple way to do it.

I'm considering making a youtube channel once I get some more knowledge under my belt, and I'll do Javascript tutorials where I talk like the dude from Idiocracy.

Yeah, coding is hard. But that is because the computer is retarded, not me. Once you realize its dumb and you approach it like its fucking dumb its honestly way easier.

"The console says you're fucked up. You code like a fag, and your shits all retarded."
 
I should learn Rust
don't do this you will gain several severe mental illnesses from all the trendy functionalshit and nodejs developer mindset elements packed around that lovecraftian abomination
then the rest of your plan won't work because you'll no longer be a normal person
 
I am starting to understand regex better and yeah its fucking complicated but the more I learn the more I realize that nothing is ever as complicated as it seems.
Here's a nice cheatsheet duckduckgo gives for regex.
regex_cheatsheet.png
It's all just identifying patterns. Imo it only really gets complicated when you start using assertions, and a lot of regex engines don't even support them fully.

My favorite trick for quickly pulling stuff like URLs from files is the non-greedy capture .*?. I use [^"]* a lot with HTML too.
 
Anyway, I can't ask on 4chan's stupid questions thread because the site is shitting itself so I'll ask here-

I'm trying to make a react crud app with nodejs mysql backend, as one does, but I can't figure out where the database, like, goes. Do I put a .db file in one of the folders? Where?
 
Anyway, I can't ask on 4chan's stupid questions thread because the site is shitting itself so I'll ask here-

I'm trying to make a react crud app with nodejs mysql backend, as one does, but I can't figure out where the database, like, goes. Do I put a .db file in one of the folders? Where?
So, mysql is actually another program that your backend is going to interact with as though it is a server. That means what you're looking for is a port to interact with, not a file. When you run mysql it will start listening for connections to localhost:3306 by default. Mysql is a database *manager* and it will handle actually storing your database to disk.
 
  • Like
Reactions: Marvin
Anyway, I can't ask on 4chan's stupid questions thread because the site is shitting itself so I'll ask here-

I'm trying to make a react crud app with nodejs mysql backend, as one does, but I can't figure out where the database, like, goes. Do I put a .db file in one of the folders? Where?
Where MySQL keeps its data should be a configuration property of the daemon. You run a MySQL server concurrently with your app and it connects over some sort of local socket. If you're using the system's default MySQL service, the database itself probably lives somewhere in /var if I had to guess. Understand how your app connects to it and set it up to make proper connections.

* This is based on the assumption that node is doing things the normal way. I have no faith in JS programmers doing things the normal way. The library you're using could be abstracting over shit like spawning processes by itself or something deviant like that. Who knows?
 
Ah. I'd begun to suspect something like that, as all the tutorials I watched had some MySQL program open at the same time, but none of them actually explained it. Also I remembered I'd actually made a node script that read/wrote to a database file so I could probably just do that too. I can probably figure it out now, thanks.
 
Ah. I'd begun to suspect something like that, as all the tutorials I watched had some MySQL program open at the same time, but none of them actually explained it. Also I remembered I'd actually made a node script that read/wrote to a database file so I could probably just do that too. I can probably figure it out now, thanks.
So you really don't even need to install MySQL if you want. There are a bunch of RDBMS that can be ran on a local file system if you are just making a toy. SQLite is one such RDBMS that node probably has a package for. I learned everything I knew about databases from the book below and I used to make 6 figs.

81o1Ceyx+YL._AC_UF1000,1000_QL80_.jpg
 
So you really don't even need to install MySQL if you want. There are a bunch of RDBMS that can be ran on a local file system if you are just making a toy. SQLite is one such RDBMS that node probably has a package for. I learned everything I knew about databases from the book below and I used to make 6 figs.

View attachment 5997888
>making 6 figs off a manga guide to databases
Living the dream, man... I mean, I'm making a toy for now just to get something up and running, but I would like to be able to put out professional-level work and maybe you know get a job at some point.

Anyway, I've now advanced to "Client does not support authentication protocol requested by server; consider upgrading MySQL client". Which is neat because I literally just installed MySQL so it really ought to be the latest version already.
 
Anyway, I've now advanced to "Client does not support authentication protocol requested by server; consider upgrading MySQL client". Which is neat because I literally just installed MySQL so it really ought to be the latest version already.
If I had to guess, that just means you have to configure the server to use something that your client library supports. Root around in /etc violently until you find something.
 
Anyway, I've now advanced to "Client does not support authentication protocol requested by server; consider upgrading MySQL client". Which is neat because I literally just installed MySQL so it really ought to be the latest version already.
Node's mysql package is fucked and doesn't support the default authentication method introduced by MySQL 8. See the second answer here for a full explanation and a fix; the first answer works but makes your database less secure.
 
Node's mysql package is fucked and doesn't support the default authentication method introduced by MySQL 8. See the second answer here for a full explanation and a fix; the first answer works but makes your database less secure.
Ah, so basically mysql is old and shidd and I should upgrade to mysql2, the sqlquel. Makes sense, I was using an old-ish tutorial anyway.

Update, it just werk:
1715998018990.png

Thanks for all your help, bros.
 
Last edited:
:stress:
Fucking spent hours trying to figure out why in the fuck my code is saying
Code:
(93 < 345) = false
and my console kept spitting out fuckin binary code and ip addresses and shir only to find out
JavaScript:
let x = (x + cid[7][1])
x = x.toFixed(2)
returns a string and not an integer.

And yes I was lazy and used alot of if else statements and a function that keeps calling itself.
 
I am starting to understand regex better and yeah its fucking complicated but the more I learn the more I realize that nothing is ever as complicated as it seems.

I ended up making a telephone validator for freecodecamp and regex was the most simple way to do it.
In many cases, regexes are very straightforward. They CAN be utterly baffling at times though, especially when extensions to what you typically might use with a tool like grep are used. A lot of regex extensions were introduced in Perl (hence "Perl-compatible regular expressions" or "PCRE") and have since disseminated to other languages such as Python.

Another more fundamental challenge you can run into is using regexes for tasks they mathematically, provably are not suited for, which reminds me of the following famous StackOverflow answer concerning attempting to parse HTML with regexes:

"The console says you're fucked up. You code like a fag, and your shits all retarded."
If I were to anthropomorphize error messages, they always gave me a vibe like "I shat myself! Come clean me up!"
:stress:
Fucking spent hours trying to figure out why in the fuck my code is saying
Code:
(93 < 345) = false
and my console kept spitting out fuckin binary code and ip addresses and shir only to find out
JavaScript:
let x = (x + cid[7][1])
x = x.toFixed(2)
returns a string and not an integer.
Types in JavaScript are fucked. I can take or leave static (vs. dynamic) typing but JavaScript specifically has weak (vs. strong) typing. (A point of confusion for beginners sometimes: these two distinctions are orthogonal, though I can't say I've heard of an instance of weak typing without dynamic typing.) The former binary of static vs. dynamic is a trade-off but weak typing is just a mistake. Also the only native number type JS has is floating point numbers which is another colossal mistake.
 
Last edited:
The former binary of static vs. dynamic is a trade-off but weak typing is just a mistake. Also the only native number type JS has is floating point numbers which is another colossal mistake.
I very much agree.

@SandyHooker, maybe look into TypeScript, which makes Javascript slightly less shit
 
My favorite trick for quickly pulling stuff like URLs from files is the non-greedy capture .*?.
Can you tell me how that's different from .* or, say, .+? ... I assume it has something to do with greedy/capture but I'm not seeing why it'd be useful...
 
  • Like
Reactions: y a t s
If I were to anthropomorphize error messages, they always gave me a vibe like "I shat myself! Come clean me up!"

Somehow my function is making the browser crash and its also making a variable go negative even though it shouldn't be. Decided to fucking delete it and restart and I added this into my new function so if it happens again the console will talk shit.

JavaScript:
else if (x < 0){
    return console.log(`Your chart says you're fucked up. You talk like a fag and your shits all retarded. ${x}`)
  }
I very much agree.

@SandyHooker, maybe look into TypeScript, which makes Javascript slightly less shit
I'll look into it. I've been using freecodecamp to teach myself and right now I'm just trying to knock out the javascript projects on there. Even if it doesn't mean shit on a portfolio, I've been learning alot.
 
Can you tell me how that's different from .* or, say, .+? ... I assume it has something to do with greedy/capture but I'm not seeing why it'd be useful...
Sure thing.

Suppose you were working with an HTML file and wanted to extract the src attribute from an <img> tag like this one:
HTML:
<img class="lnXdpd" alt="Google" height="92" src="/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" srcset="/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png 1x, /images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 2x" width="272" data-csiid="1" data-atf="1">

An easy way to do this is to grep for src=".*?" then isolate that bit between the quotes using sed and a simple capturing group (fyi, ripgrep has a nice replace feature for stuff like this). If you grepped for src=".*" instead, you would end up pulling everything up to the final " that appears on that line due to regex's default greedy behavior. The same idea applies if you use the + quantifier instead of *. In this case, using src=".*?" would also match any src attributes that are empty (i.e. src="").

Note that some implementations of grep require the -E option for extended regex to use advanced techniques like this non-greedy quantifier, and others require -P for Perl style regex. If you have support for -P, then you could skip the sed piping and simply use lookahead and lookbehind assertions like (?<=src=").*?(?=").

Of course, you should use a proper parser for more serious tasks, but this works fine for simple tasks like isolating a list of URLs to throw at aria2c. The [^"]* trick I mentioned previously works just as well (and is slightly more compatible with old regex engines), but it feels super clunky in comparison when trying to hammer out a quick command in your terminal.
 
Last edited:
Back