Skip to content

Instantly share code, notes, and snippets.

Avatar

Hendrik Mans hmans

View GitHub Profile
View gist:52550
- set_page_title do
%h1
%strong Ein neuer User.
Wie spannend!
View gist:52804
Add localized templates
# Default locale
app/views/messages/index.html.erb
# I18n.locale is set to :da (Danish)
app/views/messages/index.da.html.erb
View gist:67733
def index
@users = User.latest.with_avatar
end
def random
@users = User.random.with_avatar.limit(21)
end
View gist:152806
module ActiveRecord
class TablelessBase < ActiveRecord::Base
def self.columns() @columns ||= []; end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
end
end
View gist:178000
def recalculate!
self.number_of_questions = Match.connection.select_value("SELECT count(*) as c
FROM
responses as my_responses
LEFT JOIN
responses as their_responses
ON their_responses.user_id = #{user_b.id}
AND my_responses.question_id = their_responses.question_id
WHERE
my_responses.user_id = #{user_a.id}
View gist:268464
# awesome git-enabled prompt
function parse_git_branch {
ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
export PS1='\[\033[00;32m\]\u \[\033[00;35m\]\w\[\033[00m\]\[\033[00;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s` \[\033[00m\]\$ '
View .irbrc
require "rubygems"
require "ap"
unless IRB.version.include?('DietRB')
IRB::Irb.class_eval do
def output_value
ap @context.last_value
end
end
else # MacRuby
@hmans
hmans / gist:876593
Created Mar 18, 2011
Having fun with Rspec 2 and Capybara.
View gist:876593
require 'acceptance_helper'
feature "Welcome Page" do
background do
50.times { Factory(:user) }
end
scenario "when user is not logged in" do
visit '/'
page.should have_content('Welcome! :)')
@hmans
hmans / .gitconfig
Created Oct 10, 2011
My .gitconfig
View .gitconfig
# User information. Replace with your own data, obviously.
#
[user]
name = Hendrik Mans
email = hendrik@mans.de
# Automatically track branches with the same name
#
[branch]
autosetupmerge = true
@hmans
hmans / gist:1378862
Created Nov 19, 2011
FlexImage Polaroid extension
View gist:1378862
class Fleximage::Operator::Polaroid < Fleximage::Operator::Base
def operate(angle_range = 10, border_width = 10)
@image.border!(border_width, border_width, "#f0f0ff")
# Bend the image
@image.background_color = "none"
amplitude = @image.columns * 0.01 # vary according to taste
wavelength = @image.rows * 2
You can’t perform that action at this time.