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
# Find closest point to a set of points.
findClosestPoint = (needle, haystack) ->
(init = new Point).diff = Number.MAX_VALUE
comparator = (memo, point) ->
point.diff = Math.abs(needle.x - point.x) + Math.abs(needle.y - point.y)
if point.diff < memo.diff then point else memo
_.foldl haystack, comparator, init
# Find closest point to a set of points based on angles.
findClosestPointByAngle = (needle, haystack, origin) ->
# Find closest point to a set of points.
findClosestPoint = (needle, haystack) ->
(init = new Point).diff = Number.MAX_VALUE
comparator = (memo, point) ->
point.diff = Math.abs(needle.x - point.x) + Math.abs(needle.y - point.y)
if point.diff < memo.diff then point else memo
_.foldl haystack, comparator, init
@gf3
gf3 / Rakefile
Created September 28, 2011 08:47 — forked from alexaivars/Rakefile
sass, haml & coffescript watcher
require 'rake/clean'
BIN = "public_html"
HAML = FileList['**/*.haml']
LESS = FileList['**/*.less']
COFFEE = FileList['**/*.coffee']
SASS = FileList['**/*.scss']
HTML = HAML.ext('html')
@gf3
gf3 / ago.js
Created June 2, 2011 18:43
Super small relative dates
module.exports = (function(){
const MS =
{ seconds: 1000
, minutes: 60 * 1000
, hours: 60 * 60 * 1000
, days: 24 * 60 * 60 * 1000
, weeks: 7 * 24 * 60 * 60 * 1000
, months: 30 * 7 * 24 * 60 * 60 * 1000
, years: 365 * 24 * 60 * 60 * 1000 }
@gf3
gf3 / git-feature
Created May 3, 2011 22:45
Git Feature Command – Feature Branches
#!/usr/bin/env zsh
# git-feature
# Written by: Gianni Chiappetta <gianni@runlevel6.org>
# Requires: git 1.7.5+, zsh 4.3.11+
# Screenshot: http://cloud.gf3.ca/6TPb
function c_list { echo " \033[1;32m✔\033[0m $1"; }
function e_list { echo " \033[1;31m✖\033[0m $1"; }
var elemDisplays = {},
// Store the iframe outside the function to reuse it
iframe;
function defaultDisplay( nodeName ) {
if ( !elemDisplays[ nodeName ] ) {
// Try the classical method first, which is far faster
var elem = document.createElement( nodeName ),
display;
document.body.appendChild( elem );
@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() : ':('
}
@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 / 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 }
(function() {
var css =
[ '/css/default.css'
, '/css/section.css'
, '/css/custom.css'
]
, i = -1
, link = document.createElement( 'link' )
, head = document.getElementsByTagName( 'head' )[0]
, tmp