Skip to content

Instantly share code, notes, and snippets.

@sionide21
sionide21 / gist:5214764
Created March 21, 2013 17:13
PEP8 and pyflakes aliases for git
[alias]
pep8 = !git status -s | awk '{print $2}' | grep '.py' | xargs pep8
pyflakes = !git status -s | awk '{print $2}' | grep '.py' | xargs pyflakes
@sionide21
sionide21 / gist.rb
Created December 11, 2015 22:35
Enumerable Weirdness
class Test
include Enumerable
def each
yield "Hello"
yield "World"
end
end
enum = Test.new
array = ["Hello", "World"]
@sionide21
sionide21 / regexen.rb
Created July 31, 2012 00:59
Regex game regression tester
class Regexen
def initialize(a={})
a.default_proc = proc { |h,k| [] }
@good = a[:good]
@bad = a[:bad]
end
def good=(r)
@good << r
end
def bad=(r)
@sionide21
sionide21 / taxes.rb
Created June 30, 2012 15:00
Taxes Estimator 2012
SINGLE_RATES = {8700 => 0.10, 35350 => 0.15, 85650 => 0.25, 178650 => 0.28, 388350 => 0.33, Float::INFINITY => 0.35}
MARRIED_RATES = {17400 => 0.10, 70700 => 0.15, 142700 => 0.25, 217450 => 0.28, 388350 => 0.33, Float::INFINITY => 0.35}
def taxes(amt, rates=SINGLE_RATES)
last_cap = 0
taxes = 0
rates.each do |cap, rate|
taxable = amt - last_cap
if taxable > 0
taxes += [cap, taxable].min * rate
@sionide21
sionide21 / simple_form.rb
Created January 2, 2012 16:40 — forked from seyhunak/simple_form.rb
Using simple_form and integrating Twitter Bootstrap
1. Use latest build
gem 'simple_form', :git => 'git://github.com/plataformatec/simple_form.git'
2. Create an initializer
# /config/initializers/simple_form.rb
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a complete input.
# You can remove any component from the wrapper, change the order or even
@sionide21
sionide21 / test.rb
Created March 3, 2011 13:37
DNS Sample
require 'dns'
server = DNS::Server.new
server.handle_a do |query, response|
response << DNS::Record::A.new(query.name, "192.168.12.10#{rand 10}")
end
server.listen
@sionide21
sionide21 / gist:850065
Created March 1, 2011 22:49
Firefox Error
sqlite> select count(*) from moz_downloads;
Error: database disk image is malformed
export FIGNORE=".svn"
@sionide21
sionide21 / gist:434547
Created June 11, 2010 14:37
Remove leading whitespace
${FOO##*( )}
@sionide21
sionide21 / gist:434550
Created June 11, 2010 14:40
FOO with whitespace
FOO=" Bar"