Skip to content

Instantly share code, notes, and snippets.

View fallengiants's full-sized avatar
💭
in Domine sola fidi, et mala omnis acqui vincit.

fall fallengiants

💭
in Domine sola fidi, et mala omnis acqui vincit.
View GitHub Profile
// INPUT
[
{ "id": "a0001"
, "name": "happiness inc."
, "opens_at": (3600 * 8)
, "closes_at": (3600 * 20)
, "popularity": 8
}
,
@fallengiants
fallengiants / gist:b8e9bf84cbf8e3a9e450
Last active August 29, 2015 14:09
O(n^2) naive implementation
# naive implementation. We could move all the .index stuff into one loop
# and do all kinds of other terrible things
# but that's boring
class ParkingOrder
def initialize(current)
@state = current.split('').uniq
@empty = @state.index ?_
end
seasonalize () {
local season="$1"
shift
rename 's/\d{2}/S'"$season"'E$&/' "$@"
}
@fallengiants
fallengiants / google_autosuggest
Last active August 29, 2015 14:03
Google autosuggest plumbing
require 'cgi'
require 'open-uri'
require 'json'
class AutoPoet
BaseURL = 'http://suggestqueries.google.com/complete/search?client=chrome&q='
Seeds = ['i love', 'you are', 'why does', 'why do', 'why not', 'i have', 'why are', 'where is', 'when will',
'who is', 'will i', 'can i', 'my girlfriend', 'my boyfriend', "i can't", 'i can', 'my dad', 'my mom', 'my wife',
'my husband', 'our family', 'some people', 'why do boys', 'why do girls'
]
@fallengiants
fallengiants / roman
Last active January 2, 2016 12:59
Roman Numerals
class Integer
Roman = 'IVXLCDM'
def to_roman
raise "Number too large" if self > 3999
num = self
num_size = Math.log10(num).to_i
# for each num_size.downto(0),
# get which character to display for that level.
num_size.downto(0).map do |pow|
mid = (pow * 2) + 1
rule110 = [0, 1, 1, 1, 0, 1, 1, 0]
iterate = (array_of_bools) ->
result_array = []
array_of_bools = [false, false, array_of_bools..., false, false]
for index_pointer in [0..(array_of_bools.length - 2)]
tally = 0
tally += 1 << i for i in [0..2] when array_of_bools[index_pointer + 2 - i]
result_array.push rule110[tally]
@fallengiants
fallengiants / gist:5341324
Last active December 15, 2015 23:38
Inject JQuery
d=document;s=d.createElement('script');s.src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js";s.type="text/javascript";d.getElementsByTagName('head')[0].appendChild(s);
@fallengiants
fallengiants / gist:5273343
Created March 29, 2013 20:17
hash.search
class Hash
def search(m)
retval = []
self.each_pair do |k,v|
if v.kind_of?(Hash)
v.search(m).each {|u| retval << [k,*u]}
else
rets = case m
when Regexp
v.to_s =~ m
@fallengiants
fallengiants / gist:5248795
Last active December 15, 2015 10:49
TVTropes Spoiler bookmarklet for ipad
+javascript:(function()%7Bd%3Ddocument%3Bs%3Dd.createElement(%22script%22)%3Bs.src%3D%22//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js%22%3Bs.type%3D%22text/javascript%22%3Bd.getElementsByTagName(%22head%22)%5B0%5D.appendChild(s)%3B%24().ready(function()%7B%24(%22.spoiler%22).click(function()%7B%24(this).removeClass(%22spoiler%22)%7D)%7D)%7D)()%3B
@fallengiants
fallengiants / gist:4992809
Created February 20, 2013 04:11
Git branch in prompt
git_prompt () {
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
PS1="\w \$(git_prompt)\$ "