Skip to content

Instantly share code, notes, and snippets.

@dnagir
dnagir / .vimrc
Created March 14, 2012 23:27
My current .vimrc
" Example Vim configuration.
" Copy or symlink to ~/.vimrc or ~/_vimrc.
set nocompatible " Must come first because it changes other options.
filetype off
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
"silent! call pathogen#runtime_append_all_bundles()
@dnagir
dnagir / Gemfile.lock
Created February 21, 2012 07:20
Rails issue #5095
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.1)
actionpack (= 3.2.1)
mail (~> 2.4.0)
actionpack (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)
@dnagir
dnagir / utility_steps.rb
Created February 20, 2012 23:14
Capybara/Cucumber AJAX
module UtilitySteps
def wait_for_page_load
page.wait_until do
if Capybara.current_driver != :rack_test
page.has_css?('body.dom-loaded') and !has_pending_ajax_request?
else
true
end
end
@dnagir
dnagir / application.rb
Created February 15, 2012 01:37
Rails 3.2.1 configs
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
@dnagir
dnagir / async_smtp_delivery_method.rb
Created February 10, 2012 03:38
Threaded mail delivery in rails
# lib/async_smtp_delivery_method.rb
require 'mail'
class AsyncSmtpDeliveryMethod
def initialize(settings)
@settings = settings
end
def deliver!(mail)
@dnagir
dnagir / has_symbolic_field.rb
Created February 8, 2012 23:44
Symbols and enums
module HasSymbolicField
extend ActiveSupport::Concern
module ClassMethods
# Defining (all below are equivalent):
# - has_symbolic_field :status, [:active, :pending]
# - has_symbolic_field :status, :active => 'Active', :pending => 'Pending'
# - has_symbolic_field :status, :active => 'Active', :pending => nil
# Accessing:
# - it.status # :available
@dnagir
dnagir / import.rb
Created February 8, 2012 04:41 — forked from baldowl/import.rb
Import a blogger archive to jekyll (octopress version, allows quotes in titles)
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'uri'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]
@dnagir
dnagir / fail_fast.rb
Created February 1, 2012 08:00
Fail fast with Capybara
require 'capybara/util/timeout'
# Rewriting the https://github.com/jnicklas/capybara/blob/master/lib/capybara/util/timeout.rb
# Instead of raising timeout error, print the response info
module Capybara
class << self
##
# Provides timeout similar to standard library Timeout, but avoids threads
@dnagir
dnagir / ci.rake
Created January 28, 2012 07:24
Fail CI build with SimpleCov
# lib/tasks/ci.rake
require 'nokogiri'
desc "Run everything on the CI server with all its outcomes (deploy etc)"
task :ci do
Rake::Task['spec'].invoke
ensure_test_coverage 99
Rake::Task['cucumber'].invoke
# TODO: Figure out how to run Jasminerice https://github.com/bradphelan/jasminerice/issues/31
@dnagir
dnagir / faster_helper.rb
Created January 25, 2012 03:21
The spec helper I use to run faster specs
ENV["RAILS_ENV"] ||= 'test'
cur_dir = File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH << "#{cur_dir}"
if defined? Bundler
# Most likely going with the full env
require 'spec_helper'
else
$LOAD_PATH << "#{cur_dir}/app/models"