Skip to content

Instantly share code, notes, and snippets.

View timonv's full-sized avatar
🚀

Timon Vonk timonv

🚀
View GitHub Profile
@timonv
timonv / post.rb
Created August 14, 2011 10:16
Post model
class Post
include Mongoid::Document
include Mongoid::Timestamps
field :title, :type => String
field :content, :type => String
field :permalink, :type => String
belongs_to :user
@timonv
timonv / rvminfo
Created August 14, 2011 11:11
RVM info
ruby-1.9.2-p290@blog:
system:
uname: "Darwin Vainglory.local 11.0.0 Darwin Kernel Version 11.0.0: Sat Jun 18 12:56:35 PDT 2011; root:xnu-1699.22.73~1/RELEASE_X86_64 x86_64"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)"
zsh: "/usr/local/bin/zsh => zsh 4.3.12 (i386-apple-darwin10.7.4)"
rvm:
version: "rvm 1.6.32 by Wayne E. Seguin ([email protected]) [https://rvm.beginrescueend.com/]"
@timonv
timonv / remove remote merged branches
Created September 3, 2012 13:43
Remove merged branches from remote git
git branch -r --merged | grep -v 'master$' | sed "s/origin\///" | xargs -I% git push origin :%
def wait_for(klass, objects, assert = Proc.new { |x| x.present? }, retries = 10)
retries.times do |i|
break if assert.call(klass.send(objects))
sleep i * 0.1
end
end
# For pretty oneliners. It just memoizes on nil, but accepts TrueClass as a value
def memoize(&block)
key = caller[0][/`.*'/][1..-2] # Get the method name of the caller
@_memoized ||= {}
@_memoized[key].nil? ? @_memoized[key] = block.call : @_memoized[key]
end
# memoize do
# ExpensiveOperation
# end
@timonv
timonv / .vimrc.after
Last active December 14, 2015 16:29
Always show sign column so on syntastic/gitgutter it doesn't 'jump'
# Thanks to http://superuser.com/questions/558876/how-can-i-make-the-sign-column-show-up-all-the-time-even-if-no-signs-have-been-a
autocmd BufEnter * sign define dummy
autocmd BufEnter * execute 'sign place 9999 line=1 name=dummy buffer=' . bufnr('')
class Person
def self.get_name
persons_name
end
def self.persons_name
"Sam"
end
private_class_method :persons_name
@timonv
timonv / test.rb
Created April 9, 2013 13:03
Private class methods in Ruby
class Person
def self.get_name
persons_name
end
def self.persons_name
"Sam"
end
private_class_method :persons_name
@timonv
timonv / application.rb
Last active December 17, 2015 14:49
Show UserID in log files with UUID
# Hack around the middleware stack a bit to get warden session correctly in
config.middleware.delete(ActionDispatch::Cookies)
config.middleware.delete(ActionDispatch::Session::CookieStore)
config.middleware.insert_before(Rails::Rack::Logger, ActionDispatch::Session::CookieStore)
config.middleware.insert_before(ActionDispatch::Session::CookieStore, ActionDispatch::Cookies)
# Rotate two files, max 5 mb each
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(config.paths['log'].first, 2, 5 * 1024 * 1024))
config.log_tags = [
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end