Skip to content

Instantly share code, notes, and snippets.

@Epictetus
Epictetus / client.rb
Created May 11, 2012 11:40 — forked from jugyo/client.rb
remote console using druby
require 'drb'
require 'readline'
DRb.start_service
server = DRbObject.new_with_uri("druby://localhost:9898")
while buf = Readline.readline('> ', true)
buf = buf.strip
case buf
when 'exit'
@Epictetus
Epictetus / README.md
Created May 11, 2012 11:40 — forked from fujimura/README.md
heroku_config.rake

ローカルのomniauth.ymlにheroku用の設定を書いておいて、

$ rake heroku_config:upload

すればherokuに設定がコピーされます。

@Epictetus
Epictetus / Capfile
Created May 1, 2012 19:38 — forked from koseki/Capfile
Capistrano without Rails
# この行を追加。デフォルトだと-fでCapfileを指定したときにエラーになる。
Dir.chdir(File.dirname(__FILE__))
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
@Epictetus
Epictetus / readonly_console.rb
Created May 1, 2012 07:52 — forked from mirakui/readonly_console.rb
readonly rails console using Arproxy
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/console'
require APP_PATH
Rails.application.require_environment!
require "arproxy"
module Arproxy
class Readonly < Base
describe "GET current" do
before do
@request.cookies['hidden_notices'] = "1,#{notices(:permanent).id}"
get :current, :format => 'js'
end
it { should respond_with(:success) }
it { should set_cookie(:hidden_notices).to("#{notices(:permanent).id}") }
it { should render_template('notices/current') }
end
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
@Epictetus
Epictetus / heroku_unicorn_logger_fix.rb
Created April 26, 2012 01:43 — forked from jamiew/heroku_unicorn_logger_fix.rb
Fix Heroku cedar app logging with Rails 3.1 and Unicorn
# config/environments/production.rb
# We're on Heroku, just output straight to STDOUT
# This is required because we're using Unicorn: https://github.com/ryanb/cancan/issues/511#issuecomment-3643266
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'INFO')
@Epictetus
Epictetus / gist:2468735
Created April 23, 2012 03:53 — forked from shu0115/gist:2404897
nil? zero? blank? の動きの違い
[参考ページ]
blank? nil? zero?: Rails開発日記
- [ http://underrails.seesaa.net/article/135698039.html ]
---------
0.nil? #=> false
0.zero? #= true
0.empty? #=> NoMethodError
@Epictetus
Epictetus / gist:2468734
Created April 23, 2012 03:53 — forked from shu0115/gist:2404985
BigDecimal/to_d - float演算
◆例
[ 0.001 * 100 ] : 0.1
[ 0.58 * 100 ] : 57.99999999999999
[ 0.58.to_d * 100 ] : #<BigDecimal:1017f2f68,'0.58E2',9(36)>
[ 0.58.class.name ] : "Float"
[ 0.58.to_d.class.name ] : "BigDecimal"
[ (0.58.to_d * 100).to_i ] : 58
@Epictetus
Epictetus / gist:2468730
Created April 23, 2012 03:51 — forked from shu0115/gist:2468495
配列:アルファベット/数値/ひらがな/カタカナ/漢字
◆アルファベット
('a'..'z').to_a
# => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
('A'..'Z').to_a
# => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
◆数値
(1..20).to_a
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]