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
Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
So this is dumb, but I'm working on an application with my team that seems to have randomly stopped logging runtime error messages -- I can [].butt('fart') and the task will abort but not log an error. It's like something is globally catching exceptions. window.onerror is not set. The application is loaded and run through RequireJS.

Any ideas where to start looking?

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Munkeymon posted:

Yeah, I'm gonna miss that when 12 finally gets too far behind the times to justify using. RIP Opera's good days :(
Opera's been WebKit-based for awhile now - where are you afraid of it falling behind?

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

IT BEGINS posted:

Not sure if this belongs here or the PHP thread, but I'm wondering if there is a good way to pre-load JSON data from a PHP script into a javascript variable. Basically, I'm having to support a lovely back-end report system where I need to output an editable table. I'd like to do this with angular, but I can't use an http request after the page loads to get my JSON results from the report - the JSON has to be generated on the original request only. I've tried doing something like:

code:
<script type='text/javascript'>
    var data = '<?=$data?>';
    var json = JSON.parse(data);
</script>
However, this fails for very large JSON for unknown reasons [just an error like "Uncaught SyntaxError: Unexpected token <" ]. I tried dumping it into a hidden input field with similar results. It also seems really bad to me to be doing this. Am I being foolish or missing something simple?
base64-encode your output.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

HardDisk posted:

Can someone point me to a decent Angular tutorial? I already completed Google's phonecat, but I still don't have much of a clue to what I'm doing in general.
http://www.egghead.io

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
As awful as this line of logic actually is, it's getting very Slashdot in here

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

revmoo posted:

Long shot; I need to automatically loop scroll an unordered list with slide movement animation every few seconds that pauses on mouseover. Anybody know of a snippet?

I've tried a few different methods including doing it from scratch and I haven't been happy with the results.
Mind a quick MSPaint or something so we know exactly what you're looking for?

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
"Javascript navigation" and "static site" don't go well together in this context, unfortunately. If you care about SEO, you really should be serving complete documents from the server and doing progressive enhancement.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

neurotech posted:

I'm currently reflecting on a solution to my first real challenge in a new project I'm working on.

I have an API endpoint that is spitting out a JSON blob which changes every 5 minutes. I want to build a simple front-end that does the following:

  • Polls the feed every 5 minutes and parses it
  • Traverses the parsed results and binds the various keys to various HTML elements
  • Updates said HTML elements with the relevant values associated with each key
  • Animates the changes in some sort of interesting way

My current plan is to use jQuery to poll the whole feed with .getJSON() and .setInterval(), then perform a whole bunch of chained jQuery methods on the various HTML elements.

Can anyone recommend a better way to do this?
Depending on exactly what you're trying to animate, D3.js might be a better option than jQuery since it's really built for exactly this type of dynamism up front. If you just need basic transitions for regular HTML elements though, Transit sounds like what you want for animation.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Chenghiz posted:

Why is it that every new hot database seems to be key/value? Are relational databases like postgresql and mssql just that perfected/done?
Most of the features of traditional relational databases (joins, multi-table transactions, etc.) become totally useless (as in they don't work anymore) when you need to start sharding your dataset across multiple server instances.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Suspicious Dish posted:

Just the fact that it seems like a lone IT guy going "I know how to make it better! Computers!!" and building some system nobody actually really likes.
I've been this guy more times than I can count.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There's also JavaScript Allongé if you want to annoy the poo poo out of all your coworkers by writing Lisp in Javascript.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Subjunctive posted:

That's not my recollection, and I think I was the first person to implement JS exceptions. JScript had a bug where it created the variable in the enclosing function's scope, rather than one that matched the duration of the catch block, which I think is the opposite of what you're describing, but exceptions were always specified to create a new scope chain entry with the identifier bound.

15 years, though, so yeah I'd love a reference if you have one.
The people we get on these forums :swoon: :sparkles:

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

necrotic posted:

JavaScript code:
getArticle().spread(replaceImages.bind(this, article, meta));
would be
article and meta are undefined in this scope

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Wheany posted:

Welp, that's pretty conclusive.
If you think that's bad, you should see the part in the standard where they explicitly tell implementers to calculate DST incorrectly instead of using the system's date/time facilities. (Thankfully, this one will be fixed in ES6.)

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

necrotic posted:

The only way to ensure order is using arrays, objects in Javascript are not ordered. For a 2D grid, use a 2-dimensional array where the first dimension is rows and the second is columns.
This is true for the table data. You'll also want some kind of ordered lookup with row and column names.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

ExcessBLarg! posted:

"i++" exists because it's a distinct operator (post-increment) and in compiled languages (e.g., C) often translates to an increment instruction in assembly. Modern C compilers should observe that "i+=1" and even "i=i+1" are the same thing and optimize them accordingly, but this wasn't always the case. It exists in JavaScript because of it's prevalence and familiarity to users of C-family/inspired languages.
It also makes more sense if you understand that there's also a pre-increment operator (++i) and the two are used differently. Where the post-increment operator evaluates to the value of the variable before modification, then increments the variable, the pre-increment operator does the reverse, incrementing before it evaluates to the updated value. In other words, these two are algorithmically identical:

code:
i = 0;
a[i] = 42;
i = i + 1;

--

i = 0;
a[i++] = 42;
versus the pre-increment operator:

code:
i = 0;
i = i + 1;
a[i] = 42;

--

i = 0;
a[++i] = 42;

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

I hate promises and callbacks. I just cannot get my dumb head around them, I feel hopeless and lost, and I've read almost every resource I can find on it.

I have a simple problem, I am writing in node, I have a postgres database. I want to use pg package to return the results of a query. I want to do this async using promises. But I honestly don't even know where to begin or how to do it. It seems like the pg's query function is blocking, so can I just not use promises with it? I honestly am so confused. My brain is so bad at async.
Promises are for async code, not for sync code. (You can technically use them with sync code, but why?)

If you suck at async code, you either suck at modeling the flow of the problem you're trying to solve, or you suck at doing something with the state you get back. Once you stop leaking state all over the place, it just becomes a way of decomposing your flow into different chains that execute at the same time. It might help if you flowchart the path of remote data through your program. If nothing else, it can help us write some boilerplate code for you to start with.

Think of a promise like a box that might have a value inside. When you do something (.then()) on the resolution of the promise, you're basically saying:

  • If this box already has a value stored in it, do this thing immediately.
  • Otherwise, do this thing as soon as the box has a value stored in it.

There's nothing crazy or complicated about that, the promise chain is just some code sequence sitting around until someone dumps a value in the box.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

I guess I am just confused as to how to wrap something in a promise or how to start a promise off. I just hate promises.
If you need to interact with a library which does not natively support promises, then most promise implementations like when.js or Bluebird or whatever contain a lift() function which takes as a parameter a (possibly Node-style) function and wraps that function to return a promise instead. So instead of

code:
mymodule.myfunction(a, b, c, function (err, data) {
    if (err) {
        // handle error
    } else {
        // do something
    }
});
you have

code:
node = require('when/node');
myfunction = node.lift(mymodule.myfunction);
return myfunction(a, b, c)
    .then(function () {
        // do something
    })
    .otherwise(function () {
        // handle error
    });

Vulture Culture fucked around with this message at 19:02 on Aug 10, 2015

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There's a few other (simpler) ways you can do this.

Using bind():

code:
function1()
    .then(function2.bind(this, 'someArg', 9000))
    .then(function3)
    .done();
Using anonymous functions:

code:
function1()
    .then(function () {
        return function2('someArg', 9000);
    })
    .then(function3)
    .done();

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

Thanks for the examples guys, is there a "standard" way to do it or is it the wild west? Also is using higher scope variables a bad idea?
Globals are a bad idea in any programming language, but it really depends on the specific context (heh) of what "higher scope variables" means here.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

piratepilates posted:

Edit:I will say, one nice thing to say about the maturity of the Facebook stack is that it is being embraced in production by (one of) the most widely used websites today. I believe the big ticket item for angular these days is still the YouTube app on the PS3.
Angular was written by the DoubleClick team within Google and the entire DoubleClick frontend platform runs on AngularJS. It's been the largest production AngularJS project for a long, long time.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Lumpy posted:

Because then you only have to bookmark one site for all your documentation!
stackoverflow.com!

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Odette posted:

Is node.js really that bad?

Just wondering cause I'm trying to learn the MEAN stack as opposed to a standard LAMP stack.
A lot of the problems are overblown, especially since io.js was merged back in and Node itself seems to be going in a sane direction again, but there is a problem with a lot of Node.js libraries and frameworks being real poo poo. Your average NPM package has about the average quality of something from PEAR.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

Speaking of node and js, what is the standard way to declare functions? is it:

code:
function myFunc(poop) {};
OR

code:
var myFunc = function(poop) {};
I've seen both ways, both being used by novice and expert coders alike.
It really just depends on where you want the function's name scoped

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Jabor posted:

Choosing the technologies you're using based on whether the first letters can be made into a word is really dumb, hth.

Chances are high that anyone using MEAN has made completely the wrong decision for at least one of the components, and since everything's relatively new tech you don't even have the advantage of heaps of people treading the same road in the past to help you work through issues.
I agree with your main thesis here in the sense that MongoDB is almost never a good decision, but the "relatively new tech" angle is super-weird. The V8 engine has been around since 2008 and tested on literally hundreds of millions of installations, and all four of MongoDB, Express, Angular and Node.js have been in wide use since 2009. Angular is quite probably the least mature of these components, with people only picking it up around 2011, but having around 43,000 stars on GitHub suggests that "heaps of people" may have, in fact, tread that same road. at worst you're still talking about 4 years of solid dev time with heavy user exposure, which is way different than using someone's open-source hobby framework that hasn't seen a commit in 10 months.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Suspicious Dish posted:

so your website won't have any seo. gj
literally every application must be search engine crawlable, even internal ones or ones that don't display search engine-relevant content, and there is no way to provide any content to a search engine in a single-page application

-suspicious dish

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
One of these things is untrue (guess which?)

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Suspicious Dish posted:

it makes it a whole lot harder. yes, i know about the crazy #! thing
seriously, is this 2011? who writes webapps this way anymore?

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There's also Network Link Conditioner on Mac and tc on Linux.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Maluco Marinero posted:

Yep, that's why no one cares about isomorphic, err universal JavaScript... Except that's not true, everyone cares about universal JavaScript these days because you can't just ship everything to the client and expect a good user experience, from search optimisation to initial page load performance, resilience when the JavaScript defers due to a lovely network, SPAs are just not the magic bullet you seem to think they are.
I was talking about #/whatever URL routing, which nobody does because of exactly the things you're mentioning

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

So here is a stupid question. If I wanted to find a good webhost to set up a decent lamp stack, where would I start. Currently I've only done a setup on a fedora core VM. In the past I used 1and1 for php and mysql webhosting but I am looking for node js and postgres.
1. LAMP is an acronym describing a specific stack, Node.js and Postgres aren't part of it
2. http://forums.somethingawful.com/showthread.php?threadid=3289126

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

my effigy burns posted:

Of course, in the long run I kinda I think we'd be better off if javascript had a king who could make decrees at will.
Also if that guy was Reg Braithwaite

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There was a MongoDB thread but it corrupted itself during a network partition

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There was an Angular thread but it got to be too slow with more than a few posts so now it's a thread about React

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
One reason that people like MongoDB is that in most relational databases, schema updates in large-scale production applications are really, really expensive to do. In MySQL doing something as simple as deleting a column can take your application down for hours or days, and while Postgres handles this much better because of MVCC, you basically never see it run at large scale because of a historical attachment to really janky, bad clustering mechanisms prior to the 9.0 release. In Mongo, gently caress it, there's no schema, so there's no downtime for schema updates.

Your downtime comes when, without warning, important records randomly go missing from your database instead.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Biowarfare posted:

just use postgresql with a single primary key column and a json column

:v:
With the JSONB support in 9.4 and corresponding perf improvements to Generalized Inverted Indexes, this is not an altogether awful idea anymore

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Zasze posted:

4. Express is a framework for building api's so you will only see tutorials for creating api's.
Completely, totally incorrect. Express.js is a top-to-bottom server-side web framework explicitly designed to parallel Ruby's Sinatra framework. There's an entire section in the documentation on using template engines if you want to do some or all of your rendering on the server.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

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!
App servers almost always include some kind of supervisor that will restart the process automatically if it crashes.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

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.
Some of the historical data integrity problems with MongoDB have been resolved, especially in the 3.0 release. Many of the failure conditions that cause data loss in MongoDB are related to partial network partitions, and are very difficult to trigger unless you have a very high write load to a sharded database at the exact moment a partition occurs. A large number can be worked around by requiring a majority of nodes to acknowledge operations to a database/document collection. In other words: these are real problems, and they certainly affect people in the real world, but they predominantly affect applications working at extreme scale, when you absolutely must scale out and you cannot scale up to improve your performance any further. If you're looking to prototype something quickly so you can ship, you can do a lot worse than Mongo -- namely, by picking anything that causes you not to get software into the hands of users. As others have pointed out, PostgreSQL 9.4 has some really great schemaless features also.

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
PM2 is a really robust Node process manager with Keymetrics integration. We use it all over the place.

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