Skip to content

Instantly share code, notes, and snippets.

View derekprior's full-sized avatar

Derek Prior derekprior

View GitHub Profile
@danabr
danabr / test_helper.rb
Created April 30, 2011 13:37
Find slow test cases in Test::Unit
class Test::Unit::TestCase # Or ActiveSupport::TestCase if you are using Rails
# This is a debugging utility to find slow tests.
# Usage: rake FIND_SLOW_TESTS=true test:units
unless ENV["FIND_SLOW_TESTS"].blank?
alias_method :old_run, :run
def run(*args, &block)
start_time = Time.now
old_run *args, &block
test_time = Time.now - start_time
puts "\nSLOW TEST: #{self.name}, #{test_time}s" if test_time > 0.5
@ebonical
ebonical / pomodoro.rb
Created May 25, 2011 13:05
Script for starting Pomodoro
#!/usr/bin/env ruby -w0
#
# Using Pomodoro app by iUgol
# http://itunes.apple.com/en/app/pomodoro/id417574133?mt=12
#
require "rubygems"
require "appscript" # gem install rb-appscript
include Appscript
@schneems
schneems / .rb
Created November 23, 2015 19:54
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', github: "rails/rails"
gem 'arel', github: "rails/arel"
gem "rack", github: "rack/rack"
gem "sprockets", github: "rails/sprockets"
gem "sprockets-rails", github: "rails/sprockets-rails"
gem 'coffee-rails', github: "rails/coffee-rails"

Useful Vim mappings

...you didn't know you wanted

Convert Ruby 1.8 to 1.9 hash syntax

nnoremap <Leader>: :%s/:\([^ ]*\)\(\s*\)=>/\1:/gc<CR>
@mcmoyer
mcmoyer / application_helper.rb
Last active December 11, 2015 23:48
my general coffeescript/javascript style
#embed this in your body tag
# %body{body_data}
def body_data
{
:"data-controller" => params[:controller],
:"data-action" => params[:action],
:"data-id" => params[:id],
:"data-parent-controller" => parent_controller,
:"data-parent-id" => params["#{parent_controller.to_s.singularize}_id".to_sym]
#!/usr/bin/env bash
branch_pattern="^## (.*)$"
git_status=`git status -sb`
if [[ $git_status =~ $branch_pattern ]]
then
echo ${BASH_REMATCH[1]}
fi
@henrik
henrik / yosemite_upgrade_notes.md
Last active December 30, 2015 02:29
Yosemite upgrade notes

Yosemite upgrade notes

From a (mostly) Ruby on Rails developer.

After doing the below everything seems to work (some of it worked before doing anything), including Ruby, Gems, RVM, Homebrew, VirtualBox/Vagrant VMs, Pow, tmux, git, vim.

  1. Did a full-disk backup that I can restore from
  2. Moved out /usr/local to avoid super slow install, per option 1 in https://jimlindley.com/blog/yosemite-upgrade-homebrew-tips/: sudo mv /usr/local ~/local
  3. Upgraded to Yosemite
  4. Restored /usr/local, per option 1 in https://jimlindley.com/blog/yosemite-upgrade-homebrew-tips/: sudo mv ~/local /usr
add_index :attachments, :parent_id
add_index :attachments, :asset_id
add_index :domain_names, :user_id
add_index :domain_names, :event_id
add_index :event_memberships, :user_id
add_index :event_memberships, :event_id
remove_index :attachments, :parent_id
remove_index :attachments, :asset_id
remove_index:domain_names, :user_id
remove_index:domain_names, :event_id
config :my_app, :twitter_api,
client: Twitter.SandboxClient
class User < ActiveRecord::Base
attr_accessible :name
has_many :admin_memberships, class_name: "Membership", conditions: {role: 'admin'}
has_many :editor_memberships, class_name: "Membership", conditions: {role: 'editor'}
def admin?
admin_memberships.exists?
end