Skip to content

Instantly share code, notes, and snippets.

View hmans's full-sized avatar
🚀
Let's go!

Hendrik Mans hmans

🚀
Let's go!
View GitHub Profile
def index
@users = User.latest.with_avatar
end
def random
@users = User.random.with_avatar.limit(21)
end
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
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}
# 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\]\$ '
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 March 18, 2011 18:35
Having fun with Rspec 2 and Capybara.
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 October 10, 2011 09:31
My .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 November 19, 2011 14:05
FlexImage Polaroid extension
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
@hmans
hmans / gist:1497767
Created December 19, 2011 15:58
New rbfu invocation style
# So here's the new rbfu invocation style I'm tinkering with.
# If you want to play around with it, you can get it from the
# 'rbfu-exec' branch in rbfu:
#
# https://github.com/hmans/rbfu/tree/rbfu-exec
#
# The overall syntax is:
#
# rbfu [@<version>] <command>
#
$listenerOptions = new Zend\Module\Listener\ListenerOptions($appConfig['module_listener_options']);
$defaultListeners = new Zend\Module\Listener\DefaultListenerAggregate($listenerOptions);
$defaultListeners->getConfigListener()->addConfigGlobPath('config/autoload/*.config.php');