Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
@nornagon
nornagon / .bashrc
Last active December 27, 2015 10:59
Become vocabulous with random word definitions on your shell.
# 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'
}
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
{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'
@nornagon
nornagon / gist:4670491
Created January 30, 2013 03:57
disintegrate
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
@nornagon
nornagon / gist:4472517
Created January 7, 2013 05:05
playing with bytebeat
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
@nornagon
nornagon / css_to_rgb.js
Created December 3, 2012 02:53
Parse CSS colors like 'hsla(32,50%,20%,0.4)' into RGB components
// 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)
@nornagon
nornagon / new terminal.applescript
Created November 26, 2012 03:01
AppleScript to open a new iTerm session
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
@nornagon
nornagon / _tag.coffee
Last active October 13, 2015 03:57
3l33t javascript tag creation
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
<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>
@nornagon
nornagon / server.coffee
Created March 19, 2012 11:34
Programmer nomic
coffee = require 'coffee-script'
vm = require 'vm'
connect = require 'connect'
browserChannel = require('browserchannel').server
comm = new (require('events').EventEmitter)
# TODO: sandbox
master = ((comm) ->
code = '''