« first day (62 days earlier)      last day (4869 days later) » 

Kev
12:02 AM
hey guys....what does this mean: $(function () { // code }); is this a jQuery specific thing?
 
Yeah it's jquery
it runs the function you pass in after the dom has loaded
 
Kev
ah ha
 
which, iirc, is before the window.load event, but after all the nodes are ready for you to play around with
 
Kev
is it a synonym for $(document).ready(function () { ...
 
yep i believe so
 
Kev
12:06 AM
ah found it on the docs now I know what to look for :)
thanks
 
I just found out about the stackoverflow chat, this blows my mind :D
 
it is quite hidden
unfortunately so actually... it means there aren't many people in here
 
$('#selector').find('a') or $('#selector a') ... which is better? Do those do different things or the same thing?
@david howso? It's at the top of every bloody SO page
 
in fairly small letters, and not advertised as being awesome, and locked until you earn enough rep
Anyway, triangle ordering, how do i do it? ><
 
12:22 AM
20 rep (two good questions or answers, or getting accepted once) and everything up there is in small letters, and the whole fracking site is awesome, that's like Superman walking around going "see this forearm, it's awesome" ... I'm sorry, he's Superman, I think we realize he's full of awesome. I've yet to come across something on the site that's not [simple, fast, works]
define: triangle ordering
in that jsfiddle you would find the distance from the POV to the relevant points of each triangle, and find which point was closest overall
that would give you which one was in front.
as for POV overlap, you need the angle from "true north" and the distance to the triangle
 
this link: jsfiddle.net/TkZWq some of the triangles are being drawn infront of things they should be behind
 
but remember that "in front of" is subjective
 
Kev
@drachenstern i think $('#selector').find('a') & $('#selector a') are functionally equivalent. .find() is useful of you already have a pre-selected object
 
that animation needs a pause button. I can't tell if they're truly in front or if its coloration
@Kev I think they are functionally equivalent too, but not sure. I'm gonna get @YiJiang or someone to run a test on it ...
 
Kev
@drachenstern so many ways to skin a cat in jQuery
 
12:27 AM
in one direction it's fine, in the other direction they're drawn in the wrong order
 
@Kev yep
@david do you have a non-min'd version of the script?
 
barely, but it is
has this code been compiled?
 
yeah i ran it through the closure compiler to try get a bit of speed out of it
triangle sorting seems to be a slightly hard problem... i might just have to go with an approximation
 
@david do you have a non-compiled version of the code by chance? I'm working my way through the closured one and it would be easier to read if I had an English/Documented version
Not that I can't read closure, but I'm looking for something specific, and that would be easier
 
12:38 AM
eeh, it's kinda gross, so i'd rather not... what are you looking for?
 
I'm not entirely sure. But your answer kind of speaks for itself doesn't it?
"I think my code is terrible and needs to be refactored badly so I don't want to share it" ...
 
hello!
any jquery guys around?
 
is not much of a jquery guy
 
heh, I figured I would ask you guys here first before typing up the question, i've got a menu on this page hub.mhn.co/Store/Product that suddenly stopped working and I can't figure why
 
are you using Firebug or something similar?
 
12:48 AM
yeah
it seems to be firing the click event twice
opening and then closing the intended menu
hell, maybe its my mouse double clicking on me, i'm hoping its a quick fix
 
You realise you're running that $(document).ready() code every time you have a new list item right?
it's possible each click is firing off... 10 events
because you have 10 little [+] things
Did the problem start after you added a new menu item?
 
yep
that makes sense
 
you really only want to run it once... you can put it in the <head> or something, because the ready handler will make sure it only runs once the list is loaded
Another problem with chat is you don't get rep for answering questions in here >.>
 
you just get that warm feeling
 
i'll type it up as a question if you'd like
that way you get the rep for answering
i though that $(document).ready() was where i was supposed to bind events like that
 
12:56 AM
it is! but you only need to do it once...
you're using ".showHide" as your selector, so each time it's getting every single one, and binding the event to every single one
so if you have X list items, you're running the code X times, and each list item is getting X event handlers attached...
 
this is news to me, i've been using this same way for a couple of months now and this is the first time i've encountered this issue. Is it because the .ready() isn't in the head? or maybe cause there are multiple?
 
because there are multiple ones. They are all running
try adding an alert to the click event, see if it alerts 10 times per click
because i might be wrong :S
 
alright, ill get back to ya
thats totally whats happening, 13 times!!
sigh but moving the code into the <head> didn't solve the issue
 
:(
it's still doign it 13 times? o_O
 
20, miscounted
so without the alerts, its appearing to work again
i'm going to type up a question
 
1:07 AM
nah dw
it's not updated on the link you sent?
 
no, sorry - ill upload it
 
you're also getting a 404 error for /hub/Content/custom/custom.css
 
oh wow, i uploaded it and its working
i must have tested a cached page
well, thanks for your assistance - its working now
fixed the 404, didnt notice that before, unnecessary reference
 
 
3 hours later…
4:31 AM
Hey, does anyone here know Google Closure?
 
@williamparry are you talking about Google Closure Compiler?
 
no, the library
I bought the ebook and am reading through the XhrIO object
I am looking at timed scheduling of it
 
no, don't know that
 
okay
no probs :)
 
gah! in my timezone, it's 5:39. And a few minutes ago, my little brother woke me up to let me interpret the current list of school cancellation. Well, at least it does get canceled in our city :)
 
 
2 hours later…
6:30 AM
Why would '(' + (parseInt(n, 10) + parseInt(m, 10)) + ')' , where n = '4' and m='0', cause the two to be concatenated, not added together?
ie. Shouldn't it produce (4) not (40)?
 
@YiJiang I get (4) in Firefox, where are you trying that at?
 
var n='4';var m='0'; console.log('(' + (parseInt(n, 10) + parseInt(m, 10)) + ')')
(4)
@YiJiang are you sure that that's the actual code?
 
This is the actual code:
return t + ' (' + (parseInt(f.offensive, 10) + parseInt(f.spam, 10)) + ')';
 
Oh, so this chat room is alive again. :rotates tabs to put the other 3 SE chat rooms behind it:
 
Console logging the types of both of those tell me they're numbers
 
6:42 AM
console.log('blabla' + ' (' + (parseInt("123", 10) + parseInt("5", 10)) + ')')
blabla (128)
@YiJiang sure?
 
the 40 only happens if you're missing the parenthesis which wrap the two parseInt methods
since then it's a string concatenation because of '(' and ')'
 
I don't get it. It should work
 
@YiJiang is your code available somewhere online for testing?
Hello @Ivo
 
morning all
 
@thejh I can't repro it anywhere else
The context of the code is something like this:
 
6:49 AM
still 2 ;_;
 
$('.post-tag').text(function(i, t){
    var n = '4', m = '0';

    console.log(t + ' (' + (parseInt(n, 10) + parseInt(m, 10)) + ')');
    return t + ' (' + (parseInt(n, 10) + parseInt(m, 10)) + ')';
});
 
@YiJiang: what happens if you put this into your url bar
@YiJiang: javascript:alert('(' + (parseInt("4", 10) + parseInt("0", 10)) + ')');
 
what is t?
 
@jAndy Always worth a shot, of course, but no, it says (4)
 
'' + 4 + 2 = '42'
 
6:51 AM
@IvoWetzel there are brackets
@IvoWetzel '' + ( 4 + 2 ) = '6'
 
ahh hardly awake, anyways something fishy is going on then
 
pulling out hair
 
@YiJiang You're 100% sure of the input?
 
Hum, what's the problem ?
 
f = { offensive="4", spam="0"}
@TimStone Quite
 
7:00 AM
@YiJiang: what is returning here: t + ' (' + ((+n) + (+m)) + ')';
looks wierdo tho :p
 
hum normally if you want to make sure something is converted to a number doing *1 does the job
' (' + (n*1 + m*1) + ')'
 
@HoLyVieR isn't -- cooler?
 
@jAndy Still getting flag (40)
 
You could alternatively also do :
 
This is... amazing... god I don't think I'll have any hair left after this
 
7:02 AM
' (' + (n*(!![] + ![]) + m*(!![] + ![])) + ')'
@YiJiang have you tried with the *1 trick ?
 
@YiJiang Ah, OK. I asked because one time I was printing out an object to the console, and Firebug always shows you the current state of the object (so I went crazy wondering why the object was correct when I printed it out, but the next line of code thought it wasn't, heh)...in your case, I think it's just cursed. ;)
 
@HoLyVieR: *1 does the same internal cast as + exept its one more character
 
@jAndy I see
 
heh
 
I saw that on DailyWTF a few days ago
 
7:14 AM
@thejh Classical, yes.
 
I learned something really nice about Javascript, it's quite mind blowing
You can actually build JS script without using any alpha-numeric character
And this includes doing stuff, like alert.
 
@HoLyVieR uh... what?
 
that alerts "js is cool"
 
gah, that even works
 
lots of stuff like that around
 
7:21 AM
useful for a JS maximizer... uh wait
 
I know, I saw a video/conference about programming javascript without using letter or number. It's really nicely explain how you get to build that.
 
@HoLyVieR: sounds really useful
 
The main purpose of that was to dodge filter
 
why is "(1+{})[3];" "b"?
 
1+{} = "Number"
(1+{})[3] = "b"
 
7:24 AM
Uh, am I missing something here?
1+{} > "1[object Object]"
 
yep
 
ya >.>
 
what is "1[object Object]"?
 
just a string
 
uh 1+ {}.toString()?
 
7:26 AM
@IvoWetzel the point is that you must not use letter or number
That's the challenge
 
I know that
 
((_$={})+'')[!![]+!![]] is an alternative I found to get the "b"
 
@IvoWetzel ah, ok
 
8:19 AM
This is the script which I was working with just now. Any 10k'er want to help me debug that curious problem?
The line is line 85. Removing the + in front of the inner set of brackets causes the addition sign to be recognized as concatenation instead between the two inner numbers
Browser is Firefox 3.6.13. See this happening on posts which have flags on them
 
@YiJiang without testing it: offensive: f.eq(0).text() is a string that gets stored as JSON, right? Which means that f.offensive will be a string later, right?
 
@thejh Definitely, but whatever it is, it'll always be a string, since type information doesn't get stored in JSON
 
@YiJiang {"a":1} and {"a":"1"} are different. There is type information
just limited, but there is
 
@thejh Okay, but it still shouldn't make a difference. Here's a snippet of the JSON: "4466544":{"offensive":"5","spam":"0"}
 
@YiJiang what happens when you do`offensive: --f.eq(0).text()` or something like that? (the same for spam)
 
8:32 AM
You mean storing it as numbers instead of strings?
 
@YiJiang yes
 
Using that with return (t + ' (' + (f.offensive + f.spam) + ')'); get's me the same results - flag (40)
Which, frankly, is amazing.
 
what's typeof f.offensive then?
 
number, for both
 
gah!
@YiJiang and what does (f.offensive + f.spam) say?
 
8:37 AM
@thejh 4, typeof - number
Well actually the number of flags has grown to 5 now, but that doesn't matter
 
@YiJiang crazy idea: (t + ' (' + ((f.offensive + f.spam)) + ')') maybe?
 
@thejh Tried that, didn't work. You saw the solution, right? Type coercing the entire thing (by adding a + to the outermost bracket) works
 
@YiJiang yes, I saw it. but I want to know why it is that way
 
@thejh I'm asking a question now. I'm also want to know
 
@YiJiang Hah, I can reproduce it too..
 
8:48 AM
@TimStone Wait, how did you get 10k reps?
 
@YiJiang Magic!
But no, I just mocked up the flags.add() step
@YiJiang Apparently it only happens if you append a string after the parenthetical.
Oh, I take that back..kinda.
The hell Firefox.
console.log(f.offensive + f.spam); // 50
console.log('' + (+f.offensive + +f.spam)); // 5, but returning this yields 50 somehow
console.log('' + (+f.offensive + +f.spam) + ''); // 50
 
@TimStone How did you modify the add function to repro this bug? I need to add it to the question I'm writing
 
@YiJiang Oh, I just took out your AJAX request and put in flags.add(4468653, { offensive: "5", spam: "0" }); (where the number is some random question I clicked)
 
morning all
 
9:03 AM
'Ello @AndyE
 
@TimStone I don't have Chrome here right now. Can you install the script on Chrome and see if the problem can be repro'd?
 
Sure thing.
@YiJiang [status-norepro] in Chrome, looks like a Firefox bug.
 
@TimStone Oh wow... I discovered a bug in the erm... Firefox JavaScript engine?
 
Apparently. :P
 
Still doesn't seem right
 
9:11 AM
console.log('' + (c = +f.offensive + +f.spam) + ''); // 5
Heh
Ah, and that one actually works when you return it. GG Firefox. shakes head
 
0
Q: Problem with type coercion and string concatenation in JavaScript in Greasemoneky script on Firefox

Yi JiangI'm creating a GreaseMonkey script to improve the user interface of the 10k tools Stack Overflow uses. I have encountered an unreproducible and frankly bizarre problem that has confounded me and the others in the JavaScript room on SO Chat. We have yet to find the cause after several lengthy debu...

Absolutely ridiculously long post describing what really should be a very simple problem
 
I don't see any way this isn't a Firefox bug. I'm not really sure how this could have been overlooked, but..
return t + ('(' + ((+f.offensive + +f.spam) + ')')); // 5
return t + '(' + ((+f.offensive + +f.spam) + ')'); // 50
return t + ('(' + (+f.offensive + +f.spam)) + ')'; // 5
In the words of @drachenstern, lolzwut?
 
9:29 AM
Have you tried using Number() instead of unary +?
 
@AndyE Well, previously I've tried parseInt so...
 
He was originally using parseInt(f.offensive, 10), but not sure if we ever tried that.
 
hmm
try breaking it down into separate expressions
 
And with @thejh's suggestion above I've actually moved the type conversion up to the add function, without resulting in any change
 
var num = +f.offensive + +f.spam;
return t + '(' + num + ')'; // ??
 
9:31 AM
@AndyE Yeah, that works (you get 5)
 
It looks like a GM bug then.
 
@AndyE And yet it shouldn't be - the script is using script injection, so these codes should be running in the client machine as any other piece of code would
 
@YiJiang OH!
Son of a bi**!
 
hmm...
 
When you .toString() the function it removes the damn parentheses
return t + ("z" + + f.offensive + + f.spam + "z");
 
9:35 AM
@TimStone I.. you... what?
 
lol
 
To inject the script into the page, .toString() is called on the function you defined.
 
@TimStone Yes, I know that
 
Apparently in that process, the parentheses are removed.
 
Then it's an issue with Function.prototype.toString()
 
9:35 AM
@TimStone Huh?
 
@YiJiang What's actually injected to the page doesn't have those parentheses.
 
@TimStone How is Firefox doing that?
 
Hell if I know, but at least we know why we get the wrong result. Just, not the why for the why. :P
 
@TimStone Actually, that's not quite right
This is what I see when I pop open Firebug:
Meh, stupid mistake. Go ahead and post that as an answer
 
@YiJiang Oh no, you're right. They aren't removed.
They're just...relocated.
 
9:40 AM
can't repro in Firefox 4's console.
 
return t + ("(" + + f.offensive + + f.spam + ")"); should be return t + "(" + ( + f.offensive + + f.spam) + ")";
 
@TimStone Without all the space in front of the variables
 
Right, right. :P
 
Let me see if this can be found on teh intertubes
There we go: bugzilla.mozilla.org/show_bug.cgi?id=530537 - Function.prototype.toString strips out parenthesis when displaying function
 
That was fixed a while ago, and it's slightly different anyway no?
 
9:45 AM
@TimStone I'm not sure. Weird...
 
it appears to share similar characteristics (string before and after). Maybe the fix didn't fix all cases.
 
Yeah, could be. Hrm..
 
function hello(){
    return (t + ' (' + +(+f.offensive + +f.spam) + ')');
}

console.log(hello.toString());
Output:
function hello() { return t + (" (" + + (+ f.offensive + + f.spam) + ")"); }
 
Yep
 
@YiJiang that's not a bug ;)
 
9:51 AM
@NickCraver It's not? :P Surely relocating parentheses is...heh
 
@NickCraver What do you mean?
 
function hello() { return 1+2; }, want to guess what that renders?
.toString() isn't specified behavior, it's implementation dependent...so really they can do whatever the hell they want :)
 
@NickCraver argh
 
IIRC there's a .toSource() or something for Firefox that doesn't screw with it
 
@NickCraver O_O
 
9:52 AM
@NickCraver This also has the same problem (in this case)
 
@NickCraver actually that's not strictly true - they do have to return a string representation of the function, but the string returned can be implementation dependant
 
@AndyE yeah, but the issue we're discussing is the function, yes? It's logically equivalent?
 
It's not. :P
 
the same as function hello() { return 1+2; } is logically equivalent to the `function hello() { return 3; }`it returns
 
back..
 
9:54 AM
@NickCraver: yeah, which is the implementation dependant part
other browsers won't mess with the function's source code.
My guess is that Firefox is changing the source to what it thinks is the equivalent and it's actually not in the case of the GM script code
 
var t = "bob", f = { offensive: 1, spam: 2 };
function hello() {return t + (" (" + + (+ f.offensive + + f.spam) + ")");}
hello();
did you test it? ;)
 
I'm confused what you're driving at @Nick :P
 
maybe I'm not following...do you have a data scenario where the .toString() version produces a different result?
 
Yeah
 
@NickCraver: it looks like it will work fine, I haven't tested it. But they're having specific problems with this function because it is converted to a string and then injected via script - it doesn't seem like it could be any other issue.
 

« first day (62 days earlier)      last day (4869 days later) »