Programming Regs Lounge

  • 343,079 Views
  • 17,770 Replies
New Topic Respond to this Topic
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Programming Regs Lounge Jul. 23rd, 2012 @ 02:32 PM Reply

That happens because of how JavaScript treats empty arrays (which is, a lot of the, treated as a string).
So that first piece of code:

(![]+[])

Creates the string "false".
This is because when you do this:

![]

You get a boolean false, because an array is not considered false, so therefore when used with the ! (not) operator returns false. Inversely if you were to do this:

!![]

You would get a boolean true, but that's not really important.
In order to convert the boolean to a string the boolean is incremented by an array; that is the same as incrementing by an empty string. The following two lines do the same thing:

![]+[]; // "false"
![]+""; // "false"

So now you have the string "false" and need to get the "f" out of it, which is at index position 0.
Before explaining that, take the following for example:

+5; // 5
-5; // -5
-+5; // -5
+-+5; // -5
-+-5; // 5

The positive/negative symbols do pretty much what you'd expect:
- Positive plus Positive equals Positive
- Positive plus Negative equals Negative
- Negative plus Negative equals Positive

Or, in other words:
- No negative sign, or equal number of negative signs, equals Positive
- Otherwise equals Negative

What happens when you use these with an empty array?

+[]; // 0
-[]; // -0

Yes, negative zero really is a thing.

So using that, you can easily get the "f" from a string of "false":

var falseStr = ![]+[]; // "false"
var fStr = falseStr[+[]]; // "f"

// One line:
(![]+[])[+[]];

Now knowing how to do goofy shit like that, you can break that code into smaller chunks:

// Generates "f":
(![]+[])[+[]];

// Generates "a":
(![]+[])[+!+[]];

// Generates "i":
([![]]+[][[]])[+!+[]+[+[]]];

// Generates "l":
(![]+[])[!+[]+!+[]];

And it stops becoming an incomprehensible mess.
Make sense now? :)

P.S.
I don't consider this a "fail" at all; just a neat trick produced by abusing the hell out of JavaScript.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 23rd, 2012 @ 04:55 PM Reply

At 7/23/12 02:32 PM, Diki wrote: Make sense now? :)

P.S.
I don't consider this a "fail" at all; just a neat trick produced by abusing the hell out of JavaScript.

bWF5IGJlIHBpY3R1cmUgdGFsayBpbnN0ZWFkIG9mIG1lLg==

Programming Regs Lounge

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Programming Regs Lounge Jul. 24th, 2012 @ 11:23 AM Reply

Ignoring the stupid memes this video is a pretty interesting talk on some goofy things JavaScript does (as well as Ruby).
And this post explains why JavaScript does the things that are outlined in the video.

citricsquid
citricsquid
  • Member since: Jun. 25, 2005
  • Offline.
Forum Stats
Supporter
Level 23
Blank Slate
Response to Programming Regs Lounge Jul. 25th, 2012 @ 05:08 AM Reply

http://phpjs.hertzen.com/

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 25th, 2012 @ 12:50 PM Reply

At 7/25/12 05:08 AM, citricsquid wrote: http://phpjs.hertzen.com/

good for some fun I gues, as the docs say it's not recommended for production env

doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Programming Regs Lounge Jul. 25th, 2012 @ 07:01 PM Reply

What's up guys?


At least not a muffin.

BBS Signature
NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 27th, 2012 @ 11:48 PM Reply

At 7/25/12 07:01 PM, doodle-bread14 wrote: What's up guys?

Posted 2 days ago. Embarrassing.
OT: Been making this site from like 9pm to now (almost 6am). Don't know how much longer can I last

doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 08:35 AM Reply

At 7/27/12 11:48 PM, NinoGrounds wrote: Posted 2 days ago. Embarrassing.
OT: Been making this site from like 9pm to now (almost 6am). Don't know how much longer can I last

Having problems, huh? Me too.


At least not a muffin.

BBS Signature
NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 10:20 AM Reply

At 7/28/12 08:35 AM, doodle-bread14 wrote: Having problems, huh? Me too.

Not really, just a lot of content.

doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 10:44 AM Reply

At 7/28/12 10:20 AM, NinoGrounds wrote: Not really, just a lot of content.

Gzzbshgmdfck... And how's the website going?


At least not a muffin.

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 03:40 PM Reply

Last night I spent over 6 hours refactoring my SimpleJS JavaScript framework.
The new source code is here and I think it's a hell of an improvement.
This is the old source code for comparison.

That took a while, but it was totally worth it. :)

doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 05:41 PM Reply

At 7/28/12 03:40 PM, Diki wrote: Last night I spent over 6 hours refactoring my SimpleJS JavaScript framework.
The new source code is here and I think it's a hell of an improvement.
This is the old source code for comparison.

That took a while, but it was totally worth it. :)

Wow... You certainly have talent. I don't know how a man can have nerves to make over 1000 lines of code. Congrats!
And for what did you make that framework? For a school project or something?


At least not a muffin.

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 06:44 PM Reply

At 7/28/12 05:41 PM, doodle-bread14 wrote: Wow... You certainly have talent. I don't know how a man can have nerves to make over 1000 lines of code. Congrats!
And for what did you make that framework? For a school project or something?

1,000 lines really isn't that much. A lot of that is also the comments; there's probably only about 600 lines of actual code.
And nope it's not for school; just something I made because I don't like how complicated vanilla JavaScript is, so I wrote a framework to simplify it without adding any custom wrappers like jQuery and MooTools do.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 28th, 2012 @ 09:36 PM Reply

At 7/28/12 10:44 AM, doodle-bread14 wrote:
At 7/28/12 10:20 AM, NinoGrounds wrote: Not really, just a lot of content.
Gzzbshgmdfck... And how's the website going?

Pretty good. Still have a lot to do though.

At 7/28/12 06:44 PM, Diki wrote: just something I made because I don't like how complicated vanilla JavaScript is, so I wrote a framework to simplify it without adding any custom wrappers like jQuery and MooTools do.

That's the spirit.

Going to make a little thingy now, I think I should be finished in 2 hours. Then I'll post it here.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 03:35 AM Reply

At 7/28/12 09:36 PM, NinoGrounds wrote: Going to make a little thingy now, I think I should be finished in 2 hours. Then I'll post it here.

2 hours my ass. I just spent 5 and half hours and I'm still on like 1/2. to be contiuned

kiwi-kiwi
kiwi-kiwi
  • Member since: Mar. 6, 2009
  • Offline.
Forum Stats
Member
Level 09
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 05:34 AM Reply

At 7/29/12 03:35 AM, NinoGrounds wrote:
At 7/28/12 09:36 PM, NinoGrounds wrote: Going to make a little thingy now, I think I should be finished in 2 hours. Then I'll post it here.

That white/blue combination is very heavy on the eyes while reading.
Try this

doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 07:37 AM Reply

At 7/28/12 06:44 PM, Diki wrote: 1,000 lines really isn't that much. A lot of that is also the comments; there's probably only about 600 lines of actual code.
And nope it's not for school; just something I made because I don't like how complicated vanilla JavaScript is, so I wrote a framework to simplify it without adding any custom wrappers like jQuery and MooTools do.

I couldn't do better. And why does the code look similar to AS3?

To Ninogrounds:
kiwi-kiwi is right. The blue/white combination really stings the eyes. You could try the dark blue/light blue combination.


At least not a muffin.

BBS Signature
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 12:06 PM Reply

At 7/29/12 07:37 AM, doodle-bread14 wrote: I couldn't do better. And why does the code look similar to AS3?

Dialects of EMCAScript.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 02:29 PM Reply

At 7/29/12 07:37 AM, doodle-bread14 wrote: kiwi-kiwi is right. The blue/white combination really stings the eyes. You could try the dark blue/light blue combination.
At 7/29/12 05:34 AM, kiwi-kiwi wrote: That white/blue combination is very heavy on the eyes while reading.
Try this

tell me about it. but that's what the employer wanted, because that are "their colors"

doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 02:58 PM Reply

At 7/29/12 02:29 PM, NinoGrounds wrote: tell me about it. but that's what the employer wanted, because that are "their colors"

Very well then.


At least not a muffin.

BBS Signature
NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Jessii
Jessii
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 36
Movie Buff
Response to Programming Regs Lounge Jul. 29th, 2012 @ 06:30 PM Reply

At 7/29/12 05:41 PM, NinoGrounds wrote: thank me later

Wow! Just wow!

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 07:22 PM Reply

I'm guessing he bought it from this chick whom I found out about a few weeks ago.
Some guys are pretty damn desperate to have a girl touch them.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 29th, 2012 @ 07:47 PM Reply

At 7/29/12 06:30 PM, Jessii wrote:
At 7/29/12 05:41 PM, NinoGrounds wrote: thank me later
Wow! Just wow!

I know, I know

At 7/29/12 07:22 PM, Diki wrote: I'm guessing he bought it from this chick whom I found out about a few weeks ago.
Some guys are pretty damn desperate to have a girl touch them.

I strongly suggest that we LOIC that site

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to Programming Regs Lounge Jul. 29th, 2012 @ 08:10 PM Reply

At 7/29/12 07:22 PM, Diki wrote: I'm guessing he bought it from this chick whom I found out about a few weeks ago.

Reminds me of this.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 30th, 2012 @ 05:40 PM Reply

At 7/29/12 08:10 PM, liljim wrote:
At 7/29/12 07:22 PM, Diki wrote: I'm guessing he bought it from this chick whom I found out about a few weeks ago.
Reminds me of this.

Yeah he's an idiot. But aside from that, I just noticed that YT video are now embed. Nice work.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 30th, 2012 @ 09:33 PM Reply

IE is a fucking moron, even if its newest version (10, it comes with win8).
Any suggestions on how to fix this site ? It looks fine in Chrome and FF
Linky to hi res: http://img687.imageshack.us/img687/1002/capturelqr.png

Programming Regs Lounge

citricsquid
citricsquid
  • Member since: Jun. 25, 2005
  • Offline.
Forum Stats
Supporter
Level 23
Blank Slate
Response to Programming Regs Lounge Jul. 30th, 2012 @ 10:15 PM Reply

At 7/30/12 09:33 PM, NinoGrounds wrote: IE is a fucking moron, even if its newest version (10, it comes with win8).
Any suggestions on how to fix this site ? It looks fine in Chrome and FF
Linky to hi res: http://img687.imageshack.us/img687/1002/capturelqr.png

http://validator.w3.org/check?uri=http%3A%2F%2Flabs.recgr.co m%2Fterme2%2Fhr%2FGalerija&charset=%28detect+automatically%2 9&doctype=Inline&group=0

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Programming Regs Lounge Jul. 30th, 2012 @ 10:54 PM Reply

At 7/29/12 08:10 PM, liljim wrote:
At 7/29/12 07:22 PM, Diki wrote: I'm guessing he bought it from this chick whom I found out about a few weeks ago.
Reminds me of this.

Ahah. Definitely some weird folks out there.
And for the record, I don't know what show that is, but I saw Ricky Gervais, and Ricky Gervais is awesome.

At 7/30/12 09:33 PM, NinoGrounds wrote: IE is a fucking moron, even if its newest version (10, it comes with win8).
Any suggestions on how to fix this site ? It looks fine in Chrome and FF
Linky to hi res: http://img687.imageshack.us/img687/1002/capturelqr.png

As someone whose job it is to make websites I completely agree that IE is an absolute pile of shit, but unfortunately if you want to make websites or a living you have to learn how IE works.
I tried loading that site in IE9 and it certainly seems to be loading incorrectly; I do not know why though. Best advice I can give for writing IE compliant HTML is to treat your page like a series of boxes, and each box does not contain elements that extend its boundaries. IE doesn't like that.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Programming Regs Lounge Jul. 31st, 2012 @ 01:42 AM Reply

At 7/30/12 10:54 PM, Diki wrote: and each box does not contain elements that extend its boundaries. IE doesn't like that.

thanks