« first day (1646 days earlier)      last day (3307 days later) » 
00:00 - 16:0016:00 - 00:00

4:00 PM
I've been looking for a lightweight promise-based ajax lib. i might just start with somekittens's example and expand as needed.
still using jquery (ducks tomatoes)
 
@SomeKittens what the fuck happened to Andrew Barber :O?
@thePetProjectProgrammer generally, that's a better way (in case other people hold a reference, but you can pass an object and have your modified reference as a property of it to get pass-by-reference
 
@BenjaminGruenbaum That's Billy Crystal
 
@phenomnomnominal Holy Skull Seizures, Batman!
 
That would require all other users of that string to also hold a reference the the wrapper object and keep using it.
 
4:03 PM
@BenjaminGruenbaum what might that property be? I am unable to spot anything obviously named (browsing MDN)
 
He's suggesting to put the string inside another object like:
var stringWrapper = { theString: "dfdss" };

functionThatModifiesString(stringWrapper);

console.log(stringWrapper.theString); //will output the modified one
was I wrong?
 
eep
 
pictures of pre-women?
 
no idea
Don't want to make accusations, not gonna say anything.
These things can be destructive and people deserve benefit of the doubt.
 
well, i have no idea who any of those people are.
 
4:09 PM
Yeah lol
 
but, yea.
 
Don't worry about it
 
Also looking for some editing/review:
 
@SomeKittens I actually consider equity a lot when looking at offers
 
really?
 
4:13 PM
Yeah, I had an hour long chat with a friend yesterday about bargaining for more equity over salary. Also, a big part of equity is that it's usually given with a 4 year vesting period which is incentive to stay at the same company for 4 years.
(a quarter each year)
 
Yup, didn't go into vesting in that article as I felt it wasn't relevant
 
The concept isn't just getting a more motivated employee - it's getting them cheaper and giving them incentives to stay even if you don't give them raises.
 
Vesting works slightly different here though - nothing for a year, then 25% as a lump, then montly
 
Yeah, the year is still a big part of it, you have motivation to stick around if a better offer comes along after 6 months
 
but that only motivates one to stay longer - not work harder
I should address that though
 
4:16 PM
There is a surprising amount of scientific research on how to motivate employees by the way, I can ask my wife about it if you'd like she took a course about it
(In the university)
Not saying that's a good paper, just what I googled
 
how's life?
 
Pretty good, got accepted for a pretty big conference in Israel. Working on interesting stuff.
 
nice :)
yeah saw the conf, labelled as "core io.js contributor"
hehe
 
4:32 PM
> Higher profits in turn cause them to reciprocate with better job performance in the subsequent period.
 
I told them it's not true :/
 
Interesting
 
@SomeKittens note that it's profilts and not shares
 
@BenjaminGruenbaum Yes, my assumption is that these are public companies?
 
4:33 PM
> roughly 4500 managers in a large public company
yep
That makes sense, too
it's very easy to see a direct line between your work and profits (quarterly, as opposed to "sometime, in the theoretical future")
 
@BenjaminGruenbaum How’s that?
I was under the impression that it hadn’t even started yet
 
@minitech cancellation and promises and stuff
 
@BenjaminGruenbaum What?
 
Long story
 
> The authors estimate that it would take a seven-fold increase in the amount of options held by the typical employee to generate the same job performance effects as a doubling of the employee’s profits on exercise of stock options.
That'll actually be a good point for my article
Once employees see the relationship between their work and $$$, they work harder (for up to a year)
 
4:38 PM
@BenjaminGruenbaum Can something important about the story be summed up in a sentence?
I cannot find anything about this
 
@minitech cancellation is inherently problematic given promises being eager and immutable and multi consumer - people disagree on how it should be done and they become demotivated.
 
@BenjaminGruenbaum I wasn’t aware that the fetch API promises were cancellable
Do they even need to be?
 
Not really
 
Anonymous
are js noobs welcome here?
 
Anonymous
4:52 PM
thanks :)
 
@samaYo The one type of noob behavior we don't allow is asking for other people to write one's code for them.
 
Anonymous
@SomeKittens I am not that kind of noob.
 
We'll be the judge of that.
j/k :)
 
Anonymous
ok then, see you on judgement day :p
 
@samaYo I figured. Those noobs typically arrive and dump a pile of code
also, 4k rep isn't too shabby
 
4:55 PM
didn't know about \Q...\E in regexes
QUOTING

         \x         where x is non-alphanumeric is a literal x
         \Q...\E    treat enclosed characters as literal
 
what if you want to enclose \E?
 
@FlorianMargaine OMG THIS WORKS IN JS?
 
Anonymous
@SomeKittens yeah good thinking, and thanks.
 
Yay, random downvote on the dupe
Oh, it's not random
Why would you ask a question that you a) know the answer to, b) have asked yourself before half a year ago and c) mark it yourself as duplicate to your own question? I mean, seriously, this is complete nonsense. — Tomalak 2 mins ago
 
I knew someone would notice
 
5:03 PM
@Tomalak people ask a lot about the promise constructor antipattern and why it's called an antipattern not realising it's the same thing as the deferred anti-pattern. I figured out the best way to approach this on Stack Overflow is this. The point was to create a searchable target for this pattern that reuses the answers on that other question. We see this question pretty often and the terminology is interchangeable. Asking questions in Q&A style is encouraged here, canonicals are good. If you think I should bring it up on meta I'll gladly do so. — Benjamin Gruenbaum 1 min ago
:/
Why the hell does that question have a reopen vote...
 
@BenjaminGruenbaum Probably same guy voted to reopen
 
@jemz yes
 
@BenjaminGruenbaum no idea, it's PCRE
 
!!> /\QHello\E/.test("Hello")
 
@BenjaminGruenbaum false
 
5:08 PM
hmmph
 
-1
Q: How turn on and off a 100 watt led with Javascript

CarlosHRGI need to know if posible to control a led like this with Javascript, how can I connect a laptop to this led powered by the electrical home network and turned on/off? Thanks in advance.

wat
How many JS developers does it take to switch a lightbulb?
 
haha
omg
 
@SecondRikudo specifically, 100 of them
 
5:11 PM
Javascript only works with 50 watt led
 
Now seriously - can Node access USB devices?
 
@JanDvorak By the power of @rlemon, they can even access serial ports
 
Now I just need a serial port :-)
 
Is it reasonable to call iterator variables, e j k i o u w p q y x z?
 
e???
 
5:16 PM
I use e a lot.
 
dat order is suspicious
 
for(i..)for(e..)
That is an unordered list btw
 
it is not reasonable to have 12 nested for loops, no
 
Sometimes. How big is the scope of the iterator?
 
2 nested loops maybe, 3.. ?
 
5:17 PM
0
Q: Deliberately opening duplicate questions as search targets

Benjamin GruenbaumIn the last year and a half I've answered almost 500 questions in the promise tag. We have a rather small community there and we like to open canonicals such as this one this one or that one. They usually help a lot with duplicates and are generally very useful to us. One canonical in particular...

Backup would be nice.
 
I was wondering what should I call the variables i = 0; i < ..length; i++ ..
 
@Catgocat logical lines
 
wat
 
I mean, if it's a three-liner, you don't need a descriptive name. If it's a 3k-liner, you do.
 
And if it's three-liner, what variables would you use?
 
5:19 PM
now that I'm not hourly I don't feel as bad playing video games at work after everyone is gone
 
i e and j ?
i j and k?
 
@Mosho I didn't know you're not hourly, we shall discuss this on Wednesday
 
yes master
 
damn right son
 
5:36 PM
@Mosho Congrats!
 
thanks :>
 
@Tomalak it's not rickrolling at all. Rickrolling is when you expect a link to something and end up here (instead of what you wanted). What Benjamin has constructed is the StackOverflow version of Google's "Did you mean" function. — SomeKittens 1 min ago
 
I was in the process of writing an elaborate answer with a number of reasons why all this is not a good thing, but they all start to feel pretty contrived now that I've thought about it some more. Technically there is nothing wrong with this and it has potential benefits. I'll remove my downvote on your question (I think you have to edit it for this to work). — Tomalak 1 min ago
success
 
6:05 PM
@JanDvorak what a bro
 
hi, I am creating a "class" that takes some parameters in its constructors, and I want to process then inside the ctor itself. How can I do this in a way that every instance of the object gets that processing method? Can this C++ paradigm be applied to JS?
 
Using bluebird.js breaks azure
Failed to load script file 'sendOtp.js': TypeError: Cannot read property 'configurable' of undefined
with a very non-helpful message.
 
@thePetProjectProgrammer Yup.
 
@thePetProjectProgrammer I can't even understand what you want, but it should be possible
 
Any assistance my friends ?
 
6:54 PM
Lemme find a good commented exampel of a class in JS with instance methods, etc.
 
I am trying to do something lime this
var Person = function(name)
{
this.name = name;
var mod = function(){this.name = "mr. " + this.name; }
mod();
};
I want mod to be present in every instance of Person to be able to process the name.
 
close. put mod() on the protoype like in that link and you can call it with:
this.mod();
 
It seems this.prototype is specific to the object at hand and is replaced everytime.
 
search that page for: Person.prototype.sayHello
No, prototype is for 'instance methods'.
 
Person.prototype is done outside the ctor, so can't use that in ctor.
 
7:00 PM
it's slightly differnt but close
No, you can.
 
Neo
Hi
I need some help with regEx
 
They may be defined later in the file, but the constructor isn't CALLed until later
 
Neo
I have to extract from a string all the numbers that have before them a certain string
can someone help me ?
 
@Neo use a capturing group for the number
 
I am trying to make it behave like C++, may be that's my problem. May be in JS things are two step process?
 
7:01 PM
You can do exactly what you want. start with defining mod() on the prototype.
we'll go from there
 
This is what I have. Firefox debugger shows the call to mod goes to speak.
 
Neo
var st = "X n°13243 something n° 1234"; var tab = st.match(/^n°$\s/gi); alert(tab);
 
var Person = function(name)
{
this.name = name;
this.mod = function(){this.name = "mr. " + this.name; }
mod();
};
Person.prototype.speak = function(){alert(this.name);};
 
Neo
@JanDvorak Can you give more precisions please, here is what I tried so far : var st = "OF n°13243 something n° 1234"; var tab = st.match(/^n°$\s/gi); alert(tab);
basically I want to extract the numbers that have "n°" or "n° " before them
 
No you are creating a new mod function on each instance instead of sharing one
speak, however, is a proper instance method
 
7:05 PM
!!tell neo google regex capturing group
 
@thePetProjectProgrammer jsfiddle.net/oqmcho4o/1
 
var Person = function(name) {
	this.name = name;
}

Person.prototype.speak = function() {
	alert(this.name);
}

Person.prototype.mod = function() {
	this.name = "mr. " + this.name;
}
@thePetProjectProgrammer
 
I want it to be a one step process, as in, var p = new Person("mister") and expect p.speak() to say mr.mister. Seems with JS its a two step process.
 
look at my link
 
7:10 PM
class Person {
     constructor(name){
         this.name = name;
     }
     speak(){
         alert(this.name);
     }
     mod(){
         this.name = `mr. ${this.name}`;
     }
}
 
ES6 works too :p
 
Much nicer.
 
true fact
 
True, but I didn't want to introduce that (which would likely require transpilers, etc)
 
Although of course no one has ever made a Person class anyway.
 
7:11 PM
It's a universal example.
 
A bad one
 
The class I always have trouble with is the bourgeoisie because they control the means of production
 
the booj-wa.
 
I use animals
dog does rofl
cat does meow
 
9
Q: Kitten can't speak

SomeKittensI'm running through the mongoose quickstart and my app keeps dying on fluffy.speak() with the error TypeError: Object { name: 'fluffy', _id: 509f3377cff8cf6027000002 } has no method 'speak' My (slightly modified) code from the tutorial: "use strict"; var mongoose = require('mongoose') , db =...

 
7:13 PM
and Benjamin does Mooo
 
@thePetProjectProgrammer That work for you?
 
...what? Who downvoted that?
 
perhaps it's due to the unhelpful title?
 
Not me, but that subject isn't a good one. :)
 
Not me either
Vote Down requires 125 reputation
I have 104
:p
 
7:19 PM
@Luggage hmm nope. I think I'll stick to two step process for the moment. I am only hacking something together, so I'll dig deeper later. Thanks.
 
My example covers your need precisely.
 
@Luggage no it doesn't. I want a one step process. with your example p.mod() must be called explicitly. Anyway, like I said, it isn't crucial for now. Thanks for the time.
 
No it doesn't
 
@thePetProjectProgrammer the constructor can call it just fine
 
Like my example does.
 
7:22 PM
@thePetProjectProgrammer ok see you in nasa
 
It's liek he looks at the solution and just won't beleive it really works
there i took out the second call which was showing that you could ALSO call it separately, @thePetProjectProgrammer
 
The fiddle didn't run for me, so I assumed. Sorry if I was wrong. I am with JS only since last week/
 
ohh. did you have the console open (F12) to see the output?
i didn't write any html, just to the debug console.
 
You know what happens when you assume?
 
mathematics?
nice chatting. thanks to all who took time.
 
7:25 PM
@thePetProjectProgrammer goodreads.com/quotes/…
 
!!xkcd assume
 
^ @JanDvorak
 
night
 
@SomeKittens you're welcome
 
Here I go to learn python and I get this:
m = [1, 2, 3]
n = [4, 5, 6]

// Join lists
m + n
 
Just ran into this again: gist.github.com/Zirak/3373067
 
@Zirak we lol'd about that last week.
@Catgocat Python has lists, and not arrays.
 
Yes that
 
@BenjaminGruenbaum What amazes me most is that it ran on first write, and all subsequent additions
 
7:43 PM
@Zirak you weirdo
Pretty sure that makes you a saint
 
@BenjaminGruenbaum They're arrays though
 
@copy the same way a C# List is an Array.
 
My bookshelf is an array.
 
@BenjaminGruenbaum The same as JS arrays, no?
 
My git repository for (azure mobile backend) has 250 commits with "F*** you microsoft for no debugging tools"
 
7:52 PM
@copy yeah, but in JS it's called an array. In Python it's called a list. If you talk to python people they'll use Python terminology
 
8:31 PM
One thing I don't like about a lot of programming books: They offer "big tasks" (ex: full websites, games) that are extremely boring to do
 
8:53 PM
I'm trying to return validation errors to my client. Are there any 'standards' or at least some API with a good model I can copy off of?
 
@copy or js' arrays are actually lists?
in pretty much every C-structured language arrays are non-expandable whilst lists are, right?
so why are js' lists called arrays?
 
Cuz Java
 
9:11 PM
oh hey! The youtube icon just changed...
that's like the most relevant thing that happened to me today, sad story
 
also, dicks, read my thing (pinned), and rip it apart
 
had read to about 1/4, after I saw the wall of text I gave up
 
feedback on the first 1/4 then?
 
it felt pretty nice to the eyes, but I guess I wasn't in the mood for specific test explanations...
so it might just be me in that moment
right after the cucumber part
 
Can anyone give me an example how not using modules actually pollutes the global scope? I understand that variable names are likely to collide, but I can't picture in what form external non-modular code would be loaded
 
9:22 PM
in node.js, all .js files are modules anyway. You have to explicitly pollute the global scope using the global.someVariable = ...; (which you shouldn't do).
So you'd need to put more work into avoiding modules than just using them.
 
@Luggage Did nodeJS boot CommonJS out of the toolbox for the core of developers?
 
hm?
 
Is commonJS obsolete now?
 
No.
 
NodeJS didn't overtake it's functionality?
 
9:26 PM
node.js is commonjs with some add-ons.
 
@Luggage You're always helping me out when you're around
 
ok, so THAT spaceplane failed
My drone program was a partial success though
 
@StevensHaen Writing for node, the browser, or both?
 
@Luggage You've probably answered 20 of my question so far
 
But who's keeping score..
 
9:34 PM
How do I attach an ion drive to a rover?
I can only get it on top and bottom
 
Right now, I'm half way through "Eloquent JS" and am about to start building my first modular NodeJS app
 
@SomeKittens Might be ablt to use the new adjustments to attach to the top or bottom, then just rotate nd offset to place where oyu want.
Stevens: then just stick with the normal nodejs style of require() and module.exports.
There are also editor plugins that allow you to surface attach even on parts you normally can't.
 
I should add some mods
 
@Luggage But should I define the functions in the module first and then choose the exports at the end, or should I return multiple functions in an object, or should I use an export argument and add the methods to it?
 
Only have MechJeb/Engineer/Science thingy now
 
9:38 PM
All of the above. Use what is most readable to you.
 
@Luggage WWAPD what would a pro do?
 
They would use the style that's the most readable to him/her. And once you pick a style you like you'll find exceptions and have to break that rule.
 
The real question is "Why are you building an ion-powered rover?"
 
In those examples, they both use an exports style that makes sense for the content but both could other another style.
 
This is the easiest implementation, that's what I've used so far. I imagined experienced devs cut it short in some way. ..
 
9:45 PM
I can't imagine how.
 
var names = ["Sunday", "Monday", "Tuesday", "Wednesday",
             "Thursday", "Friday", "Saturday"];

exports.name = function(number) {
  return names[number];
};
exports.number = function(name) {
  return names.indexOf(name);
};
I mean, it's similar, but not as human readable still
 
module.exports = {
    name: function(number) {
    },
    number: function(name) {
    }
}
if you like that better.
 
function require(name) {
  var code = new Function("exports", readFile(name));
  var exports = {};
  code(exports);
  return exports;
}

console.log(require("weekDay").name(1));
// → Monday
 
Why do you have your own require()?
 
the example is overwriting it for some reason, not a good one
(function(exports) {
  var names = ["Sunday", "Monday", "Tuesday", "Wednesday",
               "Thursday", "Friday", "Saturday"];

  exports.name = function(number) {
    return names[number];
  };
  exports.number = function(name) {
    return names.indexOf(name);
  };
})
How does this exports work as an arg?
 
9:50 PM
code(exports);
you are calling it with an argument.
 
Example comes from a book
Why is it passed as an arg?
 
Because commonjs works that way, you put your exports on an exports variable.
You pass in the exports variable to alter in the argument so that you have one to alter.
 
In my first example, it wasn't passed, yet still used in the body
 
node.js takes your .js file and wraps it in that function(exports) already, you don't need to do it youself.
You are just mimicking node.js
 
Well, I need to see how it works first
 
9:53 PM
Yes it was, I pasted the code that passes it, "code(exports);", the third line of your require()
 
My first example way up
 
becasue node does that for you, I just said that.
 
I read what you said, but it's not stated in the example. I mean, one time they pass it, another time it's just default behaviour
 
Well, I'm not reading the book so I don't know what they are saying
 
9:55 PM
but.. node.js already gives you a require() and wraps your files in functions.
so.. it's redundant
Just don't do it. Don't use your own require and don't make that function(exports).
But those last two code exampels are showing what node alreadt does for you
(and more)
 
"Eloquent JS" does waste one's time to an extent
still a good read
 
It's nice that it shows you how require() works, but it might be working even when you forget parts becasue it's already there
so it'll confuse you
 
I agree
The simplistic implementation of require given previously has several problems. For one, it will load and run a module every time it is required, so if several modules have the same dependency or a require call is put inside a function that will be called multiple times, time and energy will be wasted.
That's wrong. NodeJS doesn't load the same module twice
 
But that simplistic require() DOES.
it's going around node and loading the file itself and executing it.
Just move on and stop using their dumbed-down require and use the normal one.
 
Ok
What's the problem with exporting constructors?
 
10:01 PM
in node, nothing. I do it all the time.
with plain commonjs, i think you only get 'exports', not module.exports.
Therefor you can't replace exports, only add to it
module.exports = function MyConstructor() { } //completely OK
exports = function MyConstructor() { } // I just threw away the old exports value so this isn't really exported.
in node, just use module.exports all the time and you'll be fine.
This is where node.js deviated from plain commonjs.
 
So, is nodeJS primarily for making server side apps with JS>
Why not just plain old PHP?
 
Only server-side, yes.
for starters, not everyone LIKES php.
Also, node.js's async nature makes it different. You can do that in other languages but node.js makes everythign async.
 
I actually find PHP easier to digest than SS JS
 
Also, I have code that I use in node.js on the server AND in the browser. Sharing code like data validations is pretty nice.
The same code gives the user live feedback onthe web page AND validates on the server before I save changes.
So I only have to write some things once.
 
Oh, that would be a great implementation. So, let's say, a pass/coupon value doesn't have to be POSTed to PHP?
 
10:07 PM
Well, you always need server-side validation, too, or anyone can 'hack' your app just by altering the client-side js
which anyone can do by hitting F12.
 
That's an obstacle, a big one.
So, security is similar to regular client-side val
 
Yes, but being able to reuse code on client and server is useful at times.
my current project is 100% JS, client and server
 
So nodeJS caches modules it's already seen before?
 
src/client
src/server
src/shared
 
is your JS exposed ? Can I access it via my browser?
 
10:10 PM
It's not open source, if that's what you mean.
and the client can't get to src/server
I was just pointing out that I have a shared folder full of JS code the might be useful on both sides.
 
function require(name) {
  if (name in require.cache)
    return require.cache[name];

  var code = new Function("exports, module", readFile(name));
  var exports = {}, module = {exports: exports};
  code(exports, module);

  require.cache[name] = module.exports;
  return module.exports;
}
require.cache = Object.create(null);
 
I'm not interesting in re-creating any more require()s
But yea, node.js only loads a module once, typically.
 
I know. My question
would be
is there a case where overwriting the module object is useful?
 
Supposedly, it might be loaded more than once if you refer to it differently, like require('../someModule.js') in one file and require('./someModule') in another.
but in practice, I haven't seen that be an issue
 
We now have a module system that uses a single global variable (require) to allow modules to find and use each other without going through the global scope.
 
10:14 PM
I think it's best to only load a module once. If you need it to 'run' multiple times, then it should export a function instead of just values.
think of the require() as an 'import' from other languages.
 
like include, which requires just once.
Do you happen to use Browserify or not?
 
is that php? I'm not familiar, but probably.
No, I used requirejs for the client on a couple projects, and am currently using webpack
 
I've used require before and liked it
AMD is cool
 
11:00 PM
so hard to find a working cross-browser beforeunlaod..
 
11:40 PM
!!tell loktar youtube hope dies last unleash hell
 
Me gusta!
 
s/M/¡M/
@StevensHaen AMD is natural.
 
Still learning about modules
 
CommonJS is organic.
 
11:46 PM
:-D
 
@SterlingArcher read my shit --->
 
The dichotomy between Scheme and C.
It's funny, but I never thought that a functional language with C-like syntax would be practicable. And yet it turns out that it's really very straightforward.
I guess everyone else felt the same, given the way that JS has taken the programming community by surprise.
 
00:00 - 16:0016:00 - 00:00

« first day (1646 days earlier)      last day (3307 days later) »