Skip to content

Instantly share code, notes, and snippets.

View isaacs's full-sized avatar
🔮
only way out is through

isaacs isaacs

🔮
only way out is through
View GitHub Profile
YUI('lang', function (Y) {
YAP.toQueryString = function (obj, name) {
switch (Y.Lang.type(obj)) {
case 'undefined':
case 'null':
return name ? encodeURIComponent(name) + '=' : '';
case 'boolean': obj = +obj; // intentional fallthrough
case 'number':
case 'string':
<!DOCTYPE html>
<html>
<head>
<script>
// 238!
function L(U,C){var d=document,f='firstChild',r='readyState',h=d.documentElement[f],s=d.createElement('script'),m=s[r]?'onreadystatechange':0;s.src=U;s[m||'onload']=function(){if(!m||/ded|te/.test(s[r]))s[m]=0,C()}h.insertBefore(s,h[f])}
// async loading of javascript files, starting asap.
L("http://example.com/example.js",function () {
doSomething();
@isaacs
isaacs / file.js
Created September 8, 2009 05:55 — forked from anonymous/file.js
// more lines, ever-so-slightly faster search, though.
function checkValidMove (xo, pos, state) {
// invalid move.
if (state[pos[0]][pos[1]] !== '') return false;
state[pos[0]][pos[1]] = xo;
// check row
for (var i = 0, col = 0; i < 3; i ++) if (state[pos[0]][i] === xo) col ++;
if (col === 3) return "a winner is you";
@isaacs
isaacs / npm.txt
Created October 13, 2009 07:48 — forked from richtaur/npm.txt
# Node Package Manager
npm [npm-options] command [command options]
install <package>
[-b (stable, edge, nightly) | --branch]
[-f | --force]
[-v | --version]
remove <package>
[-f | --force]
this.names = {
user: "x"
,host: "x"
,server: "x"
,real: "x"
};
// fuck IE
this.names = {
user: "x",
function acquireaDependency () {
acquire('aDependency').addCallback(function(){
p.emitSuccess()
});
return p;
};
function acquireanotherDependency () {
var p = new Promise;
acquireaDependency().addCallback(function () {
@isaacs
isaacs / gist:251295
Created December 8, 2009 00:26 — forked from Marak/gist:251291
multipart.parse(req).addCallback(function(parts) {
debug.log('multipart');
resp.sendHeader(200, {
'Content-Type' : 'text/html',
'Set-Cookie' : session.setCookieHeader()
});
resp.sendBody(html);
resp.finish();
});
@isaacs
isaacs / DAG!
Created January 11, 2010 06:20 — forked from hassox/chain-example.js
/(B)---------------
--(A)--* /(D)--| \
\(C)---* --(G)--(H)
\(E)--(F)--/
chain
(A)
(route
("/B", B) // single link, then fallthrough, don't need a chain
("/C", chain
@isaacs
isaacs / snippet.js
Created February 3, 2010 22:30 — forked from tlrobinson/2-async.js
// EXAMPLE 1: async response
// PSGI equivalent
var app = function(env) {
return function(respond) {
// do some event stuff
setTimeout(function() {
respond({ status : code, headers : headers, body : body });
}, 1000);
}
@isaacs
isaacs / one.js
Created February 7, 2010 07:28 — forked from tim-smart/one.js
Get(/^\/myroute/, function(request) {
...
});
Post(/^\/myroute/, function(request) {
...
});
Head(/^\/myroute/, function(request) {
...