Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
@amiel
amiel / gist:2589753
Created May 3, 2012 21:44
Sublime Text 2 Configuration
{
"auto_complete_commit_on_tab": false,
"color_scheme": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme",
"ensure_newline_at_eof_on_save": true,
"font_face": "Inconsolata-dz",
"font_size": 14.0,
"highlight_line": true,
"rulers":
[
80,
@amiel
amiel / anti-pattern.sh
Created April 25, 2012 21:35
git checkout --merge example
$ git checkout some_branch
error: Your local changes to the following files would be overwritten by checkout:
Gemfile
Please, commit your changes or stash them before you can switch branches.
Aborting
$ git stash
$ git checkout some_branch
$ git stash pop
@amiel
amiel / add_email_at_utc_hour_to_users_spec.rb
Created April 25, 2012 04:35
A sample migration spec
# spec/migrations/add_email_at_utc_hour_to_users_spec.rb
require 'spec_helper'
require Dir[Rails.root.join('db/migrate/*_add_email_at_utc_hour_to_users.rb')].first
describe AddEmailAtUtcHourToUsers do
let(:migration) { AddEmailAtUtcHourToUsers.new }
describe '#up' do
before { migration.up; User.reset_column_information }
@amiel
amiel / gist:2295633
Created April 3, 2012 21:33
I wonder if this is causing problems
$ for g in $(for p in `echo $PATH|sed 's/:/ /g'`;do if [ -f $p/git ];then echo $p/git; fi;done|sort|uniq);do echo $g;$g --version;done
/usr/bin/git
git version 1.7.7.5 (Apple Git-26)
/usr/local/bin/git
git version 1.7.9.5
/usr/local/git/bin/git
git version 1.7.6
@amiel
amiel / gist:2288698
Created April 3, 2012 01:49
Metadata pattern
class SomeModel < ActiveRecord::Base
# These are all the things I tend to add to my activerecord model for the metadata (extension table) pattern
has_one :metadata, autosave: true, dependent: :destroy, class_name: 'SomeModelMetadata'
def metadata_with_creation
metadata_without_creation || build_metadata
end
alias_method_chain :metadata, :creation
delegate :html, :html=, :html?,
:start_at, :start_at=, :start_at?,
@amiel
amiel / capybara_select_dates_and_times.rb
Created March 7, 2012 01:02 — forked from szimek/capybara_select_dates_and_times.rb
Cucumber steps for selecting time and date (using Capybara)
require "xpath" # XPath is a separate gem now
module Cucumber
module Rails
module CapybaraSelectDatesAndTimes
def select_date(field, options = {})
date = Date.parse(options[:with])
selector = %Q{.//fieldset[contains(./legend, "#{field}")]}
within(:xpath, selector) do
find(:xpath, './/select[contains(@id, "_1i")]').find(:xpath, ::XPath::HTML.option(date.year.to_s)).select_option
@amiel
amiel / my_model.rb
Created February 4, 2012 04:40
A nice pattern for validating the type in STI
class MyModel < ActiveRecord::Base
include ActiveSupport::DescendantsTracker
validates_inclusion_of :type, :in => direct_descendants.map(&:name)
# ...
end
@amiel
amiel / custom_validation_matcher.rb
Created December 24, 2011 03:32
I was fed up with "expected valid? to return true". Now you get errors
module CustomValidationMatcher
class IsValid
def matches?(target)
@target = target
@target.valid?
end
def failure_message
"expected #{ @target.class.name } to be in valid, errors were: #{ @target.errors.full_messages.inspect }"
@amiel
amiel / gist:1477839
Created December 14, 2011 18:29
Work-around for for disappearing HTML output section in TextMate 2

Avian hidden HTML Output Work Around

Open ~/Library/Application Support/TextMate/Session/Info.plist (the XCode plist editor makes it nice and easy, but you can open it in textmate as well if you are comfortable editing plists).

You are looking for htmlOutputHeight. Mine was set to a negative value, setting it to a positive value should fix the issue (it did for me).

SHIP IT