Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

go play outside Skyler posted:

Better to make it an npm package with 5 dependencies

And make sure each one of those has at least 5 dependencies.

Adbot
ADBOT LOVES YOU

Impotence
Nov 8, 2010
Lipstick Apathy

Lumpy posted:

And make sure each one of those has at least 5 dependencies.

https://npm.anvaka.com/#/view/2d/react-native

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Managing dependencies well is so tricky.

Sometimes though I wonder if npm isn't just saying the quiet part out loud.

Computers are built on a house of cards.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It's time to start over. At some point we shifted every piece of software running it's own operating system with purpose built drivers, to one massive ball of poo poo. It doesn't matter that my phone is a super-billion times faster than what was used to land on the moon, if every time I launch Snapchat it shits itself.

Impotence
Nov 8, 2010
Lipstick Apathy

Nolgthorn posted:

It's time to start over. At some point we shifted every piece of software running it's own operating system with purpose built drivers, to one massive ball of poo poo. It doesn't matter that my phone is a super-billion times faster than what was used to land on the moon, if every time I launch Snapchat it shits itself.

This is because Snapchat intentionally tries to do a number of hosed up things, device fingerprinting and invasive garbage on boot.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Snapchat is a bad example because the software itself is so poor.

I was just using it for humour.

But it is the case that an incredible number of cycles are spent doing tings that any given piece of software doesn't need, just because it's baked into the operating system. The Linux kernel has ballooned to almost 30 million lines of code and it keeps growing. I'm just suggesting that any given piece of software only really needs a tiny fraction of that.

I watched a guy talk about it for an hour.

https://www.youtube.com/watch?v=kZRE7HIO3vk

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Oh, the guy who made a 45 minute video ranting about how Visual Studio is too bloated because it does more than debug C? He's kind of a crank, IMO

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Compared to most developers I've met? well... I mean I prefer visual studio code myself.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Yeah that guy is definitely a crank.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
if casey wants to code on a win95 machine and msvc++ 5.1 i mean im more than happy to let him do that

he will soon realize that its actually not fast, and the drat thing runs at 800x600 resolution max with 16-bit color

Anony Mouse
Jan 30, 2005

A name means nothing on the battlefield. After a week, no one has a name.
Lipstick Apathy
I scratch my "close to the metal" itch by tinkering with shaders in my free time. For dev dependencies, who cares? For prod dependencies, modern tree shaking does a pretty good job of cutting unused code. For everything else, I keep an eye on import costs and every time I think to myself "I bet there's a library for this" I spend 15 minutes checking our existing dependencies and code and trying to work it out from scratch to gauge the complexity. I'm far more concerned about internal code duplication and the fact that my team's code base currently has cruft such as: three distinct React modal components plus the one from our internal library package (yes really).

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
I have tried making an offline PWA with a service worker that caches all the files needed for the app. I also added a manifest and an icon and I'm able to install the app on my phone's home screen and run it from there.

However, if I turn on the phone's airplane mode and try to reload the page it will say "no internet" "chrome will let you know when this page is ready"

Am I doing something wrong or does reloading just always bypass the service worker and the cache?

edit: okay, I'm definitely doing something wrong since airhorner.com works fine even in airplane mode and reloading the page

Wheany fucked around with this message at 16:15 on Jun 1, 2020

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Okay, I followed the "Offline fallback" recipe from https://serviceworke.rs/offline-fallback_service-worker_doc.html

That example tries to fetch first, then catch errors and respond with a cached version. Instead I got it working by reading the cache first and then trying to fetch data over the network if not found.

Which sounds reasonable in hindsight.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Wheany posted:

Which sounds reasonable in hindsight.
Depends if you want to be able to update the data - you've got a permanent cache in what you describe, the server is never asked again once the client has any data.

Another option that can be good is read the offline version first, then request the live version, and update if a live one comes back - that way you get the fast response of a cache, but remain server-updatable (possibly at the cost of a glitchy-looking blink if an update happens.)

And if you want to get fancy, you can send a version number or a hash of the offline one with your request, and have the server just reply with a "you're up to date" signal instead of a new value if there's no update, to save bandwidth - e.g. http status code 204.

Guildenstern Mother
Mar 31, 2010

Why walk when you can ride?
So I'm doing some pre boot camp coursework, and I'm trying to make a change calculating function for one of the assignments. I put this line in to make sure my variables were working ok:

double result = amntGiven - amntRecieved;
System.out.println(result);

amntGiven is 18, amntRecieved is 17.18, and I go to compile and the thing shits out an answer of 0.8200000000000003. This doesn't seem normal, and I was thinking my decimal lengths in previous assignments were kind of long as well. I'm sure I'm missing something painfully obvious.

Ola
Jul 19, 2004

Guildenstern Mother posted:

So I'm doing some pre boot camp coursework, and I'm trying to make a change calculating function for one of the assignments. I put this line in to make sure my variables were working ok:

double result = amntGiven - amntRecieved;
System.out.println(result);

amntGiven is 18, amntRecieved is 17.18, and I go to compile and the thing shits out an answer of 0.8200000000000003. This doesn't seem normal, and I was thinking my decimal lengths in previous assignments were kind of long as well. I'm sure I'm missing something painfully obvious.

You've been introduced to the wonderful world of floating point numbers. This should be a good primer:

https://www.youtube.com/watch?v=PZRI1IfStY0

Also, Java isn't Javascript, but you run into the same things there. :)

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I listened to a guy talk about number formats for like an hour.

He said floating point numbers used to make a lot of sense but computers are better now, the conclusion was that we don't need all these number formats we just need one. He proposes that the answer is UNUM, or universal numbers. Which gives you precise numbers. He also talked for a while about how adding two int32s together the result isn't an int32. Because the sum could be larger than the space provided by an int32. Multiplication the problem was even worse and so on.

Basically he ranted about how numbers in computers suck and that future programming languages should adapt.

Doom Mathematic
Sep 2, 2008

Guildenstern Mother posted:

So I'm doing some pre boot camp coursework, and I'm trying to make a change calculating function for one of the assignments. I put this line in to make sure my variables were working ok:

double result = amntGiven - amntRecieved;
System.out.println(result);

amntGiven is 18, amntRecieved is 17.18, and I go to compile and the thing shits out an answer of 0.8200000000000003. This doesn't seem normal, and I was thinking my decimal lengths in previous assignments were kind of long as well. I'm sure I'm missing something painfully obvious.

You may be looking for the Java questions thread, this is the JavaScript questions thread.

Anyway, as a general rule in handling currency it's best to avoid using fractions, because of exactly this problem. See if you're able to do this using integer amounts of cents (or pennies or whatever), so you have 1800 minus 1718 is exactly 82. Only add the decimal point when printing to the screen.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

roomforthetuna posted:

Depends if you want to be able to update the data - you've got a permanent cache in what you describe, the server is never asked again once the client has any data.

Another option that can be good is read the offline version first, then request the live version, and update if a live one comes back - that way you get the fast response of a cache, but remain server-updatable (possibly at the cost of a glitchy-looking blink if an update happens.)

And if you want to get fancy, you can send a version number or a hash of the offline one with your request, and have the server just reply with a "you're up to date" signal instead of a new value if there's no update, to save bandwidth - e.g. http status code 204.

I think what I want to accomplish in the end is to have a fallback cache and a fresh cache and try to fetch the data into the fresh cache. If the fetch succeeds, the fresh cache becomes the new fallback and the old fallback is deleted.

This has all been for https://github.com/everestpipkin/image-scrubber where I think the idea is that it stays as offline and simple as possible. Either using service workers for "app like" behavior or easily zippable html js and css that you can unzip and use on your computer without ever sending anything over the network.

Guildenstern Mother
Mar 31, 2010

Why walk when you can ride?
Thanks for the explanations and sorry for wrong thread posting

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Guildenstern Mother posted:

Thanks for the explanations and sorry for wrong thread posting

If it's any consolation, javascript was named javascript in the 90s because there was this new cool programming language called java. You were meant to be confused by the name

Guildenstern Mother
Mar 31, 2010

Why walk when you can ride?

Wheany posted:

If it's any consolation, javascript was named javascript in the 90s because there was this new cool programming language called java. You were meant to be confused by the name
I can already tell this is going to be a magical journey

Impotence
Nov 8, 2010
Lipstick Apathy
Can we rename the thread to ECMAScript(6|2020|11|2021|...) questions?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Biowarfare posted:

Can we rename the thread to ECMAScript(6|2020|11|2021|...) questions?

Not until the last computer capable of running IE6 is no longer functional.

Sergeant Rock
Apr 28, 2002

"... call the expert at kissing and stuff..."

Lumpy posted:

Not until the last computer capable of running IE6 is no longer functional.


Ah, good, and when can you accomplish this? I will create the Kanban board.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Where's the hacker that was supposed to exploit one of IE6's millions of security vulnerabilities in order to fry the motherboard of every computer running that piece of software? They are way way behind schedule.

twig1919
Nov 1, 2011
I am an inconsiderate moron whose only method of discourse is idiotic personal attacks.

Nolgthorn posted:

Where's the hacker that was supposed to exploit one of IE6's millions of security vulnerabilities in order to fry the motherboard of every computer running that piece of software? They are way way behind schedule.

Its already happened but the simulation self-corrected because without IE6 there would not be enough suffering for the human brain to accept this reality.

Polio Vax Scene
Apr 5, 2009



Trying to detect GSM-7 extension characters in a string using regexp.
https://en.wikipedia.org/wiki/GSM_03.38#GSM_7-bit_default_alphabet_and_extension_table_of_3GPP_TS_23.038_.2F_GSM_03.38
Regex gods, what am I missing here?:

code:
	//stolen from mdn
	var escapeRegExp = function (string) {
		return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
	}

	var testString = "should[match]|nonGSM-7^";
	var gsmRegExp = new RegExp(escapeRegExp("€|^{}[~]\\"), "g");
	var escapes = (testString.match(gsmRegExp) || []).length;
	console.writeLine(escapes); // 0??
v I knew it was something simple I was missing, thanks! The writeLine isn't in the actual code, I just fried my brain trying to figure this out beforehand.

Polio Vax Scene fucked around with this message at 14:06 on Jun 18, 2020

Doom Mathematic
Sep 2, 2008
I don't think JavaScript has console.writeLine but that's not the problem...

Your regular expression is looking for the nine-character fixed string "€|^{}[~]\\". You want something like:

JavaScript code:
	var escapeRegExp = function (string) {
		return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
	}

	var testString = "should[match]|nonGSM-7^";
	var gsmRegExp = new RegExp("[" + escapeRegExp("€|^{}[~]\\") + "]", "g");
	var escapes = (testString.match(gsmRegExp) || []).length;
	console.log(escapes); // 4
Note the square brackets added, which turns the fixed string literal into a character class.

Sous Videodrome
Apr 9, 2020

This isn't a question, but I just did a blog entry on rendering markdown in React using react-markdown and I don't see another javascript or react thread on the forums. So I'm linking it here:
https://jacobwicks.github.io/2020/06/19/rendering-markdown-and-resizing-images-with-react-markdown.html

Sous Videodrome
Apr 9, 2020

Biowarfare posted:

Can we rename the thread to ECMAScript(6|2020|11|2021|...) questions?

Lol

SardonicTyrant
Feb 26, 2016

BTICH IM A NEWT
熱くなれ夢みた明日を
必ずいつかつかまえる
走り出せ振り向くことなく
&



Biowarfare posted:

Can we rename the thread to ECMAScript(6|2020|11|2021|...) questions?
Javascript thread: Harder, Better, Faster, Stronger

FSMC
Apr 27, 2003
I love to live this lie
I'm currently lost when it comes to "build" systems/tools. My current setup is based around my own bash script. The source javascript file has a hardcoded constant BUILD_TYPE, and then some logic to sets the .css file to either a local one or online depending on the BUILT_TYPE constant. I have a bash script which sets/replaces the BUILD_TYPE variable. The bash script then runs google-closure-compiler, obscurify, uglfy, updates a html page with the output, uploads the output to s3, and runs git commit. I want to add in babel but I'm not even sure what order that should go in. Also now I'm using Jest for testing but to get that to work I need to comment out the target browsers in .babelrc. I'm pretty sure I should be using a proper tool rather than my own bash script. So is there something where I can set build variables in an external file/config, that can run google-closure-compiler, babel, with their own config files depending on if I'm compiling for browser or testing. I'm using vscode.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
Look into webpack.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Seconding webpack. The tutorial/getting started on the official website is pretty good too. Once you get the project structure mostly there, you can start adding plugins to the mix

Wheany fucked around with this message at 14:01 on Jun 21, 2020

xiw
Sep 25, 2011

i wake up at night
night action madness nightmares
maybe i am scum

Cpig Haiku contest 2020 winner
I'm having a real poo poo of a time getting into the kind of frontend development i'm being asked to do, which is things like customise Bigcommerce through JS injected scripts. It feels like an infinite nightmare of reading minified JS from thirdparties and trying to reverseengineer it and change behaviour. Is this actually a usual thing (hey this compiled JS does X, change it to do Y by intercepting mutators and hunting events and charting out its flow) or am i starting with the hard stuff?

it's really dispiriting since i feel like i'm spending days staring at the debugger and occasionally get a win but often it's just 'nope i can't figure out how to do this short of breaking into react's hidden state fields' and i've wasted a lot of time.

wearing a lampshade
Mar 6, 2013

xiw posted:

I'm having a real poo poo of a time getting into the kind of frontend development i'm being asked to do, which is things like customise Bigcommerce through JS injected scripts. It feels like an infinite nightmare of reading minified JS from thirdparties and trying to reverseengineer it and change behaviour. Is this actually a usual thing (hey this compiled JS does X, change it to do Y by intercepting mutators and hunting events and charting out its flow) or am i starting with the hard stuff?

it's really dispiriting since i feel like i'm spending days staring at the debugger and occasionally get a win but often it's just 'nope i can't figure out how to do this short of breaking into react's hidden state fields' and i've wasted a lot of time.

This sounds like it ought to be banned by the Geneva convention jfc

wearing a lampshade
Mar 6, 2013

There are tools that can help you refactor scripts iirc but it's mostly around renaming obfuscated variables and functions semantically and it's basically all manual beyond making sure you're renaming something correctly in the right places. And I can't tell you where Ive seen it because it's probably just phpstorm stuff that I'm imagining had a web app

Roadie
Jun 30, 2013

xiw posted:

I'm having a real poo poo of a time getting into the kind of frontend development i'm being asked to do, which is things like customise Bigcommerce through JS injected scripts. It feels like an infinite nightmare of reading minified JS from thirdparties and trying to reverseengineer it and change behaviour. Is this actually a usual thing (hey this compiled JS does X, change it to do Y by intercepting mutators and hunting events and charting out its flow) or am i starting with the hard stuff?

it's really dispiriting since i feel like i'm spending days staring at the debugger and occasionally get a win but often it's just 'nope i can't figure out how to do this short of breaking into react's hidden state fields' and i've wasted a lot of time.

Use the API. That's why they have an API.

Also, BigCommerce would also probably be unhappy if they knew a client was monkeying with their scripts, given both any legal TOS implications and that they don't want people relying on internal undocumented behavior.

Adbot
ADBOT LOVES YOU

Ola
Jul 19, 2004

xiw posted:

I'm having a real poo poo of a time getting into the kind of frontend development i'm being asked to do, which is things like customise Bigcommerce through JS injected scripts. It feels like an infinite nightmare of reading minified JS from thirdparties and trying to reverseengineer it and change behaviour. Is this actually a usual thing (hey this compiled JS does X, change it to do Y by intercepting mutators and hunting events and charting out its flow) or am i starting with the hard stuff?

it's really dispiriting since i feel like i'm spending days staring at the debugger and occasionally get a win but often it's just 'nope i can't figure out how to do this short of breaking into react's hidden state fields' and i've wasted a lot of time.

This sounds absolutely awful. Make it your goal of 2020 to stop doing it, either by changing their minds or changing your job.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply