Skip to content

Instantly share code, notes, and snippets.

View mech's full-sized avatar
🏠
Working from home

mech mech

🏠
Working from home
  • Career Pacific / Jobline
  • Singapore, Tampines
View GitHub Profile
@mech
mech / gist:2646661
Created May 9, 2012 16:55 — forked from jacobat/gist:1240695
Comments for Cory Haines fast tests talk

Introduction

Corey Haines gave his Fast Tests talk at the Golden Gate Ruby Conference 2011 (http://confreaks.net/videos/641-gogaruco2011-fast-rails-tests), here's my feedback on it.

So first up, I think it's very interesting to see another take on how to speed up Rails testing. There's been a focus on it for a couple of years now with various solutions coming for it. From running tests in parallel, to tweaking the filesystem for faster access. Corey Haines take on it is that we should isolate ourselves from the framework that Rails provides and do as much as possible in plain Ruby objects and modules. In his talk he shows how he has been able to massively improve the runtime of his tests by implementing this.

I think it is a logical next step to the current that has been in the community for a while where we have been debating how to improve the design of Rails applications.

Objections

@mech
mech / gist:2515225
Created April 28, 2012 02:41 — forked from dhh/gist:2492118
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@mech
mech / gist:2365916
Created April 12, 2012 09:42
IRBRC
require 'rubygems'
require 'wirble'
require 'hirb'
require 'ap'
require 'pp'
Wirble.init
Wirble.colorize
Hirb.enable
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
@mech
mech / api_controller.rb
Created March 30, 2012 13:47 — forked from ahawkins/api_controller.rb
Basic API style controller for Rails
# A Basic API Controller for Rails
# Handles authentication via Headers, params, and HTTP Auth
# Automatically makes all requests JSON format
#
# Written for production code
# Made public for: http://broadcastingadam.com/2012/03/state_of_rails_apis
#
# Enjoy!
class ApiController < ApplicationController
@mech
mech / gist:2171963
Created March 23, 2012 15:44 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@mech
mech / minitest_spec_expectations.md
Created March 15, 2012 16:16 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@mech
mech / config.ru
Created March 3, 2012 16:13
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
require "rails"
@mech
mech / gist:1936785
Created February 29, 2012 01:22 — forked from metaskills/gist:1932882
Custom Sass Mixin To Supplement Compass' Transition Tools
@mixin animation (
$name: false,
$duration: false,
$timing_function: false,
$delay: false,
$iteration_count: false,
$direction: false
) {
@if $name { -webkit-animation-name: $name; -moz-animation-name: $name; -ms-animation-name: $name; }
@if $duration { -webkit-animation-duration: $duration; -moz-animation-duration: $duration; -ms-animation-duration: $duration; }
@mech
mech / anonymizer_source.rake
Created February 26, 2012 11:56 — forked from adarsh/anonymizer_source.rake
Code from blog post on anonymizing sensitive user data
task :env_checker do
unless Rails.env.development?
puts "Not in development environment, exiting!"
exit 1
end
end
namespace :app_name do
desc 'Anonymize user, company, and location information'
task :anonymize => [:environment, :env_checker] do