Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
<script src='LABjs/LAB.min.js'></script>
<script>
<!--
$LAB
.setOptions({BasePath:'/syntaxhighlight/js/'})
.script('shCore.js',
'shBrushCpp.js',
'shBrushCss.js',
'shBrushJScript.js',
'shBrushPython.js',
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// ------------------------------------
for (var i = 0, j = foo.length; i < j; i++) {
// do stuff
}
for (var i = foo.length; i;) {
// first usage in loop: blah[--i]
// do stuff slightly faster in reverse order
}
@getify
getify / gist:3189596
Created July 27, 2012 18:25 — forked from rexmac/gist:3189232
attempting to use jParser to extract dimensions of JPG image file
var fs = require("fs");
var jParser = require("jParser");
var eof = false;
fs.readFile("sample.jpg",function(err,data) {
if (!err) {
var view = new jDataView(data, undefined, undefined, false);
var parser = new jParser(view,{
// JPG
@getify
getify / type-declarations.js
Created December 14, 2012 22:36 — forked from nzakas/type-declarations.js
"type2" implementation
/*
* Forked Zakas' attempt at a `type()` "class" maker/extender utility.
* Mainly, this approach automatically calls a type's super-type (if any)
* `constructor` upon construction of the type, if you didn't specify
* a `constructor` for the type itself.
*/
function type(prototype, declaration) {
function mixin(receiver, supplier) {
if (Object.getOwnPropertyDescriptor) {
@getify
getify / type-declarations.js
Created December 16, 2012 02:27 — forked from nzakas/type-declarations.js
"make3" implementation
/*
* Forked Zakas' attempt at a `type()` "class" maker/extender utility.
* This variation just makes and links objects, without the unnecessity
* of using constructor functions. You can however specify `init()`
* functions to use upon creation of the object. NOTE: because there are
* no more constructor functions, comparisons with `instanceof` and
* `constructor` no longer apply.
*/
function make(delegateTo, declaration) {
@getify
getify / 1.js
Last active December 14, 2015 02:39 — forked from padolsey/1.js
var x = '/x/';
/x/==x
@getify
getify / test.js
Created April 29, 2013 20:14 — forked from furf/test.js
console.log('test');
@getify
getify / async.js
Last active January 3, 2016 18:29 — forked from JedWatson/async.js
Example usage of asynquence.gate() to update an array against a redis cache
// This function takes a contents object with a files array.
// The goal is to cache each file details in redis then replace
// the file's path with a secure, obscured url.
// Finally the contents object is returned with the updated array
// in place of the old one.
// async = require('async')
// uuid = require('node-uuid')
// redis.client = require('node-redis').createClient()
@getify
getify / async.js
Last active January 3, 2016 19:29 — forked from JedWatson/async.js
Example usage of the new asynquence.map() contrib plugin to update an array against a redis cache
var transform = function(contents, doneTransform) {
var authExpiry = 60 * 60 * 1000,
authId = uuid.v4(),
authKey = 'file:auth:' + authId;
redis.client.set(authKey, JSON.stringify({
userId: req.user.id
}));
redis.client.expire(authKey, authExpiry);