Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
@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
{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'
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
@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'
}
tag = (name, text, attrs) ->
parts = (name ? 'div').split /(?=[.#])/
tagName = "div"
classes = []
id = undefined
for p in parts when p.length
switch p[0]
when '#' then id = p.substr 1 if p.length > 1
when '.' then classes.push p.substr 1 if p.length > 1
else tagName = p
@nornagon
nornagon / keybase.md
Created March 17, 2014 05:45
keybase.md

Keybase proof

I hereby claim:

  • I am nornagon on github.
  • I am nornagon (https://keybase.io/nornagon) on keybase.
  • I have a public key whose fingerprint is 50BB 3434 E762 B0A9 F932 D08E 802A 9C12 D805 6B7C

To claim this, I am signing this object:

@nornagon
nornagon / corrupt.rb
Last active August 29, 2015 13:57
Corrupt random bits in a string
str = "Zalgo, he comes! He rises from the deep, he consumes us"
str.split(//).map { |char|
char.ord.to_s(2).split(//).map { |bit|
if rand < 0.01 then ["0","1"][(rand*2).floor] else bit end
}.join.to_i(2).chr
}.join
# => "Zalgo, he comes! He rises bRom the deep, `e conwumes us"
@nornagon
nornagon / Serializer.scala
Last active August 29, 2015 13:59
Serializer for squants.Quantity
object Serialization {
object UnitSerialization {
val unitForSymbol = Map(
"millisecond" -> Milliseconds,
"celsius" -> Celsius,
"kelvin" -> Kelvin,
"meter" -> Meters,
"nanometer" -> Nanometers,
"second" -> Seconds,
"minute" -> Minutes,
@nornagon
nornagon / orbitals.jl
Created September 29, 2014 01:02
Hydrogen orbitals in Julia
# Cribbed from http://commons.wikimedia.org/wiki/User:Geek3/hydrogen
function LegendreP(l, m, x)
m = abs(m)
a = 1
if m > 0
fac = 1
c = (1 + x) * (1 - x)
for i = 1:m
a *= c * fac / (fac + 1)
@nornagon
nornagon / bug.json
Created September 29, 2014 04:57
boilerplate bug
{"71,23":"thinsolid","72,23":"thinsolid","73,23":"thinsolid","71,24":"shuttle","72,24":"shuttle","73,24":"thinsolid","71,25":"nothing","72,25":"shuttle","73,25":"thinsolid","74,25":"positive","75,25":"negative","76,25":"thinsolid","81,25":"thinsolid","82,25":"negative","83,25":"positive","72,26":"shuttle","73,26":"thinsolid","74,26":"thinsolid","75,26":"nothing","76,26":"nothing","77,26":"nothing","78,26":"nothing","79,26":"shuttle","80,26":"nothing","81,26":"nothing","82,26":"nothing","83,26":"thinsolid","70,27":"thinsolid","71,27":"shuttle","72,27":"shuttle","73,27":"thinsolid","70,28":"thinsolid","71,28":"nothing","72,28":"shuttle","73,28":"thinsolid","70,29":"thinsolid","72,29":"shuttle","73,29":"thinsolid","70,30":"thinsolid","71,30":"negative","72,30":"thinshuttle","73,30":"thinsolid","71,31":"positive","72,31":"shuttle","73,31":"thinsolid","72,32":"nothing","33,22":"thinsolid","45,24":"thinsolid","53,22":"thinsolid","33,26":"thinsolid","37,26":"thinsolid","37,22":"thinsolid","37,18":"thinsolid","33,18"