Skip to content

Instantly share code, notes, and snippets.

View aergonaut's full-sized avatar

Chris Fung aergonaut

View GitHub Profile
When a mobile device is detected, the .loadVideo click event attaches a div#videoOverlay element containing the Youtube embed iframe to the document. The overlay is sized to cover the whole document and the iframe is centered inside it.
#videoOverlay has a click event bound after it is inserted that removes it from the document. This gets around the problem of the close button being unclickable.
me.age = 5
him.age = 6
[me, him].each do |we|
we.ride(Horse.new made_of: :sticks)
end
me.wear :black
him.wear :white
Fight.all.each do |fight|
fight.winner = him
end
@aergonaut
aergonaut / gist:4455253
Created January 4, 2013 19:34
ruby 1.9.3 install incantation with homebrew & rbenv - patches old OS X openssl lib - includes readline
brew update
brew install openssl readline
CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" rbenv install 1.9.3-p362
PROMPT='%{$fg_bold[green]%}%n@bean:%~$(git_prompt_info)%# %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[magenta]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$fg_bold[green]%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$fg[magenta]%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
fout = File.open "outfilename", "w+"
File.open "infilename" do |fin|
fin.each do |line|
fout << line.gsub(/production.log.[0-9]+.gz-...[:-] /, "")
end
end
jQuery ->
mapOpts =
dragging: false
touchZoom: false
scrollWheelZoom: false
doubleClickZoom: false
boxZoom: false
map = L.map('map', mapOpts)
tileOpts =
attribution: 'Tiles by <a href="http://mapbox.com/about/maps" rel="external">MapBox</a>'
@aergonaut
aergonaut / pset.rb
Last active December 14, 2015 06:49
Given a set S, generates the power set P(S) by using a mapping of the elements in S to binary strings
def pset(set)
bins = (0...(2 ** set.length)).map { |x| ("%0#{set.length}d" % x.to_s(2)).split('').map(&:to_i) }
bins.map do |a|
a.map.with_index.map { |v, i| v > 0 ? set[i] : nil }.compact
end
end
@aergonaut
aergonaut / qsort.rb
Created February 27, 2013 07:12
Basic quick sort implementation, unoptimized
def qsort(list)
return list unless list.length > 1
pivot_index = rand(0...list.length)
pivot = list[pivot_index]
less = []
greater = []
list.delete_at(pivot_index)
list.each do |el|
(if el > pivot then greater else less end) << el
end
@aergonaut
aergonaut / 00_reverse.rb
Last active December 14, 2015 06:49
Reverse an array. Recursive implementation, tail call modulo cons
def reverse(ary)
return ary unless ary.length > 1
reverse(ary[0...ary.length-1]).unshift(ary[-1])
end

aergonaut's Ruby Style Guide

Whitespace

Indent with two spaces, never tabs.

# bad
def foo
	# indented with tabs