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
" ack | |
cnoremap %%% =expand("") | |
map s :Ack %%% |
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
#auth.rb | |
module Precious | |
class App < Sinatra::Base | |
use Rack::Auth::Basic, "Restricted Area" do |username, password| | |
[username, password] == ['admin', 'pass'] | |
Gollum::Wiki.default_committer_name = username | |
end | |
end | |
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
class Controller | |
[400, 401, 402, 403, 404].each do |code| | |
define_method("render_#{code}", lambda {|message = 'error'| puts message}) | |
end | |
end | |
controller = Controller.new | |
controller.render_400 | |
controller.render_400('new message') |
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
test | |
==== | |
* one | |
* two |
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
class ArgTest | |
def self.hoge(*args) | |
p args | |
end | |
end | |
ArgTest.hoge('a') #=> ["a"] | |
ArgTest.hoge('a', 'b') #=> ["a", "b"] | |
ArgTest.hoge('a', 'b', {'c' => 1}) #=> ["a", "b", {"c"=>1}] |
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
require 'active_support/all' | |
Date.today #=> Thu, 21 Jun 2012 | |
Date.today - 1.day #=> Wed, 20 Jun 2012 | |
Date.today - 2.week #=> Thu, 07 Jun 2012 |
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 = File.join Dir.getwd, 'config', 'environment.rb' | |
if File.exist?(rails) && ENV['SKIP_RAILS'].nil? | |
require rails | |
if Rails.version[0..0] == "2" | |
require 'console_app' | |
require 'console_with_helpers' | |
elsif Rails.version[0..0] == "3" | |
require 'rails/console/app' |
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
class Property < ActiveRecord::Base | |
has_attached_file :temp_photo | |
end | |
path = 'target_file_path' | |
attach_name = 'temp_photo' | |
obj = Property.find(id) | |
attach = Paperclip::Attachment.new(attach_name, obj, obj.class.attachment_definitions[attach_name.to_suym]) |
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
file = File.read(name) | |
first_line = File.open(name, &:readline) | |
File.open(name, 'w') do |f| | |
f.puts(insert_line) if first_line.chomp != insert_line.chomp | |
f.puts(file) | |
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
~ > mtr --report s3-ap-northeast-1.amazonaws.com ~ | |
HOST: Tokyoです Loss% Snt Last Avg Best Wrst StDev | |
1.|-- bbr.setup 0.0% 10 1.4 1.4 1.3 1.7 0.1 2.|-- tokyo10-n03.flets.2iij.ne 0.0% 10 5.0 4.7 3.7 5.9 0.7 3.|-- tokyo10-ntteast0.flets.2i 0.0% 10 4.8 45.3 3.6 90.4 41.9 | |
4.|-- tky001lip21.iij.net 0.0% 10 5.0 6.4 3.8 22.7 5.8 | |
5.|-- tky001bb10.iij.net 0.0% 10 15.6 5.4 3.8 15.6 3.6 | |
6.|-- tky008bf00.iij.net 0.0% 10 5.0 5.0 4.3 6.5 0.6 | |
7.|-- tky001ip58.iij.net 0.0% 10 55.0 10.0 4.2 55.0 15.8 | |
8.|-- 202.232.8.166 0.0% 10 4.1 4.9 4.1 7.1 0.8 | |
9.|-- ge-0-0-0-0.gw3.nrt5.asian 0.0% 10 5.1 6.0 4.9 13.6 2.6 |