This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Needs jq. brew install jq. | |
random_word_def() { | |
local random_word wordnik_for_word show_definition | |
random_word() { | |
perl -e 'rand($.) < 1 && ($line = $_) while <>; print $line' < /usr/share/dict/words | |
} | |
wordnik_for_word() { | |
curl -s http://api.wordnik.com/v4/word.json/"$1"/definitions'?api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component = (c) -> | |
c::_added = (gobj) -> | |
throw 'added twice' if @me? | |
@me = gobj | |
@world = @me.world | |
@init? @_args... | |
new_c = (args...) -> | |
r = new c | |
r._args = args | |
r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{Collection} = masala = require './masala' | |
live = require './sugar' | |
data = new Collection [live { | |
name: 'list of things' | |
data: new Collection [live({val:3}),live({val:4})] | |
}] | |
http = require 'http' | |
render = require './render' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
disintegrate = (fn) -> | |
tests = [] | |
ret_fn = (args...) -> | |
args_saved = JSON.stringify(args) | |
res = fn.apply(this, args) | |
res_saved = JSON.stringify(res) | |
tests.push {args:args_saved,res:res_saved} | |
return res | |
ret_fn.tests = tests | |
ret_fn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = function(s,v) { var x = t*v; return (x*(3+1*s[(x>>10)%s.length]))%255 }, | |
S = function(s,v) { var x = t*v; return (x*(3+1*s[(x>>10)%s.length]))%255>127?255:0 }, | |
(T("121312123321",1) + T("12131212332",1.005))/2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tested in Chrome 23, Firefox 16, and IE9 in standards mode (i.e. with <!DOCTYPE html>). | |
// Converts '#f00', 'red', 'hsl(0, 100%, 50%)' and 'rgb(255,0,0)' to {r:255,g:0,b:0}. | |
function cssColorToRGB(cssColor) { | |
var s = document.createElement('span') | |
document.body.appendChild(s) | |
s.style.backgroundColor = cssColor | |
var rgb = getComputedStyle(s).backgroundColor | |
document.body.removeChild(s) | |
var m = /^rgb\((\d+), (\d+), (\d+)\)$/.exec(rgb) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "System Events" to set terminal_open to process "iTerm" exists | |
if not terminal_open then | |
tell application "iTerm" to activate | |
else | |
tell application "iTerm" | |
set myterm to (make new terminal) | |
tell myterm | |
launch session "Default" | |
activate | |
end tell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tag = (name, text) -> | |
parts = name.split /(?=[.#])/ # why yes, i am a ninja | |
tagName = "div" | |
classes = [] | |
id = undefined | |
for p in parts | |
switch p[0] | |
when '#' then id = p.substr 1 | |
when '.' then classes.push p.substr 1 | |
else tagName = p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="http://segment.io" onclick="track('clicked on segment.io')">Yay!</a> | |
<script> | |
function track(msg) { | |
new Image().src = "http://segment.io/track?msg=" + encodeURLComponent(msg) | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coffee = require 'coffee-script' | |
vm = require 'vm' | |
connect = require 'connect' | |
browserChannel = require('browserchannel').server | |
comm = new (require('events').EventEmitter) | |
# TODO: sandbox | |
master = ((comm) -> | |
code = ''' |