Skip to content

Instantly share code, notes, and snippets.

@senny
senny / github_branch_clenaup.rb
Created October 17, 2012 13:42
Github Branch cleanup
#!/usr/bin/env ruby
current_branch = `git symbolic-ref --short HEAD`.chomp
if current_branch != "master"
if $?.exitstatus == 0
puts "WARNING: You are on branch #{current_branch}, NOT master."
else
puts "WARNING: You are not on a branch"
end
puts
@senny
senny / basic_decorator.rb
Created October 2, 2012 12:05
Simple Decorator implementation for our projects
require 'delegate'
class BasicDecorator < SimpleDelegator
def self.decorate(objects)
case objects
when Array
objects.map { |object| new(object) }
when ActiveRecord::Relation, DecoratedListProxy, ActiveRecord::Associations::CollectionProxy
DecoratedListProxy.new(self, objects)
else
@senny
senny / gist:1590866
Created January 10, 2012 20:02
const_missing and Class.new
class ThisWorks
def self.const_missing(*args)
p "yay!"
end
NonExistingConstant
end
this_does_not_work = Class.new do
def self.const_missing(*args)
@senny
senny / gist:1579301
Created January 8, 2012 18:54
example virtus integration spec
require 'integration/spec_helper'
class Article
include Virtus
attribute :title, String
def title
super || '<unknown>'
end
@senny
senny / Screencast being a Value.rb
Created January 7, 2012 11:26
0047 - brittle and fragile tests
class Screencast
attr_accessor :versions
def initialize(params)
params.each {|key, value| self.send "#{key}=", value }
end
end
class ScreencastCategories
def self.by_tool(screencasts)
@senny
senny / git konfiguration
Created October 11, 2011 13:37
git configuration
# .gitconfig
[format]
pretty = %C(yellow)%h%Creset%C(green)%d%Creset %s %C(red)[%an]%Creset %C(cyan)[%cr]%Creset
# .bashrc / .zshrc
alias gg='git log --graph'
# Routes
# To prevent too deep nesting, we make the show, edit, update and destroy actions not nested under the category. We have a lot of models nested inside the product.
resources :category do
resources :products, :only => [:new, :create, :index]
end
resources :products, :only => [:show, :edit, :update, :destroy]
# ProductController
# We need to expose :category, :products and :product
@senny
senny / save_failed_scenarios.rb
Created December 28, 2010 09:02
Cucumber support file to save the source of failed scenarios into the tmp folder
# Hook to save the html page of every failed scenario into the temp
# file directory taht it can be checked after cucumber has finished running.
require 'fileutils'
require 'capybara/util/save_and_open_page'
FAILED_SCENARIO_PAGES_PATH = File.join Rails.root, 'tmp', 'failed_scenarios'
FileUtils.rm_rf FAILED_SCENARIO_PAGES_PATH
After do |scenario|
if scenario.failed?
@senny
senny / gist:736331
Created December 10, 2010 15:25
Terminal Setup
alias g='git'
alias gm='git merge'
alias gmf='git merge --ff-only'
alias gs='git status'
alias gl='git pull'
alias glr='git pull --rebase'
alias gf='git fetch'
alias gp='git push'
alias gd='git diff'
alias gc='git commit -v'
GC.disable
objects = ObjectSpace.count_objects
start = objects[:TOTAL]
puts "objects: #{start}" # => 9811
1_000_000.times do
"I am a lonly" + " concatenated" + " string" + "."
end
end_objects = ObjectSpace.count_objects(objects)[:TOTAL]
puts "objects: #{end_objects}"
puts "difference: #{end_objects - start}"