Skip to content

Instantly share code, notes, and snippets.

ack-grep
# drivers and kernel
build-essential
linux-headers-`uname -r`
@acook
acook / .rvmrc
Created September 13, 2011 15:11
Automatically use/create gemset for your project, and install bundler if its not installed already.
rvm --create ruby-1.9.2-p290@my_gemset_name
if ! command -v bundle ; then
gem install bundler
# Optional:
#bundle install
fi
@acook
acook / application_helper.rb
Last active September 27, 2015 06:17
Set your page title to a sane default.
# This will set your Page Title to a sane default
#
# Usage:
# Put this in your ApplicationHelper.
# Call `title` in your view or layout to display a default title.
# You can set `@title` in your controller action to change the default title.
def title
if @title then
@title
@acook
acook / gist:1225138
Created September 18, 2011 14:50
Simple solution to working with currency.
# in your migration
t.integer :price_in_cents
# in your view to display your price
= number_to_currency object.price
# in your model
def price
price_in_cents.to_f / 100
end
@acook
acook / gist:1226773
Created September 19, 2011 15:37
Put this in your .bash_profile or .bashrc
# Give precedence to user/local/bin because that's where Homebrew installs their stuff
export PATH=/usr/local/bin:$PATH
@acook
acook / gist:1229269
Created September 20, 2011 14:39
Simple search for Rails 3.x
# In your Model
def self.search(search)
search_condition = "%" + search + "%"
self.where 'title LIKE ? OR description LIKE ?', search_condition, search_condition
end
# reference https://we.riseup.net/rails/simple-search-tutorial
@acook
acook / ruby_dev_machine_setup.sh
Last active September 28, 2015 13:18
Simple setup script for a ruby environment on Ubuntu server.
#!/usr/bin/env/bash
# run this like: `curl https://gist.github.com/acook/1444793/raw/ruby_dev_machine_setup.sh | bash`
echo "Enter password to install packages..."
sudo apt-get update
sudo apt-get install -y build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libtool ack-grep vim-nox ctags
\curl -#L https://get.rvm.io | bash -s stable --ruby
source ~/.bashrc
@acook
acook / which.rb
Created February 7, 2012 20:19
Which class is a method defined on?
module Which
def which symbol
klass = self.is_a?(Class) ? self : self.class
reciever = klass.ancestors.select do |dad|
dad.instance_methods.include?(symbol) || dad.methods.include?(symbol)
end.last
end
end
Object.send :extend, Which
@acook
acook / run_tags.rb
Created February 13, 2012 17:12
run_tags.rb
#!/usr/bin/env ruby
# A script to run ctags on all .rb files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git callback.
CTAGS = %x{which ctags}.chomp
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
@acook
acook / array_deletify_extension.rb
Created February 29, 2012 19:57
Array deletify - removes element matching block and returns it
class Array
def deletify! &block
self.each do |element|
return self.delete(element) if yield(element)
end
nil
end
end