philihp All American 8349 Posts user info edit post |
Anyone have any references to really clever/sneaky/innovative code?
I randomly stumbled upon http://tokyoenvious.xrea.jp/b/2005/12/ -- this code is really cool. I can't read Japanese, but this guy is a madman.
(function() { unsafeWindow.HTMLCollection.prototype.forEach = function(callback, thisObject) { var thisObject = thisObject || this; for (var i = 0, len = this.length; i < len; ++i) callback.call(this, this[i], i, this); };
document.getElementsByTagName('form').forEach(function(form) { form.getElementsByTagName('textarea').forEach(function(textarea) { textarea.addEventListener( 'keydown', function(event) { if (event.ctrlKey && event.keyCode == 13) form.submit(); }, true ); }); }) })();
[Edited on May 5, 2006 at 10:14 PM. Reason : [code]]5/5/2006 10:13:46 PM |
State409c Suspended 19558 Posts user info edit post |
What does it do? I don't know callback functions (only heard the term) and I'm too lazy to look up keyCode 13 (enter?). 5/5/2006 10:29:31 PM |
Lowjack All American 10491 Posts user info edit post |
It submits any form if you hit control+enter form any text area. That part was in engrish.
[Edited on May 5, 2006 at 10:45 PM. Reason : dsf] 5/5/2006 10:42:50 PM |
philihp All American 8349 Posts user info edit post |
yeah, i usually stay far away from the prototype property when doing javascript... it lets you dynamically at runtime add or another method to a class OR a specific object (and the object's method overrides its class's). really crazy shit but really intuitive if you've ever tried to write an OO environment in a procedural top-down environment...
basically he added the "forEach" method to the HTMLCollection class, which would make the class iterate through its members referencing back to callback...
and then he had each form go through all of its textareas and add an event listener for the keydown event to go back up to the form and submit if the user pressed enter while control was depressed.
but... just look at it!! *drool* 5/5/2006 10:48:31 PM |
Perlith All American 7620 Posts user info edit post |
I've got some Java code which will convert HTML to JPG. Haven't tested it extensively, but know it works. Will post if anybody is interested. 5/6/2006 9:25:34 AM |
qntmfred retired 40819 Posts user info edit post |
here's an innovative way to interface a db
void execSqlCommand(int ActionFlag, char * sqlFileName, char * outputFileName) { int response=0; long x=0, z=0; char * systemCall = malloc(sizeof(char) * 1024);
switch (ActionFlag) { case 0: //execute sql strcpy (systemCall,"isql -U sa -P -S 192.168.3.118 -d ORGDB -n"); strcat (systemCall," -i"); strcat (systemCall,sqlFileName); strcat (systemCall," -o"); strcat (systemCall,outputFileName); response = system (systemCall); break; case 1: //delete command file strcpy (systemCall,"DEL "); strcat (systemCall,sqlFileName); response = system (systemCall); break; case 2: //delete both command and output strcpy (systemCall,"DEL "); strcat (systemCall,sqlFileName); response = system (systemCall);
strcpy (systemCall,"DEL "); strcat (systemCall,outputFileName); response += system (systemCall); break; } // wait for database to return data. z = 0; for (x=0;x< 999999900;x++) {z++;} z = 0; for (x=0;x< 999999900;x++) {z++;}
return;
}
[Edited on May 6, 2006 at 10:57 AM. Reason : courtesy thedailywtf]5/6/2006 10:57:00 AM |
moron All American 34203 Posts user info edit post |
http://www.retas.de/thomas/computer/programs/useless/misc/pi/index.html
$|=3,141592;sub _ {print@_}sub o{_++$O[0 ];_ 0for 1..$#O}sub O{$;=int $=/10,'0/^ ^';if($;<9) {_$_ for @O;;@O=() ;0}push @O,$;;0 ,;push@ O,'.'if $^==1; 0;if($; ==10){ print ,o,@O=( )}}$~= 1000000 ;$-=10* (q/@O= digits of pi =10/,1) *int($~ /3)+1;$ _=2for@ ,[0..$-] ,;for$^ (1..$~){ $:=$-;$O =0;until ($:<0){$/= 2*$:+1;$/= 10if$/==1;$==10*$,[$:]+$O;$, [$:]=$=%$/;$O=int($=/$/ )*$:--,10}O}o 5/6/2006 11:56:18 AM |
philihp All American 8349 Posts user info edit post |
^AHAAHHA Cool!
Jason Karl Davis, http://www.browserland.org/scripts/curry/
<h4>Example</h4>
function plus(a,b) { return a+b } var add1 = plus.curry()(1); alert(add1(3) == 4);
<h4>Code</h4>
Function.prototype.curry = function() { var args = [], self = this; return (function accumulate(n) { return (n == 0) ? self.apply(this, args) : function(a) { args.push(a); return accumulate(n-1) }; })(this.length || arguments[0] || 0); }
5/6/2006 12:04:38 PM |
scud All American 10804 Posts user info edit post |
qtmfred:
ahaha i remember that one - sadly that's not the first time i've seen something like that. 5/6/2006 1:50:08 PM |
Deshman007 All American 3245 Posts user info edit post |
nerds 5/6/2006 11:24:21 PM |
jimb0 All American 4667 Posts user info edit post |
should i feel bad if i'm in comp sci and i don't know what half this stuff means? 5/7/2006 12:09:52 AM |
Fermat All American 47007 Posts user info edit post |
eh if you understand half of it i'd say you're ok
i get the feeling this kind of stuff could only come from a person that spends most of his time coding from muscle-memory and intuition 5/7/2006 2:10:06 AM |