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
# Public: A module to be mixed in another class with common methods to index
# records in ElasticSearch.
#
# The host object needs to respond to 'indexed_attributes', which will return
# an array of the attributes names to be indexed.
#
# It's also recommended to override the 'save?' method to make sure only
# records that match some specifications are indexed.
#
# The type used for the ElasticSearch index will be extracted from the name of
# But why not just this?
# More straightfoward and faster to write...
class Job < ActiveRecord::Base
def publish
update_attribute(:status, "published")
JobActivityFeed.create("#{title} has been published", id)
JobMailer.info_consultant(id, "consultant@cp.com").deliver
end
end
@mech
mech / .rspec
Created January 15, 2013 09:09 — forked from coreyhaines/.rspec
--colour
-I app
require 'singleton'
# outputs a colored call-trace graph to the Rails logger of the lines of ruby code
# invoked during a single request.
#
# Example:
#
# 1) Make sure this file is loaded in an initializer
#
# 2) Add the following to your application.rb in Rails3:
@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