This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails new project-name -d mysql -m https://raw.github.com/refinery/refinerycms/master/templates/refinery/edge.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake spiders:prices:update > log/update_prices_$(date +"%Y%m%d%H%M").log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((Date.today - 6.days)..Date.today).map{|date| date.strftime("%m-%d")} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails4 full page caching is removed and extracted as gem, details from Rails Guides: | |
# Rails 4.0 has removed Action and Page caching from Action Pack. | |
# You will need to add the actionpack-action_caching gem in order to use caches_action | |
# and the actionpack-page_caching to use caches_pages in your controllers. | |
gem 'actionpack-page_caching' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# suppose there are two directories named scss and css | |
sass -t compressed --watch scss:css |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://stackoverflow.com/a/23497743 | |
state_machine :state, initial: ->(t) { t.active? ? :seeking_flesh : :dormant } do | |
state :dormant, :seeking_flesh, :attacking # this must be present | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@user = User.first | |
@project = @user.projects.build(:name => "Make your bed") | |
# if you do @project.save here, as in the gist, | |
# association will not be saved, but if you do : | |
@user.save | |
# it will save the @user with its associated projects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Conditions | |
def self.included(base) | |
class << base | |
attr_reader :conditions_map | |
def condition(name, &block) | |
@conditions_map ||= Hash.new | |
@conditions_map.store(name, block) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Attention: the below methods are actions extracted from my controllers in a Rails App, if you need to use these codes outside | |
# a Rails project, rememeber to replace some Rails-specified methods, such as, Hash#to_param. | |
# STEP 1: start to request an authorization | |
def request_authorize | |
session[:security_state] = 'I am from Martin site' | |
authorize_url = "https://api.weibo.com/oauth2/authorize" | |
params = { | |
client_id: "663911642", # Required: Your assigned App Key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# state_machine: https://github.com/pluginaweek/state_machine | |
class Order < ActiveRecord::Base | |
state_machine :state, initial: :cart do | |
before_transition on: :checkout, do: :reduce_buyer_balance | |
after_transition on: :dispatch_goods, do: :create_shipping_log | |
after_transition on: :confirm, do: :charge_to_seller | |
event :checkout do | |
transition :cart => :paid |