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 / appboy-ci.rb
Created August 30, 2012 13:10
Appboy's Continuous Integration and Deployment Script
# Build script for Jenkins. This builds the checked out code and will deploy it if the commit came from
# an environment defined by the DeployEnvironment class.
#
# Scroll down to the bottom of this script to trace how it works.
require 'open-uri'
class StandardOutLogger
# Logs a message to standard out in red
#
# @param [ String ] msg The message to log
@mech
mech / psqlfix.txt
Created July 5, 2012 10:52
Change postgres default template0 to UTF8 encoding
mike@rbci:~$ psql -U postgres
psql (9.0.3)
Type "help" for help.
postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0".
template0=# update pg_database set datistemplate = FALSE where datname = 'template1';
UPDATE 1
@mech
mech / _media-queries.scss
Created May 30, 2012 16:20 — forked from anthonyshort/_media-queries.scss
Media Queries in Sass
// Media Queries in Sass 3.2
//
// These mixins make media queries a breeze with Sass.
// The media queries from mobile up until desktop all
// trigger at different points along the way
//
// And important point to remember is that and width
// over the portrait width is considered to be part of the
// landscape width. This allows us to capture widths of devices
// that might not fit the dimensions exactly. This means the break
@mech
mech / recruitment_pipeline.rb
Created May 28, 2012 09:46
Domain Driven Recruitment Pipeline
class RecruitmentPipeline
end
# Stage is a progression or step on a candidate's job application.
# It represents the state the application is in and offers several
# statistic on the effectiveness of consultant at this stage.
#
# For example, Stage 1 might be AppliedStage, or NewStage
# depending on whether candidate applied himself or consultant
# selected him.

Refactoring

+ R1: A good test suite increases confidence that code changes won't cause 
+ unexpected side effects without being noticed.

+ R2: Tests reduce the cost of structural changes in later stages of a project 
+ because fewer bugs sneak into a system unnoticed.

- R3: Brittle tests can increase the cost of refactoring if they focus on 
@mech
mech / postsql.sql
Created May 18, 2012 15:02 — forked from tobyhede/postsql.sql
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- JSON Types need to be mapped into corresponding PG types
--
-- Number => INT or DOUBLE PRECISION
-- String => TEXT
@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