Skip to content

Instantly share code, notes, and snippets.

describe "something", :focus => true do
it 'does something'
end
rspec spec/something.rb:8
rspec spec/something.rb -t focus
rspec spec/something.rb -e 'example name'
http://user-contributions.org/wikis/userwiki/index.php?title=Bash-to-Ruby
http://www.grymoire.com/Unix/Sed.html
http://www.thegeekstuff.com/2009/12/unix-sed-tutorial-6-examples-for-sed-branching-operation/
http://www.catonmat.net/blog/sed-one-liners-explained-part-one/
http://www.catonmat.net/blog/awk-one-liners-explained-part-one/
http://sed.sourceforge.net/local/docs/emulating_unix.txt
http://www.eng.cam.ac.uk/help/tpl/unix/sed.html
Ruby:
File.read('somefile.txt').split("\n").join(" ")
@happyrobots
happyrobots / kill-port.sh
Created July 23, 2011 05:18
kill process occupying on port
lsof -w -n -i tcp:3000
fuser -n tcp 3000
netstat -anp|grep :3000[[:blank:]]
kill -9 pidnumber
# create remote tracking branch
git branch --track feature1 origin/master
# rm /var/lib/pgsql/data
# service postgresql initdb
# service postgresql start
# vim /var/lib/pgsql/data/pg_hba.conf
replace ident with trust
class OptionFilter
def initialize(default_opts)
@default_opts = default_opts
end
def generate(param_name, label_value_pairs)
@copy = @default_opts.clone
@current_param = param_name
label_value_pairs.each { |pair| yield pair[0], opts_for(pair[1]) }
end
@happyrobots
happyrobots / bm_map_vs_push.rb
Created July 6, 2011 14:23
Map is incredibly slow. Of course it's a little bit weird to let Ruby run 10M loop.
require 'benchmark'
MAX = 10_000_000
Benchmark.bm(3) do |b|
b.report("push") do
arr = []
MAX.times {|i| arr.push(i.to_s)}
end
@happyrobots
happyrobots / benchmark.rb
Created June 5, 2011 20:34
RSpec basic benchmark matchers
require "benchmark"
require "rspec"
module RSpec
module Benchmark
class Result
attr_accessor :slowest, :fastest, :average, :elapsed
def initialize(elapsed)
@elapsed = elapsed
class Array
# Largest range with different subsequence,
# without any kind of clever optimization.
def range_with_diff_subseq(other)
self_size = self.size
other_size = other.size
low = 0
max_pos = self_size < other_size ? self_size : other_size
Flash objects do not obey z-index. This is particularly often found on youtube vids..
To solve this, pass wmode parameter with transparent value... like this: www.youtube.com/embed/somecode?wmode=transparent
$(function() {}); seems to wait for document ready forever, if it's invoked on a popup. Well um.. or probably because the document is already 'ready', the piece of code inside that function won't be even executed.
Instead, put the thing inside that function near the end of </body> tag... please, only if it's a popup. lolplz..