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
necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:

"rows" in this case can be called anything correct? So the value of rows is determined as what would normally be the result var in callback(result,[err]) that makeNodeResolver takes over correct?

Yes, "rows" is just the name of your argument for that function. It can be "iDontGetThisShit" if you want. Also yes to your second question.

Adbot
ADBOT LOVES YOU

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

Knifegrab posted:

Can you expand on this, I don't completely understand what you are saying.

JSX is "compiled" into raw-JS like so:

code:
<Butte flacid="cock">Stick it</Butte>

=>

React.createElement(Buttes, {"flacid": "cock"}, "Stick it")
It is very different from doing raw HTML with html or such stuff.

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

Knifegrab posted:

Can you expand on hot reloading, and pretend I am a complete moron (I am).

Hot reloading will watch for changes to your JS files and automatically inject the new script into your browser page on the fly. No reload is necessary and you see changes immediately. It's pretty spectacular, but took me some effort to get it working the first couple of times.

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

Knifegrab posted:


edit: Nevermind, I can see that setting up node is quite easy for windows, but I still am curious about where to go for web server stuff. Also should I stick to v0.12 or should I bite the bullet and go V4.2?

Node has an HTTP server built-in. There are libraries built on top of it (such as express) to simply routing and middleware. For production you still want something like nginx or apache as the front-end server that proxies to the node process, but for development it doesn't matter.

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

Knifegrab posted:

Ugh I am lost. When I want to run my test server I have to run my expressServer.js file using node. I am using a 1and1 host and its easy enough to upload a php structure and index.html, but I cannot figure out how to implement a node files on my webhost. I feel pretty dumb right now.

Shared hosting will rarely support Node.js apps. Its possible, but not as simple as "upload this js file and it works!". http://stackoverflow.com/questions/17529613/why-node-js-cant-run-on-shared-hosting

Heroku is relatively simple (for a non-shared platform): deploying is as simple as a git push, but does require some initial setup which the linked doc outlines.

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

Knifegrab posted:

I made a post in the web hosting thread, hopefully someone there can help me. I am assuming, when you say long-running application you mean the fact that my express server must be running indefinitely?

Is there a better way to run a node server than that? In all my test development when I want to run my server I just do "node expressServer.js" and my express server starts listening on the appropriate port. However if anything goes wrong my expressServer crashes and exits, when I am in development obviously I can just restart the process but how the heck do I handle an exception like that when running production. Obviously proper error handling should prevent such a thing from happening but even best case scenario there is always something that could go wrong!

edit: Thanks Heroku looks really cool, I will take a peak!

Running the process indefinitely is literally the only way to use node for web work. As Vulture Culture said, you want to use a supervisor of some kind (systemd/upstart/sysv if you have access, but you can use a user land supervisor if you must) to auto-restart on crashes. Heroku handles this for you!

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

Knifegrab posted:

So as a follow up, do you work for Heroku? Just curious because you speak very highly of it, not to say it isn't a good service but I just wanted to check.

Also Heroku seems very cool but I am worried about pricing/performance. I pay very little for my current hosting (less than a hundred a year), my current project gets about 100,000 visits a month and the servers hold up just fine, never have any loss of perforamnce or anything.

However with Heroku it seems like their base minimum plan, which would still cost me well over a hundred a year, isn't that great. Downtime on my Database every month, and what seems like a very limited number of works. And to just get a database that does not have downtime, I would have to pay an extra 50 a month, which is very excessive. Maybe I am misunderstanding but would Heroku's "Hobby" level tier even perform for 100k visits a month?

I do not. I've used them a bit in the past, and for something like Node or Ruby they are probably the easiest to get up and running with. Their "Hobby" tier may work, but its not intended for that much traffic. Once you get off of shared hosting things start to get a bit pricier unless you manage everything yourself; which simply shifts the cost to time you spend instead of money you spend.

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

I'm trying to decide between MEAN or Rails for tabletop gaming app I'm building. It'll probably be high-write/read, if that makes a difference.

I am leaning towards ActiveRecord (Rails) and PostgreSQL but I am kind of itching to try MEAN out but it's tough to get unbiased, up-to-date information about MongoDB half the time.

I'm not sure if Mongo's schemaless design will benefit something that's basically a DB for D&D-like characters and all the things that entails.

Mongo has a terrible track record. If you want schema-less (which is not as useful as it sounds in most use cases) use Postgres with a JSON column, its highly performant (especially in 9.4+) and you still have all the goodies an RDBMS.

edit: Check out the Jepsen review of Mongo.

necrotic fucked around with this message at 20:05 on Oct 14, 2015

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

kloa posted:

I must be missing something, because I can't the following JSON result to output:

code:
var state = ...workplace.workplaceAddresses.P,1;
I've tried putting the P,1 in brackets and quotes but I keep getting JSHint errors when trying to console log the variable.

It's weird because mustache.js has no problem rendering fields with commas, but the JS console isn't liking it.

Err, that doesn't look like valid JS or JSON. What's it supposed to do? Mustache probably does some magical handling of "fields" like that when rendering.

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

IronDoge posted:

Angular is a javascript framework for web apps. It's has a promise library built in and it is better than using pure jQuery for controlling the UI IMO. It's pretty nifty generating entire components of a page using a few lines of code.


jQuery and Angular aren't even comparable. One is a library, with the original goal of making cross-browser JS consistent; Angular is an entire MVC framework.

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

Knifegrab posted:

I think I will definitely be pursuing React and react routing in my next step of development.

Do it. React has been a pleasure to work with.

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

Depressing Box posted:

Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const?

I use const for immutable data for clarity. When using Babel to transpile to ES5 the const check is handled while compiling, the actual output is a var (same with let); so for now I'd say there's no performance hit at all! I think its unlikely there would be any performance implications once its hit browsers and we stop transpiling.

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

Depressing Box posted:

Ah, I didn't realize the checks were just during compilation, that's cool.

I wasn't 100% sure either. I find the online REPL useful for figuring out how Babel transpiles things.

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

Depressing Box posted:

That's pretty handy. Interestingly enough, it looks like Babel has an optional transformer (part of "High compliancy" mode in the REPL) that will add TDZ checks to the compiled code.

That could be useful for development!

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

Mr. Jive posted:

Couldn't the emitter pass basically anything in there? How do I know that something usable is being passed? How does the emitter know that it needs to pass in the data it receives from the socket? How does the emitter know that a 'data' event means it should send something my code can broadcast? Is the event emitter passing a whole truckload of arguments but my code (as written) only cares about the first one?

All of the parameters for each event will be documented. Because its JS the only "guarantee" you have on the arguments is the documentation (or reading the code lol).

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

Mr. Jive posted:

Thanks, this in particular helps.


Am I understanding this documentation correctly in that the bullet point is the thing that will be passed as an argument when the listener is called? So in this case, the 'net' event emitter creates an instance of 'net.Socket' upon a 'connect' event and passes that as the first argument to the listener?

Correct. The format for their documentation of event callbacks is piss poor, but at least it exists I guess...

necrotic
Aug 2, 2005
I owe my brother big time for this!
That do/while loop doesn't look like it does anything except set some embedded data to the same value 10 times. If you want the difference between two Dates in days I'd use something like:

code:
// First we get the last Time and now in milliseconds
var lastTime = +new Date("2015-11-17 18:23:45"); // Pretend from ${e://Field/day1date}
var thisTime = +new Date();

// Now we find the difference in milliseconds
var diffTime = thisTime - lastTime;

// Now we calculate how many days that is (0.9 days is still 0 days)
var numberOfDays = Math.floor(diffTime / 1000 / 60 / 60 / 24);
You can make this shorter, but I like the explicitness of each step. The shortest I'd go is embedding the diffTime step into the numberOfDays calculation.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Will that work with objects that are equivalent but not equal? His array has 2 objects that are duplicated, but that doesn't mean they're the same object.

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

no_funeral posted:

So far the list of possibilities include React, Reflux with Flux, and Knockout... I don't really have any criteria for what is best, other than ease of use, and performance(which is why I'm leaning towards React).

Reflux is a Flux library that sits on top of React, its a way of managing global state at the top level of the React component hierarchy. The general trend seems to be heading towards Redux, which does better at enforcing immutable state. Flux is an Architecture, thats it (though Facebook did release a dispatcher when they described the Flux architecture). Redux is based on this architecture but takes it a step further.

I've been very happy working with React + Redux, and while there's no "framework" really built around these libraries yet they are pleasant to work with and have a small enough surface area to piece together on your own.

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

Knifegrab posted:

Edit nevermind but I do have anohter question.

I am using node to spawn a child process that is creating an ssh tunnel. However it needs a password (no keys cannot be used in this system). How do I tell node to supply ssh with a password (since there is no additonal command line parameters for passing a password), and I cannot get any additional packages like sshpass.

You would have to re-implement what SSHPass does: "Sshpass utilizes the pty(7) interface to control the TTY for ssh"

There is no other way.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Promise.all still runs everything asynchronously doesn't it? It sounds like he wants one to complete before another starts, if I'm understanding his post.

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

Skandranon posted:

Yes, it does. That is usually how you would want to do things. You'll get your cards, then once all cards come back, you'll get your card details. Why would you want to get card1, then card2, then card3, etc? Are you wanting to simulate properly drawing cards from a deck? If so, I'd create a route that lets you "draw 3 cards", which will let the server properly handle pulling 3 cards from the deck, and then return all 3 at once.

I'm not trying to do anything outside of read that guys post, which said

Geno posted:

I'm trying to figure out a way for the AJAX calls for the card info to only be created after the previous card's AJAX is fully done. For example, card 1 and 2 load but not the card info yet. I don't want the AJAX for card info 2 to be created until the AJAX for card info 1 to be fully done.

My intent was to point out that Promise.all does not do what he asked, unless I misread his post (which I didn't).

necrotic
Aug 2, 2005
I owe my brother big time for this!
That's because its not sugar; The sugar for binding is {object}::{method} and is supposed to come out with ES2017.

https://github.com/zenparsing/es-function-bind

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

Munkeymon posted:

I mean all the class ceremony. Making the language look more familiar to people used to non-prototypal inheritance doesn't do a ton of good if they're just going to run headlong into the prototype complications as soon as they try to do anything remotely interesting with their 'class' but at least now I understand what the bind operator is coming in to fix.

Ah, yeah. There's going to be a lot of fun issues that pop up because people assume its not a typical class system. its almost like people should learn the language they use, no matter how piss poor it is.

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

Skandranon posted:

JavaScript is meant to have semicolons at the end of lines, it is just not strict about it. You should use them.

Speaking of, you should 'use strict'; as well.

necrotic
Aug 2, 2005
I owe my brother big time for this!
edit: whoops, refreshed and there's more!

Yeah, what Depressing Box just posted is the correct way. Your parent should never know about the children state, and vice versa. The idea is to make testing _easier_, not harder.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Isn't the result of $.csv.toArrays(input) exactly what you want for studentData? I don't think you need to do anything else if you want it as an array of rows and each row is an array of columns.

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

stoops posted:

That worked, phew. THANK YOU!

Yeah, CSV doesn't encode types so everything is a string. I'm surprised whatever graphing lib didn't handle the coercion for you, though the parseInt approach is definitely better.

You can also use map so you don't have to loop yourself:

code:
var data = $.csv.toArrays(csv).map(row =>
  row.map(val => parseInt(val, 10))
);

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

Skandranon posted:

Not sure about native ES6 support, but TypeScript turns it into a straight up for() loop without any closures at all when targetting ES5.

Yeah, forEach is in most browsers now (all?) and writing a shim is super simple for older ones.

If TypeScript is not hoisting the closure when transpiling thats loving dumb, though.

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

Skandranon posted:

How is that dumb? A closure is not needed, just like you do not need one for a for() loop.

forEach takes an anonymous function. Is TypeScript transpiling forEach(function(e) { console.log(e) }) to:

code:
for(var i = 0; blah gently caress blah) {
  (function(el) {
    console.log(el)
  }).call(null, el)
}
or

code:
for(var i = 0; blah gently caress blah) {
  console.log(el)
}
or

code:
var handler = function(e) { console.log(e) }
for(var i = 0; blah gently caress blah) {
  handler.call(null, el)
}
The first one is creating a new closure every iteration of the loop. The second changes the semantics and would make return gently caress things up. The latter seems like the "correct" transpiling approach.

However, the best is just to define a forEach shim and not transpile to ES5 at all.

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

Skandranon posted:

I was not talking about forEach. I was talking about the ES6 for...of(). It translates for...of to a for() loop. There are no closures because there are no passed functions, there is just inline code.

My bad, I mixed it in with the forEach talk.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Which ie? Does ie even support inline functions like that map call?

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

Depressing Box posted:

When would you want to use reduceRight() instead of reduce()?

and otherwise it seems like they'd give you the same result (outside of doing something messy with implicit conversion).

If you're doing a sum sure, but other mathematical operations would give you different values. Or as you mentioned, gross implicit conversions.

Also, javascript has generators now for infinite lists. Though I'm not sure if you can use reduceRight on those? I haven't really touched generators.

necrotic fucked around with this message at 21:36 on Jul 26, 2016

necrotic
Aug 2, 2005
I owe my brother big time for this!
You can also use the actual debugger and break at the entry point and really step through. If you wanted to break in the success callback you'd have to add another one there, too.

You can break in code with debugger and the console open. Works pretty well.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Agreeing with facts is a good way to get ahead in life.

necrotic
Aug 2, 2005
I owe my brother big time for this!
You can get buy writing a decent amount of modern JS without transpiling. One of the biggest things you'll lack is a proper module system, though.

It's unlikely babel will get replaced, at least anytime soon. Hopefully they won't completely rewrite the core again.l and break everything. Lol who an I kidding of course they will.

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

Skandranon posted:

You can potentially cache 100s of mb if you want to (don't do this, you'll surely upset someone).

The spec defines a (suggested) "arbitrary limit of 5 megabytes per origin", and most browsers default to around this.

https://html.spec.whatwg.org/multipage/webstorage.html#disk-space-2

I think Opera and FF let users change this limit, but Chrome doesn't.

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

Skandranon posted:

I did not know this... and this is actually very consequential. Thanks!

Imagine the poo poo show if there was no limit. Webdevs endlessly caching dumb data and never purging it, oh poo poo its using 5gb of my HDD for one website!

necrotic
Aug 2, 2005
I owe my brother big time for this!
That doesn't help if he wants the key enumerable when a value is present.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Nothing exists in stdlib for that. I'm not familiar with any libraries that do that, but you either need one of those or write your own.

Adbot
ADBOT LOVES YOU

necrotic
Aug 2, 2005
I owe my brother big time for this!
:not([data-expand]) :input? If the parent has the attribute then it needs to come first in the selector.

edit: I didn't read the whole question and that probably won't do it either.

With the layout you have you cannot really do that, as the "hearing" level is a parent of checkboxes B, C and D. You need to move that attribute so its only a parent to B, or introduce a new one. And then the selector needs to be something like [data-expand="hearing"] :input

necrotic fucked around with this message at 17:05 on Nov 14, 2016

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