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
teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
yeah it's an NPM package that has no typings module. Actually looks like I forgot to pass the --save flag when I installed it, so npm install wasn't grabbing the package after cloning the repo

Whoops.

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

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

yarn just saves it, no need to pass an extra flag.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
Yarn is just a faster npm right?

That was how it was explained to me by my coworker

smackfu
Jun 7, 2004

With new and different bugs.

reversefungi
Nov 27, 2003

Master of the high hat!

Grump posted:

Yarn is just a faster npm right?

That was how it was explained to me by my coworker

From Stack Overflow:

quote:

From the get-go, the Yarn lockfile guarantees that repeatedly running yarn on the same repository results in the same packages.

Second, Yarn attempts to have good performance, with a cold cache, but especially with a warm cache.

Finally, Yarn makes security a core value.

Yarn handles package management more intelligently by using lock files. The latest versions of NPM have also been using lock files, though google tells me that yarn's solution still wins out.

Odette
Mar 19, 2011

The Dark Wind posted:

From Stack Overflow:


Yarn handles package management more intelligently by using lock files. The latest versions of NPM have also been using lock files, though google tells me that yarn's solution still wins out.

Ironically, Yarn lockfiles depend on the Yarn version. Different yarn version = different lockfile. Having said that, I'm glad that there's competition in the node package manager space.

redleader
Aug 18, 2005

Engage according to operational parameters
[img-xkcd-standards.png]

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Anecdotally, yarn didn't work and I had to force install all of my packages more often than it worked at my last job.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
I'm playing around trying to get some TypeScript set up in WebStorm, but for some reason it wants me to configure a node executable or something? I don't really care about node, all I want to do is client side TypeScript that I'd like for WebStorm to automatically compile when I press the Go button. Specifically I'm getting the error about Node executable not being configured when I exit configuration and a "Service is not started" when I tell it to compile all. I don't even know what a node executable is or how/where to get one.

Roadie
Jun 30, 2013

Joda posted:

I'm playing around trying to get some TypeScript set up in WebStorm, but for some reason it wants me to configure a node executable or something? I don't really care about node, all I want to do is client side TypeScript that I'd like for WebStorm to automatically compile when I press the Go button. Specifically I'm getting the error about Node executable not being configured when I exit configuration and a "Service is not started" when I tell it to compile all. I don't even know what a node executable is or how/where to get one.

Typescript is a Node module, not a self-contained executable.

https://nodejs.org/en/download/

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe

Roadie posted:

Typescript is a Node module, not a self-contained executable.

https://nodejs.org/en/download/

Oh, thanks. Not sure why WebStorm even talks about a built-in compiler then.

Sedro
Dec 31, 2008

Joda posted:

Oh, thanks. Not sure why WebStorm even talks about a built-in compiler then.

In the settings, you can choose between Jetbrains built-in compiler and the typescript language service. You should use the language service

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
What are the best places to host your basic Nodejs app these days? I have been using Bluemix which is great but I'm starting to get a small stack of apps running there and it's becoming no longer cheap, they seem to have disabled "auto sleep" for my less important apps so I'm always racking up gigabyte hours too.

The Fool
Oct 16, 2003


Nolgthorn posted:

What are the best places to host your basic Nodejs app these days? I have been using Bluemix which is great but I'm starting to get a small stack of apps running there and it's becoming no longer cheap, they seem to have disabled "auto sleep" for my less important apps so I'm always racking up gigabyte hours too.

Do you need custom domains? Azure app hosting has a free tier, and a shared tier which is very cheap.

Heroku is also an option.

Google cloud advertises a free tier but I don't know a lot about it.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Yes I need to use my own custom domains, I need SSL, I also have a project coming up that needs to host a (incoming) mail server. I don't know much about the details of receiving mail at a domain if there are special requirements for that.

Are there smaller players than Microsoft, Heroku, and Google?

The Fool
Oct 16, 2003


Don't host your own email. Use 365 or google apps.

Azure app service is very reasonably priced, supports node, custom domains, ssl (even easy le support with an extension), deploy from git, and other features. It's worth checking out.

I'm sorry I don't have any other suggestions. Azure is what we use at work, so I'm the most familiar with it.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Cool I'll try it out!

I don't need my own mail server per say I just need to to be able to receive and read emails, no sending emails, no storing emails, nothing like that. Basically this.

https://github.com/Flolagale/mailin

Nolgthorn fucked around with this message at 17:23 on Sep 30, 2017

Ranzear
Jul 25, 2013

You can get a Linode for $5 a month now. Then you just use certbot for your SSL. Redirecting to gmail with a text record is easy too.

If bashing out your own linux server is scary I could help you out. I know some neat tricks to terminate SSL for websockets too.

Roadie
Jun 30, 2013

Nolgthorn posted:

What are the best places to host your basic Nodejs app these days? I have been using Bluemix which is great but I'm starting to get a small stack of apps running there and it's becoming no longer cheap, they seem to have disabled "auto sleep" for my less important apps so I'm always racking up gigabyte hours too.

If you want to avoid running your own server stuff, you may want to look at now. The pricing scales badly for lots of individual domains, though.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Now looks frighteningly competent. All I need is a regular package.json and it'll deploy my app... I can add domains and it automatically gets decorated with ssl and whoisguard for free. I can generate as many deployments as I want.

It's too bad that the free tier open sources your code. That means I can't really try them without using a test app, instead of my actual app.

Something is fishy about the competency.

What if I manage my own domains ssl certs and whoisguard elsewhere because I'm a tinfoil hatter and want to spend more.

Thermopyle
Jul 1, 2003

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

I really like Heroku just for their ease of use and the ability to just get poo poo done fast.

They get pretty expensive if you need to scale out or need lots of different servers.

huhu
Feb 24, 2006
Edit: nevermind.

huhu fucked around with this message at 18:55 on Oct 1, 2017

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Running a bunch of nodes is pretty common.

It's supposed to be, you can have one for each api concern. Docker is big because of the demand for microservices, something that lets me run a bunch of small stuff would make me feel more future proof.

Thermopyle
Jul 1, 2003

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

Nolgthorn posted:

Running a bunch of nodes is pretty common.
Yes. But how much that will cost will depend on how active they are. It's entirely possible to have a bunch of free tier nodes at a lot of providers if they're not resource intensive.

Digital Ocean is another option.

prom candy
Dec 16, 2005

Only I may dance
Oh wow I just realized there's a $7/mo tier on Heroku now. I stopped using them ages ago because it was either free and your app fell asleep and took forever to load, or it was $36/mo. $7/mo for not having to janitor a Linux server is not a bad deal at all. now.sh looks interesting too. I work at an agency and we have over 100 droplets on our digital ocean account, it is hell sometimes.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
edit: My last question was dumb and for idiots. I have a newer more dumb question.

OK so I have a stream of data, that could be inexplicably huge. I am trying to pipe this data to a transform and then pipe it to an output stream.

This is all well and good and should provide some decent scalability. But the problem is, I need to do some processing based on the very first line of the stream. I know how to pipe the stream to my transform, but I am not sure how to pullout only the first line and use it for all future line transformations...

Also what is the boundary on a "data" event. Like if I have:

process.on('data', funcDoAThing);

How often is doAThing called? Is there a byte limit? I don't understand when I would see a "chunk" of data.

Knifegrab fucked around with this message at 01:20 on Oct 6, 2017

Roadie
Jun 30, 2013

Knifegrab posted:

edit: My last question was dumb and for idiots. I have a newer more dumb question.

OK so I have a stream of data, that could be inexplicably huge. I am trying to pipe this data to a transform and then pipe it to an output stream.

This is all well and good and should provide some decent scalability. But the problem is, I need to do some processing based on the very first line of the stream. I know how to pipe the stream to my transform, but I am not sure how to pullout only the first line and use it for all future line transformations...

Assuming by "stream of data" you mean a bytestream, "the first line" actually means "everything from the first byte up to the first line ending". What a line ending is will depend on the system sending it. Windows and other dinosaurs use \r\n, while everything else uses \n.

Knifegrab posted:

Also what is the boundary on a "data" event. Like if I have:

process.on('data', funcDoAThing);

How often is doAThing called? Is there a byte limit? I don't understand when I would see a "chunk" of data.

You cannot control or predict it. If you want to use specific segments of it, you'll need to save it to a local buffer and use that.

code:
const ENCODING = 'utf8'
const NL = '\n'
const NL_BYTES = 1
let localBuffer = Buffer.alloc(0, 0, ENCODING)

/**
 * @param {Buffer | string} chunk
 */
const processChunk = chunk => {
  if (typeof chunk === 'string') {
    chunk = Buffer.from(chunk, ENCODING)
  }

  // update local buffer
  localBuffer = Buffer.concat([localBuffer, chunk])

  // look for a newline
  const possibleNewline = localBuffer.indexOf(NL)
  if (possibleNewline !== -1) {
    // log string up to newline and remove it from buffer
    const newlineBuffer = localBuffer.slice(0, possibleNewline + NL_BYTES)
    localBuffer = localBuffer.slice(possibleNewline + NL_BYTES)

    console.log(newlineBuffer)
  }
}

process.on('data', processChunk)

plasticbugs
Dec 13, 2006

Special Batman and Robin
I'm dealing with an not-so-edge edge case with text search on a MongoDB (3.4) through Node. I've got the field I'm searching indexed as text.

The search ignores diacritics (like the e in Beyoncé here). So, if I type a diacritic into the search, like this: îphone -- I get iPhone results as expected. HOWEVER, if I search for "beyonce", I don't get any of the rows that have Beyoncé stored with an accent over the e. Only if I search with the diacritic do I actually get Beyoncé results.

EDIT: I've also got $diacriticSensitive set to false, but it's not doing what I think it ought to do. The text index should be diacritic insensitive by default in Mongo 3.2+, but it's not a two-way insensitivity somehow?

I guess I could write logic just to handle Beyoncé, but is there a better way to handle this?

My very naive approach right now is if any searches give 0 results and have an "e" in them, I would rerun the search with all "e"s replaced with "é"s.

plasticbugs fucked around with this message at 05:20 on Oct 6, 2017

Ranzear
Jul 25, 2013

I can only think to have someting like php's iconv() in ASCII//TRANSLIT mode to store a 'searchable' string of plain ascii on the side.

https://github.com/bnoordhuis/node-iconv

Ranzear fucked around with this message at 07:58 on Oct 6, 2017

Munkeymon
Aug 14, 2003

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



Roadie posted:

Windows and other dinosaurs use \r\n, while everything else uses \n.

Does Node on OSX autoconvert \r to \n?

necrotic
Aug 2, 2005
I owe my brother big time for this!
I hope not.

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
Heads up for those still using bower: they are advising you to gtfo.

necrotic
Aug 2, 2005
I owe my brother big time for this!
They have been for a while. Simply using bower shows a message recommending you move off.

plasticbugs
Dec 13, 2006

Special Batman and Robin

Ranzear posted:

I can only think to have someting like php's iconv() in ASCII//TRANSLIT mode to store a 'searchable' string of plain ascii on the side.

https://github.com/bnoordhuis/node-iconv

This should work! I'll store searchable text alongside each record and will report back on results.

Edit: I tried iconv, but it was giving me Beyonc'e instead of Beyonce, so I used a module called 'remove-accents' and that did the trick. I added a searchable text field with all accents removed and it works perfectly. Thanks for the help!

plasticbugs fucked around with this message at 20:10 on Oct 6, 2017

Ranzear
Jul 25, 2013

plasticbugs posted:

I tried iconv, but it was giving me Beyonc'e instead of Beyonce
code:
ranzear@ubuntu:~$ php -a
Interactive mode enabled

php > echo iconv("UTF-8", "ASCII//TRANSLIT", "Beyoncé");
Beyonce
php >
Weird.

The PHP docs note that it may be system dependent. I copypasted your 'Beyoncé' but maybe yours is a composite character and it's doing the diacritic separately? Are you missing 'UTF-8' as the first arg?

Ranzear fucked around with this message at 21:03 on Oct 6, 2017

Coco Rodreguiz
Jan 12, 2007

Peckerhead isn't used enough as an insult if you ask me.
Can someone help me out here? I'm taking a JavaScript class and I hosed this assignment up enough it dropped me a letter grade but I'm still not 100% on what I did wrong.

It's supposed to prompt you for a letter (and the instructor wants everything pirate themed :shrug:). Then eventually write that to the page with true or false for each 0 or 1.

I know I'm not grasping some simple js concept cause I'm a loving idiot. Apparently I'm not calling the function right but I dunno why but the way the instructor and ta explain it to me I just can't comprehend. This is the first assignment that needed returns and I feel like I'm not grasping what a return does correctly too.

myself posted:

$(document).ready(function() {

function password() {  
  var intDefLetter = "C";  
  var intQuestion = "Arrr I got a message I can give, do ye have the password?";   
var intNewLetter = "";    

  intNewLetter = prompt(intQuestion, intDefLetter);      

if (intNewLetter.length > 1) {                   prompt(intQuestion, intDefLetter);     
   }    
return intNewLetter;
}

function parseAscii(intNewLetter) {   var intAscii = "";    

intAscii = intNewLetter.charCodeAt(0);    

return intAscii;  
   }

function parseBin(intAscii) {  
  var strBin = "";    

strBin = parseInt(intAscii, 10).toString(2);      

if (strBin.length < 8) {       
  
var intPlaceHolders = 8 - strBin.length;        

   for (var i = 0; i < intPlaceHolders; i++) {       
         strBin = "0" + strBin;                
  }            
}
   return strBin;   
  }

function split(strBin) {  

  var strMessage = "";   

   strMessage = strBin.split("");  

    return strMessage;   
  }

function forEach(strMessage) {  
  var arrayLength = strMessage.length;  
  var i;      

for (i = 0; i < arrayLength; i++) {         

        if (strMessage[i] = 0) {           
  var falseOutput = document.getElementById("message");
    var msgFalse = "False ";     

                falseOutput.textContent = msgFalse;       
    } else {            
var trueOutput = document.getElementById("message");           
  var msgTrue = "True ";        

          trueOutput.textContent = msgTrue;         
     }       
  }   
};

password();
parseAscii();
parseBin();
split();
forEach(); });

tldr: help me I'm stupid at JavaScript and if I can't grasp calling a function and returns I'm probably gonna fail every assignment for the rest of the semester.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Coco Rodreguiz posted:

Can someone help me out here? I'm taking a JavaScript class and I hosed this assignment up enough it dropped me a letter grade but I'm still not 100% on what I did wrong.

It's supposed to prompt you for a letter (and the instructor wants everything pirate themed :shrug:). Then eventually write that to the page with true or false for each 0 or 1.

I know I'm not grasping some simple js concept cause I'm a loving idiot. Apparently I'm not calling the function right but I dunno why but the way the instructor and ta explain it to me I just can't comprehend. This is the first assignment that needed returns and I feel like I'm not grasping what a return does correctly too.


tldr: help me I'm stupid at JavaScript and if I can't grasp calling a function and returns I'm probably gonna fail every assignment for the rest of the semester.

Well, I haven't looked terribly closely... but at the end, you just call all your functions without any parameters. Why are you returning values and expecting parameters if you are not using them?

Edit: Ok, that's what you are not getting...

Imagine you want to encapsulate some code that does something for you. Specifically, calculate PI. Lets call that getPI().
That function might look something like "function getPI() { return 3.14; }". What this means, is if you then call it, you will get the value from the return statement. So you can do "var pi = getPI();". Now pi = 3.14. You can also pass information into functions. So you could do like "function getArea(radius) { return getPI() * radius * radius; }". You would call it like "var area = getArea(3)".

Skandranon fucked around with this message at 21:11 on Oct 7, 2017

Ranzear
Jul 25, 2013

Coco Rodreguiz posted:

I'm taking a JavaScript class

quote:

$(document).ready

:negative:

I get that libraries and frameworks are a thing, but you should be learning without JQuery first.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Ranzear posted:

:negative:

I get that libraries and frameworks are a thing, but you should be learning without JQuery first.

He's got a long ways to go... needs to get functions, parameters, and return values down first.

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
code:
    var a = password();
    var b = parseAscii(a);
    var c = parseBin(b);
    var d = split(c);

    forEach(d);
You want something like this. To avoid hoisting and save you some sanity, plz use `let` and `const` instead of `var`. Super easier.

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