Skip to content

Instantly share code, notes, and snippets.

View mz026's full-sized avatar

Yang-Hsing Lin mz026

View GitHub Profile
@mz026
mz026 / GeneralController.rb
Created September 29, 2013 13:10
general controller to be inherited
class GeneralController < ApplicationController
skip_before_filter :verify_authenticity_token
def method_missing method_name, *args, &block
if [:render_400,
:render_401,
:render_403,
:render_404,
:render_409].include?(method_name)
execute <<-SQL
ALTER TABLE credit_cards
ADD CONSTRAINT fk_credit_cards_kid_users_kid
FOREIGN KEY (kid) REFERENCES users(kid)
ON UPDATE CASCADE
ON DELETE CASCADE
SQL
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@mz026
mz026 / city.rb
Last active December 28, 2015 02:29 — forked from sumskyi/README.md
class City < GeoEntity
end
RSpec::Matchers.define :has_the_same_format_as do |expected|
result = nil
match do |actual|
police = HashPolice::Police.new(expected)
result = police.check(actual)
result.passed?
end
failure_message_for_should do |actual|

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
environments = [ "development", "test" ]
namespace :shot do
namespace :migrate do
def migrate_task name
Rake::Task.tasks.find do |t|
t.name == name.gsub("shot", "db")
end
end
module Timestamp
def self.included(mod)
def mod.timestamp instance_method_name
alias_name = "_#{instance_method_name}"
alias_method(alias_name, instance_method_name) if instance_methods.include?(instance_method_name)
define_method(instance_method_name) do |*arg|
if respond_to?(alias_name, *arg)
@import "compass/utilities/sprites/base";
// General Sprite Defaults
// You can override them before you import this file.
$icon-sprite-base-class: ".icon-sprite" !default;
$icon-sprite-dimensions: false !default;
$icon-position: 0% !default;
$icon-spacing: 0 !default;
$icon-repeat: no-repeat !default;
@mz026
mz026 / mock_active_record.rb
Created April 20, 2014 05:51
RSpec mock_active_reocord
# inspired by https://envygeeks.com/blog/mocking-activerecord-to-test-concerns
module RSpec
module Helpers
module ActiveRecordMocks
def mock_active_record(name, &block)
create_temp_table(name, &block)
Object.const_set("#{name}".camelize, Class.new(ActiveRecord::Base)).class_eval do
self.table_name = "__#{name}_table"
end