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
@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);
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 / 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
@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'
]
seasonalize () {
local season="$1"
shift
rename 's/\d{2}/S'"$season"'E$&/' "$@"
}
@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
// INPUT
[
{ "id": "a0001"
, "name": "happiness inc."
, "opens_at": (3600 * 8)
, "closes_at": (3600 * 20)
, "popularity": 8
}
,
1.upto(3**8).each do |i|
flags = i.to_s(3).rjust(8, ?0).split(//)
math = ''
1.upto(9).map do |c|
math += c.to_s
math += case flags.shift
when ?1 then ?+
when ?2 then ?-
else ''
end
#f '123456789',100
def f(d,t)
a=[]
0.upto(3**(d.size-1)).map do |n|
l,n=[d,n.to_s(3)].map {|t| t.chars.map(&:to_i)}
k,m,z=[l.shift],1,1
l.map {|i| o=n.pop||0;z=(1-(o&1)*2); o&2>0 ? k<<k.pop*10+i*m : k<<i*m=z }
a<<k.join(?+).gsub('+-',?-) if k.reduce(&:+)==t
end
class Symbol
def ~@
_bound = binding
return ->(arg) {_bound.send(self, arg)}
end
end