Skip to content

Instantly share code, notes, and snippets.

View gf3's full-sized avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
i = [10,20,30,40,50].index {|n| n > 20 }
## Code (gf3)
function units(n,l) {
if (typeof l === "undefined") l=0;
return (n > 1024 ? units(n/1024, ++l) : (n).toFixed(2)+['','k','m','g','t','p'][l]+'b/s');
}
## Run
units(9001)
// 8.79kb/s
units(900001)
/*!
* jQuery whenLoaded - v0.1pre - 06/25/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// NOTE: TOTALLY UNTESTED!
@gf3
gf3 / gist:457702
Created June 29, 2010 19:40
Regenerate ctags on checkout
#!/bin/sh
# Regenerate ctags on checkout
# project/.git/hooks/post-checkout
DIR=$GIT_DIR
if [ 0 -eq $3 ]; then
# file checkout
else
# tree checkout
@gf3
gf3 / gist:469685
Created July 9, 2010 16:31
Function#bind for V8/node
/**
* Function#bind(context [, arg1 [, arg2 [, argN]]]) -> Function
* - context (Object): Object context to bind to.
* - arg1 (?): Optional argument to curry.
*
* Bind a function to a given `context`. Optionally curry arguments.
*
* ### Examples
*
* var new_func = my_func.bind(my_object, "no u");
@gf3
gf3 / LOLheritence.js
Created September 29, 2010 03:46
Executable child instances
/* ------------------------------ Main Class ------------------------------ */
// Returns "instances" of itself which are actually functions.
function Ben ( greeting ) { var Parent, scope
function Scope () {
// Here is where you put your normal constructor junk
this.greeting = greeting
this.colours = [ 'yellow', 0xFFFFFF ]
}
// Magic
(function() {
var css =
[ '/css/default.css'
, '/css/section.css'
, '/css/custom.css'
]
, i = -1
, link = document.createElement( 'link' )
, head = document.getElementsByTagName( 'head' )[0]
, tmp
@gf3
gf3 / fancy-instances.js
Created December 12, 2010 22:48
Fancy Instances
// Proto-classy
function Book ( a_auth, a_email, options ) { var author, email
this.options = options || {}
this.options.__proto__ = Book.options
author = a_auth
email = a_email
accessor.call( this, 'author'
, function() { return 'Author: ' + author }
@gf3
gf3 / Exam Study Terms.txt
Created April 21, 2011 18:07
Exam Study Progress
3 tenets of science: measurability, falsifiability, and repeatability
Advertising and lack/desire
Advertising as an imagined future
Analogue/Digital
Appadurai, Arjun
Baudrillard, Jean
Beaubourg
Benjamin, Walter
Bilal, Wafaa
Brand, Stewart
@gf3
gf3 / gist:941238
Created April 25, 2011 21:12
An Example Class
function User( options ) {
(this.options = options || {} ).__proto__ = User.options
// Private
function utilityMethod() { return "oh hai" }
// Public
this.say = function say() {
return this.options.awesome ? utilityMethod() : ':('
}