« first day (1116 days earlier)      last day (4057 days later) » 

11:00
yeah, this is way better: )))))
@phenomnomnominal It's at that point you start to ponder the use of a promise library
or you know, CoffeeScript :)
@dystroy he uses one
(but I'm not 100% sure I never wrote a similar sequence of }))
but he doesn't know how to use it...
11:02
@FlorianMargaine badly
Ale
Ale
@phenomnomnominal I might rewrite it in coffescript once I make it working
(I didn't see initialy that @phenomnomnominal was answering to Ale, so I didn't know what code it was related to)
@Ale this is how you use a promise
kindlify = function (image, done) {
    convert.addData(image, "/test.png");
    convert.allDone().then(function () {
        return convert.run('-dither', 'FloydSteinberg', '-remap', '/kindle_colors.gif', '/test.png', '/result.png');
    }).then(function () {
        return convert.getFile('result.png');
    }).then(function (real_contents) {
        done("data:image/png;base64," + window.btoa(real_contents));
    });
};
^ much nicer
Ale
Ale
11:04
Cool
why the callback/promise mixup.. just return the promise ^^
cos like if there is any error then it is not handled
or cannot be even handled
0
Q: How to handle editing a large file for a non-technical user

LukeI have a client who is given a tab delimited .txt file containing hundreds of thousands of rows. I have a user story as follows: As a user I want to take the text file and add a new value at the end of each line which contains the concatenated value of two of the columns. for example if th...

kindlify = function (image, done) {
    convert.addData(image, "/test.png");
    return convert.allDone().then(function () {
        return convert.run('-dither', 'FloydSteinberg', '-remap', '/kindle_colors.gif', '/test.png', '/result.png');
    }).then(function () {
        return convert.getFile('result.png');
    }).then(function (real_contents) {
        return "data:image/png;base64," + window.btoa(real_contents);
    }).then(done)
};
@Esailija because there is a done function... didn't want to change that, I don't know his caller code :?
11:12
.nodeify(done)
stupid callbacks
yeah it should have err as 1st argument anyway
if it's node style callback you can do
.nodeify(done)
then it won't swallow the return value
@Esailija oh btw, remember my parser? I didn't want to bother yet with changing everything to promises, here is how I did it: github.com/Ralt/fastjs/blob/master/lib/parser.js#L81
hate me :D
I'll change it when the parser will work ofc
but for now... I just want to take care of the logic, not that ~~
11:15
@Esailija oh btw how do you return a value in a promise? Promise.fulfilled(data)?
that or Promise.cast(data)
returns a fulfilled promise for data
if it's not a promise
what's the difference?
I'd like to be able to do more things in a synchronous manner in NodeJS because I use it a lot for scripting, but I guess .coroutine or .async in Q solve that.
Ale
Ale
convert.mkDir("/usr/local/etc/ImageMagick/").then(function() {
  return convert.addUrl('./src/config/magic.xml', '/usr/local/etc/ImageMagick/');
}).then(function() {
  return convert.addUrl('./src/config/coder.xml',   '/usr/local/etc/ImageMagick/');
}).then(function() {
  return convert.addUrl('./src/config/policy.xml',  '/usr/local/etc/ImageMagick/');
}).then(function() {
  return convert.addUrl('./src/config/english.xml', '/usr/local/etc/ImageMagick/');
}).then(function() {
  return convert.addUrl('./src/config/locale.xml',  '/usr/local/etc/ImageMagick/');
Oh shit
@FlorianMargaine very subtle.. if data is a promise fulfilled will return a new promise that follows that promise
11:17
@FlorianMargaine btw, this is how I'd do it:
cast will return the promise right back
Ale
Ale
Is it really what it supposed to be?
btw if you have synchronous code the transformation is simple
Wait, why all those returns? Why are you not passing the data?
@BenjaminGruenbaum I fucked it up... using the 1st parameter to pass data. I want to rewrite it
oh god I'm stupid
I already wrote parsers and am used to recursion... but there I fucked it up :|
11:18
kindlify = function* (image, done) {
    yield convert.addData(image, "/test.png");
    yield convert.run('-dither', 'FloydSteinberg', '-remap', '/kindle_colors.gif', '/test.png', '/result.png');
    var real_contents = yield convert.getFile('result.png');
    return  "data:image/png;base64," + window.btoa(real_contents);
};
^ @FlorianMargaine this is your code using coroutines. You can do Promise.coroutine to convert it into a promise.
@BenjaminGruenbaum with scripting it's still really nice when stuff runs in parallell
A lot shorter and nicer imo.
if you just use *Sync it will be sequential
@Esailija No built in way to execute a process and wait for it to complete synchronously in Node.
like building bluebird creates like 100 files.. in parallel so that's nice
11:20
Yeah, parallel building is usually a must.
@BenjaminGruenbaum function* ??
@BenjaminGruenbaum uh?
@phenomnomnominal generators :)
Oh yum. I need to look at that stuff!
Welcome to the future, we got good concurrency :)
11:21
ah yeah, child_process has no synchronous API
A lot clearer than that huge list of .then imo
It looks so nice!
yes but error handling sucks in generators because of broken try-catch
Why would it suck? You can try... catch in generators like you do in normal code.
real try catch is really shit, you know that right? It catches all errors
11:22
We just need native async/await that would solve so much
it's like writing catch(Exception e) all the time
@Esailija You want conditional catch like in Firefox?
or whatever is the top level error in C# :P
surely that is an anti pattern in C#
(Worth noting, I do catch(Exception e) most of the time in C#, it's kind of an anti pattern but I use exception handling for well... exceptions. I like the ability to be able to differentiate but usually I don't really need it since exceptions are real edge cases and not likely possible outcomes
Since promises .catch isn't limited by the language github.com/petkaantonov/bluebird#expected-and-unexpected-errors
but the generators try catch is
but yea if you are not comfortable with promises then the generator code is still better
11:24
try {
   myroutine(); // may throw three exceptions
} catch (e if e instanceof TypeError) {
   // statements to handle TypeError exceptions
} catch (e if e instanceof RangeError) {
   // statements to handle RangeError exceptions
} catch (e if e instanceof EvalError) {
   // statements to handle EvalError exceptions
} catch (e) {
   // statements to handle any unspecified exceptions
   logMyErrors(e); // pass exception object to error handler
}
@BenjaminGruenbaum nice, didn't know that
@Esailija ^*2
or ^, it's a link to what you pasted :)
I'm comfy with promises, but I like writing less code and more expressive code and generators let me do that. Just compare the two codes.
@BenjaminGruenbaum's version is an order of magnitude nicer...
11:25
it's really annoying when people compare code without error handling
It does have error handling, can't I Promise.coroutine that and then use a catch on that?
I mean the particular example doesn't show code that is dealing with errors... what would be interesting is the client code that handles them
Would be similar
Anyway, I have a meeting - ttyl
then the try catch and if statements make generator look far worse
sure bye
@Esailija no he means
kindlify = Promise.coroutine(function* (image, done) {
    yield convert.addData(image, "/test.png");
    yield convert.run('-dither', 'FloydSteinberg', '-remap', '/kindle_colors.gif', '/test.png', '/result.png');
    var real_contents = yield convert.getFile('result.png');
    return  "data:image/png;base64," + window.btoa(real_contents);
});
then the client code becomes the same
11:28
no I mean like how the client code using that would be
try {
    var kindlified = yield kindlify(image);
}
catch( e ) {
    if( e instanceof XYZ ) {
        ...
    }
    else {
        throw e;
    }
}
vs
even with Promise.coroutine?
kindlify(image).then(function(){

}).catch(XYZ, function(e){

});
@FlorianMargaine the verbosity comes from broken try-catch.. but with promise .catch method is not limited by that
but... Promise.coroutine fixes that, doesn't it?
the only way that code will be cleaner is if ES6 or ES7 fixes try catch like
try {
    var kindlified = yield kindlify(image);
}
catch( XYZ e ) {
}
@FlorianMargaine in generator you are using normal try-catch
in promises you are using the .catch() method
0
Q: Refactoring a function to return all scores above a certain threshold

AbsI am currently learning JavaScript and wanted to fellow coders to review a function that I had written. I am looking for feedback particularly on: Whether I have followed best practice and JavaScript conventions Any suggestion on doing it better. Things I know I need to implement but don't kn...

11:36
@FlorianMargaine let me know if you don't get it still :D
Mmmmm... What's the short trick to get Math.abs(x) ?
x < 0 ? -x : x I guess
oh you mean codegolf?
and x is integer?
yes
(and less than 32 bits)
probably some bitwise trick, I am blanking out here ^^
I was looking for bitwise, yes, but I don't see it. Maybe there's none...
11:40
I don't think there is any reasonable bitwise operation which always turn an integer into a positive number
why reasonable ?
But it's possible there's none not involving a repetition of x
with reasonable I mean it like.. not foo>>>1&foo|0
which would not really be a shortcut
Yes, I'll go on typing Math.abs...
I wonder why there's no abs function on Number.prototype...
Of course this would led to strange bugs with the minus sign
Ale
Ale
Ok... so, well, it works.
-3..abs() => -3 while (-3).abs() gives 3
Ale
Ale
11:46
I've changed it back to })})})})-version
@dystroy In Ruby, -3.abs gives me 3
@JanDvorak Step 1. port all my code to ruby
3
- 3.abs (note the space) is -3, though
We all saw the space. We're programmers, here, not scripters
ok, sorry
11:51
^^
such whitespace sensitivity is a bit of a wtf to me
method names can have question marks in them, which means sometimes you have to add whitespace before a ternary
@hemma731 Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
fun fact: print(1,2) acts as expected, but print (1,2) is an unexpected comma
@SiZa Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
12:03
hi
@Esailija There is a syntax and that's not it. Also it's not JavaScripty
if anyone could help i will love you forever stackoverflow.com/questions/19788329/…
@FlorianMargaine @Esailija the thing is catching exceptions by type is not behavioral typing and it's generally a bad idea in JS, you can classify exceptions otherwise if you'd like that's a non-issue.
I'd like to see one case where that feature is useful in JS. Monadic maybes are much better and more common in JS.
stop that. If you want to talk about boy/girl parts please don't do it in the JS chatroom unless you're Zirak.
12:06
Siza you want to write those number into textboxes?
when you click the button
?
Some Most people make me fear for the future of this planet.
yes hasan
@HasanAlaca avoid multiple messages when you want to respond to a single thing you can edit.
!!youtube the horrible crowes sugar
Siza ok.. let me try..
!!s/Some Most/Almost all/
@BenjaminGruenbaum Some Almost all people make me fear for the future of this planet. (source)
@BenjaminGruenbaum Almost all people make me fear for the future of this planet. (source)
^ That song will restore your faith in humanity.
@HasanAlaca they are dynamic values pulled from a table though and can vary in row numbers
@Esailija Also, you can do that from Promise.coroutine yourself, you can wrap it in a try/catch and then classify it, can't you?
@phenomnomnominal No sound :(
12:08
SiZa got it, you will connect those variables to dynamic server
@BenjaminGruenbaum hmm, wonder if it's because of where you live.
@OctavianDamiean SUP GANGSTER!
My fever ... again.
Anyone know why i get this error in ember?
Assertion failed: Error while loading route: TypeError: Cannot read property 'map' of undefined
@BenjaminGruenbaum firefox extension is completely irrelevant, you would have this code in node anyway
12:10
@phenomnomnominal No, it's because I'm on a crappy linux box which I did not configure.
There is no more info.
@Esailija We were talking about ES.next no?
Also, can't you catch it on your side and do conditional exceptions there?
typed catches are not ES.next but firefox extension
yes but the code is horrible compared to just .catch(XYZ, function(e){})
try {
    var kindlified = yield kindlify(image);
}
catch( e ) {
    if( e instanceof XYZ ) {
        ...
    }
    else {
        throw e;
    }
}
No, you really almost never want to do .catch(XYZ,function in JS anyway, falling back on the typesystem is almost always a mistake in behavioral typing
(Not to mention the above syntax is just a macro away from the syntax you'd like native try/catch to have)
Hi, I can there anyway I can check if a script file has been uploaded to site using IE 10
12:15
what are you talking about? That is much better than comparing some ghetto string properties
@MuhammadRaja user-agent string? But why do you want to do that?
@Esailija Who said anything about string properties...
As it currently stands, people use exceptions as if they were ghetto string properties themselves... you just throw/catch based on the excpetion type - the exception is meaningless outside of that context in JavaScript. It doesn't contain any useful information other than the stack trace - this is unlike other languages like C#
you can have complex exception types in javascript
@phenomnomnominal I added few links to sharepoint webpart who meant to upload these script files for me, but for some reason I am not sure if it's working
12:17
@DeepuSA No, but this is bad...
    $("#canvas").mousedown(function(e){handleMouseDown(e);});
    $("#canvas").mousemove(function(e){handleMouseMove(e);});
    $("#canvas").mouseup(function(e){handleMouseUp(e);});
    $("#canvas").mouseout(function(e){handleMouseOut(e);});
if you are not doing this it is even worse anti-pattern than catch(Exception e)
at least in typed languages you will not swallow compiler exceptions
This is exactly what I am trying to do
http://sharepointchat.codeplex.com/

@phenomnomnominal
in Js you will swallow those too
Rightfully so mind you
Also, of course it is worse, but this is what it gives us when we pass types instead of predicates.
Look on meta.stackoverflow.com @BenjaminGruenbaum you have a notification because I write...
12:19
I don't want to catch a DBException because it is a DBException or has that on its prototype, I want to catch a DBException because I want to handle something about it - that something is what I should catch based on not the type.
Catching based on type goes against the language typesystem.
What I really want to do is:
@MuhammadRaja, sorry, don't actually care.
@connor.js ok i i know coding standard is not ok
@BenjaminGruenbaum depends... sometimes you want to catch i/o exceptions in a large block of code
what would the predicate function do? inspect some ad hoc string property?
that is really stupid
No, of course not
12:20
it doesn't have to be string, numbers are just as stupid to inspect
Objects sir, objects.
Exception objects
@connor.js resizing is not working after rotation.. its with rectangle corners
try to do the action:
   - if it caused a db error - handle the problems possibly caused in the db
   - if it caused a file i/o error - handle the problems possibly caused in the fs
   - if it caused a type error - let all hell break loose and process.exit and suicide
This is what I want to be able to convey clearly
how can i correct it
@BenjaminGruenbaum sounds like what Java already does
12:22
What I want to be able to do is to catch exceptions based on behavior and not on type.
you want to explicitly handle typeerrors?
no, I don't
I want it to throw right back.
But I don't want to rely on the type system either in a behaviorally types language - I want to rely on what the exception can do not what the exception is
sigh
@BenjaminGruenbaum the type should match the behavior - it's its purpose
@Esailija 'sigh' is a douchy thing to say.
@JanDvorak No, it's the other way around - the behavior defines the type.
→ No repeating please 2 messages moved to Trash can
12:24
var errorHandlers: {
    RangeError: function (e) {},
    ReferenceError: function (e) {}
}
try {
    doShit()
} catch (e) {
    errorHandlers[e.constructor.name](e)
}
benjamin?
@HasanAlaca read the room rules, no reposting messages please, if someone is interested they will help you - it takes time.
@phenomnomnominal Yeah, that also works, the thing is - it's a solution to a problem I don't believe really exists.
Ale
Ale
Okay, it works! 3twv.localtunnel.com
that's because you use Exception e in C# anyway
@BenjaminGruenbaum yeah, I honestly don't tend to do much that actually worries about exceptions
Which is probably bad, but meh
12:26
@Esailija I use Exception e in C# when that's appropriate, not always.
I want only the I/O error in the catch handler, not the reference error or type error or range error and whatever
if those are possible in the catch handler, then I need to check for them
and checking for some ad hoc "behavior" is not any better than checking some string properties like if( e.name === "database" )
C# has a lot more monadic constructs. I don't need to do a Date.parse and then expect an exception, I can do a Date.tryParse which will put the value of the date and return success status and not throw an excpetion. That's smarter
that is totally different class of error what I am talking about
@Esailija That's completely different. but I get what you want better now.
You just want to differentiate file errors from native errors. In that case if you believe it's important - bluebird can do that for couroutines can't it?
Just handle the case for default types
Anyway, I'm off - we will continue this later
later
12:28
:)
!!afk
@BenjaminGruenbaum Stay safe.
hi people of the browser window
I need to set video tag to fill full background of page
I have managed to assign window.innerWidth and height to it so it fill it yet it remains in same aspect it was so it has black spaces on left and right if you get what I mean.
I don't know the video tag enough to know if there is a direct solution but there is an indirect solution I used to manipulate videos : copy the frames to a canvas during the animation (and hide the video element)
that sounds like 100% CPU :p
especially on FS
@jAndy no
you can draw every 20 ms (and there might be solutions more efficient, I never took the time to search)
12:35
I do not see why they did not set scale flag
can i ask something
?
I don't say it's the best solution, I say it's a solution
why is this fiddle not working? jsfiddle.net/xgQQu/6
@HasanAlaca Read the rules of the room
@HasanAlaca
> XMLHttpRequest cannot load johnmacfarlane.net/pandoc/demo/howto.xml. Origin fiddle.jshell.net is not allowed by Access-Control-Allow-Origin.
destroy: where is this "console"?
12:37
Why don't you open the console instead of asking ?
@dystroy can you point me on how to achieve this?
@DušanRadojević Let's say you have a canvas context c you got using getContext, then you can do
is there any XML example where jsfiddle displays data ?
			c.drawImage(videoElement, destX, destY, destWidth, destHeight);
// but there's probably a direct solution...
@sabya Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
12:39
get( external.xml) ... each .. etc.. on jsfiddle ?.. anyone knows*
okzzzzzzzz @CapricaSix
everyone sleeping?
code golf again, for those who might find it fun : create in one not too long statement an array of N empty arrays
[ [], [], ...,[] ]
sleep is healthy n refreshing at times
12:50
eval("["+Array(N).join("[],")+"[]]")
@JanDvorak Not bad
(too ugly for me, but I didn't ask for pretyness)
Array(10).join('x').split('x').map(x => []);
@Hasan. I too got same experience.. I think they are busy with some important works. i am alos waiting to ask my question when they are free
@jAndy common JS...
I hate that you have to join/split there too
12:54
@dystroy that is javascript
!!> Array(10).join('x').split('x').map(x => []);
@jAndy [[],[],[],[],[],[],[],[],[],[]]
see!
Joe
Joe
Hi guys. are any of you using a client-side MVC framework. If yes, what backend are you using?
@jAndy You don't really have to join and split :
Array.apply(0,Array(10)).map(function(){ return []})
!!> Array.apply(0,Array(10)).map(x => [])
12:55
@dystroy [[],[],[],[],[],[],[],[],[],[]]
@dystroy I have that question
@BenjaminGruenbaum Were you bitten!? Strip! Prove you weren't bitten.
only more convoluted
@Esailija I'm back, so what really bothers you is that if you suppress/handle I/O errors you don't get nice treatment for stuff like RangeError and TypeError?
@Esailija (Read as: You can't handle errors and exceptions differently although they are inherently different)
yes I don't want to silently swallow unexpected errors like typeerrors
!!> try {a.b.c.d();} catch(e){}
@Esailija "undefined"
13:04
@dystroy I know, I was basically saying that its a pitty you can't just Array(10).map things
@jAndy I agree
It looks like internal optimization leaking in the dev space
But to be honest, it rarely really matters
the intent was to try-catch I/O exception at a.b.c.d() but now we don't know at all if such method even existed
without inspecting the error of course
the catch-all is utter horror
and unstable nodes have a ton of problems like 2 problems with uglifyjs alone last time I checked
so I would definitely not make a public module that depends on generators or production website using them yet
@FlorianMargaine Thanks for the link
they look like they're contradicting each other though, no real answer
13:13
Dave Cheiney's remark is interesting but this looks like a very limited usecase
and Chris just says that basically it's not true
13:27
well, it's not true if you accept one supplementary line (which I do).
I think I know Dave Cheney...
@FlorianMargaine Dave Cheney and Chris Dollin are everywhere Go is involved
@DeepuSA You can solve, keep trying.
13:42
@DeepuSA Stop asking the same exact question
asking in here isn't trying with my suggestion
@rlemon i tried but still not working.
you have a rectangle, you need to find the corners, you rotate it, but ooo snap! you don't take the angle into consideration when checking the corners...
that should be enough to go on
@Conaire Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
13:52
why can i specify an array of object with "gaps"? e.g, myArray[0] = "foo"; myArray[2] = "bar";

is there anything that i should be aware of when i do so?
Joe
Joe
@Sprottenwels you need to include a space between each array output using a loop
@Esailija That makes sense.
@Sprottenwels Yes, when you do that the length of the array would be 3 not 2
A catch(e) is insufficient in that regard.
So you would have to manually set the length
13:55
@Esailija Yeah, I was suggesting it for syntax not for actual production use.
thanks both of you. i assume that myArray[1] would return undefined in that case?
Joe
Joe
its a bad idea to put ''gaps'' in the array of objects itself
@Sprottenwels yeah
Why do you want to do that?
sure thing. the use-case behind this is that i have to extend one object with another, but the second one will not hold values for every object in the array
*in the first
@Sprottenwels so you have an array of 10 objects and you want to create 5 out of that by extending them yes?
13:58
@Esailija what about bringing the topic on es-discuss?
for predicated catch clauses?
i have an array of 10 objects. i want to override 5 of its values by extending it with another array. to do so, i create the second array like the example above. that worked pretty well, and i wondered why :o

« first day (1116 days earlier)      last day (4057 days later) »