Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
var assert = require('assert')
, subclass = function(type, proto){
// make sure we are extending a global constructor
// accepted: [Boolean, Number, String, Array, Object, Function, RegExp, Date]
if(!global[type.name] || global[type.name].name != type.name) throw new Error();
var constructor = proto.constructor,
keys = Object.keys(proto),
Obj = process.binding('evals').Script.runInNewContext('x = '+type.name), // eval ftw
// pluck
function getProp(thing, key) {
if (thing === null || thing === undefined) return thing
var prop = thing[key]
return typeof prop === 'function' ? prop.call(thing) : prop
}
function drillInto(thing, keyPath) {
return keyPath.split('.').reduce(function(memo, key) {
class Symbol
# Turns a symbol into a proc.
#
# Example:
# # The same as people.map { |p| p.birthdate }
# people.map(&:birthdate)
#
def to_proc
Proc.new {|thing, *args| thing.send(self, *args)}
end
@samsonjs
samsonjs / comma-first.js
Created October 31, 2010 23:22
ouch, accident global called index
// spot the mistake
var objects = [self valueForKeyPath:param],
length = [objects count],
index = length;
average = 0.0;
// try again
var objects = [self valueForKeyPath:param]
, length = [objects count]
; index = length
@samsonjs
samsonjs / chalk.html
Created November 5, 2010 04:27
html body of 37signals' chalk "look ma no text nodes!"
<body>
<div class="share_container">
<div class="close">
<a id="close" href="#"></a>
<div class="instruction"></div>
</div>
<div class="cover">
<div class="instruction"></div>
</div>
</div>
<!DOCTYPE html>
<html manifest="chalk.manifest">
html {
background: #000 url(/images/background.jpg) no-repeat;
-webkit-user-select: none;
}
@media only screen and (orientation:landscape) {
html {
background-position-y: -129px;
}
}
#shade {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
z-index: 10;
visibility: hidden;
-webkit-transition: visibility 0.5s ease-in-out;
}
#chalkboard {
position: absolute;
}
#chalkboard,
#canvas,
#output {
width: 768px;
height: 690px;
}
#tools div.indicator {
position: absolute;
opacity: 0;
background-image: url(../images/chalk-sprites.png);
background-repeat: no-repeat;
background-position-y: -230px;
width: 36px;
height: 25px;
bottom: -15px;
left: 50%;