Skip to content

Instantly share code, notes, and snippets.

export FIGNORE=".svn"
@sionide21
sionide21 / gist:850065
Created March 1, 2011 22:49
Firefox Error
sqlite> select count(*) from moz_downloads;
Error: database disk image is malformed
@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 / 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 / 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 / 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 / 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
ve() {
local curdir ve
curdir="$PWD"
[ -z "$1" ] && ve="ve" || ve="$1"
while ! ls -d "$ve" >/dev/null 2>&1; do
if [ "$PWD" == "/" ]; then
echo "Cannot find a '$ve' directory on the current path" >&2
cd $curdir
return -1
fi
@sionide21
sionide21 / gist:7807702
Last active December 30, 2015 09:09
This `ls` took over 3 hours to complete. I have too many files.
$ time ls -lh > ~/files.txt
real 186m14.030s
user 0m9.361s
sys 43m37.939s
@sionide21
sionide21 / sqrtSums.hs
Created December 6, 2013 13:52
sqrtSums | sum of the square root of the first natural numbers sqrtSums < x
sqrtSums :: Double -> Int
sqrtSums x = length (takeWhile (<x) (scanl1 (+) (map sqrt [1..]))) + 1