This file contains 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.application.config.assets.precompile += %w( ratchicons.eot | |
ratchicons.woff | |
ratchicons.ttf | |
ratchicons.svg ) |
This file contains 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
# 不考慮重複 key 和無 value 的情況 | |
parseQS = (qs = location.search) -> | |
object = {} | |
pairs = qs.substring(1) # 去除前置 ? 字元 | |
.split('&') # 變成一堆 oo=xx 字串 | |
for pair in pairs | |
[key, value] = pair.split('=') | |
object[key] = value |
This file contains 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
gem 'thin' | |
gem 'sinatra', :require => 'sinatra/base' | |
gem 'async_sinatra', :require => 'sinatra/async' | |
group :development, :test do | |
gem 'rspec-rails' | |
end |
This file contains 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
require 'date' | |
class Date | |
def programmers_day? | |
self.yday == 0x100 | |
end | |
end | |
Date.today.programmers_day? # => true if today is 9/14 |
This file contains 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 X | |
module Y | |
end | |
end | |
module X | |
module Z | |
Y # = X::Y | |
end | |
end |
This file contains 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
RSpec::Matchers.define :be_json do |expected| | |
match do |actual| | |
acturl_json = | |
ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(actual)) | |
expected_json = | |
ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(expected)) | |
acturl_json == expected_json | |
end | |
diffable |
This file contains 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
require 'rest-core/middleware' | |
require 'net/http' | |
class RestCore::NetHttp | |
include RestCore::Middleware | |
def call env | |
uri = URI.parse(request_uri(env)) | |
payload = ::RestClient::Payload.generate(env[REQUEST_PAYLOAD]) | |
client = Net::HTTP.new(uri.host, uri.port) |
This file contains 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
class JsonColumn | |
def self.default_with(&block) | |
new(block) | |
end | |
def initialize(default) | |
@default = default | |
end | |
def dump(obj) |
This file contains 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
# client usage | |
client.resources('/articles').post # => POST /articles | |
client.articles.post # => POST /articles | |
client.article(1).get # => GET /articles/1 | |
client.article(1).comments.get # => GET /articles/1/comments | |
client.admin # => client with admin support (for example, use http basic auth middleware) | |
client.admin.articles.get # => GET /admin/articles with http basic auth | |
# client define |
This file contains 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
class PostsController | |
before_filter :load_user | |
before_filter :load_post | |
def show | |
respond_with(@post) | |
end | |
def load_user | |
@user = User.find(params[:user_id]) |
OlderNewer