Skip to content

Instantly share code, notes, and snippets.

View airhorns's full-sized avatar
🎯
Workin' on Gadget at https://gadget.dev

Harry Brundage airhorns

🎯
Workin' on Gadget at https://gadget.dev
View GitHub Profile
toto = Toto::Server.new do
# ...
set :to_html, lambda {|path, page, ctx, blk|
Dir.glob("#{path}/#{page}.*").each do |filename|
return ::Tilt.new(filename).render(ctx, &blk)
end
raise Errno::ENOENT # Tell toto to 404 if no files can be found
}
hash = {foo: 1, bar: 2, baz: 3}
handlers = []
for key, val of hash
callback = ->
console.log "Callback has been called for key #{key}"
handlers[val] = callback
handlers[1].call() # outputs 'baz' instead of the expected 'foo', because baz was the last key assigned.
@airhorns
airhorns / gist:771286
Created January 9, 2011 00:46
Potential Validations syntax
// A complete example.
var Post = Backbone.Model.extend({
validations: {
body: {
required: true, // Uses the built in validation methods
minLength: 100
},
title: {
// Pass multiple arguments to the validation function
lengthInRange: [10,100],
val d =
[(Two,Clubs),(Three,Clubs),(Four,Clubs),(Five,Clubs),(Six,Clubs),
(Seven,Clubs),(Eight,Clubs),(Nine,Clubs),(Ten,Clubs),(Jack,Clubs),
(Queen,Clubs),(King,Clubs),...] : (rank * suit) list
- dealSimple(2,3,d);
val it = [Hand ((Four,Clubs),Hand (#,#)),Hand ((Seven,Clubs),Hand (#,#))]
: hand list
-
@airhorns
airhorns / source.tex
Created January 14, 2011 01:57
console output
This is XeTeX, Version 3.1415926-2.2-0.9997.4 (TeX Live 2010)
entering extended mode
(./cv.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, ba
sque, danish, dutch, finnish, french, german, ngerman, swissgerman, hungarian,
italian, bokmal, nynorsk, polish, portuguese, spanish, swedish, loaded.
(/usr/local/texlive/2010basic/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2010basic/texmf-dist/tex/latex/base/size11.clo))
@airhorns
airhorns / Top
Created March 6, 2011 04:55
top output
top - 23:58:21 up 22 days, 2:50, 4 users, load average: 4.00, 3.96, 3.45
Tasks: 186 total, 2 running, 184 sleeping, 0 stopped, 0 zombie
Cpu0 : 0.3%us, 5.6%sy, 0.0%ni, 7.0%id, 86.4%wa, 0.0%hi, 0.7%si, 0.0%st
Cpu1 : 0.0%us, 1.6%sy, 0.0%ni, 89.0%id, 6.8%wa, 0.0%hi, 2.6%si, 0.0%st
Mem: 3096304k total, 3015632k used, 80672k free, 12344k buffers
Swap: 9069560k total, 0k used, 9069560k free, 2816800k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26149 hornairs 20 0 5420 2296 1824 R 5.0 0.1 1:15.48 afpd
833 root 20 0 0 0 0 D 2.7 0.0 5:28.96 md0_raid5
(rdb:1) query.conditions
(book = #<Book @id=1 @name="Harry Potter">)
(rdb:1) query.conditions.first.subject
#<DataMapper::Associations::ManyToOne::Relationship:0x00000101152528
@required=true,
@key=false,
@child_model=BookTag,
@child_model_name="BookTag",
@parent_model_name="Book",
@airhorns
airhorns / gist:1165647
Created August 23, 2011 16:06
coffeescript permutations
permute = (array) ->
buf = []
return array if array.length == 1
for element, i in array
buf.push [element]
remaining = array.slice()
remaining.splice(i, 1)
subPermutations = permute(remaining)
buf.concat subPermutations
for sub in subPermutations
require 'hashr'
module Travis
module Worker
module Builders
class << self
def builder_for(config)
lang = camelize(config.language || Travis::Worker.config.default_language || 'ruby')
case lang
class SomeController extends Batman.Controller
@accessor
get: (key) ->
return @[key] if @[key]?
return @get('someModel').get(key)
set: (key, val) ->
return @[key] = val if @[key]?
return @get('someModel').set(key, val)