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 Array | |
def to_proc | |
m, args = self | |
lambda {|x| x.send(m.to_sym, *args) } | |
end | |
end | |
p [{:a => 1}].find(&[:key?, :a]) #=> {:a => 1} | |
p [{:a => 1}].find(&[:key?, :b]) #=> nil |
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
# XXX more specific name. | |
class Person < ActiveRecord::Base | |
exec_context :hoge, default: true do | |
validate :foo, presence: true | |
before_create :foobar | |
end | |
validate :bar, presence: true | |
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
#!/usr/bin/env ruby | |
remote = 'origin' | |
merged = Dir.glob("./.git/logs/refs/remotes/#{remote}/*").inject([]) do |merged, ref| | |
branch = File.basename(ref) | |
unmerged = `git log #{remote}/master..#{remote}/#{branch}` | |
unmerged.empty? ? merged << branch : merged | |
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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
require 'optparse' | |
$optval = {} | |
opt = OptionParser.new | |
opt.on('-a', '--attr=ATTR', 'display attribute value') {|v| $optval[:attr] = v } | |
opt.on('-i', '--inspect', 'output #inspect instead of #to_s') { $optval[:inspect] = true } |
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
--color | |
--profile | |
<%= begin; require 'ruby-debug'; Debugger::Command.settings[:autolist] = Debugger::Command.settings[:autoeval] = 1 ; '--debugger' ; rescue LoadError ; '' ; 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
# vim:set ft=zsh: | |
unlimit | |
limit core 0 | |
limit -s | |
umask 022 | |
HISTFILE=${HOME}/.zhistory | |
HISTSIZE=100000 | |
SAVEHIST=100000 |
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 61b68702748ff7da4fbc97a2bdf00c39a71e63ab Mon Sep 17 00:00:00 2001 | |
From: moro <[email protected]> | |
Date: Thu, 1 Oct 2009 20:58:39 +0900 | |
Subject: [PATCH] impl. rack middleware to block invalid chars. | |
block invalid chars, which is redundant UTF-8 chars for example, | |
to come into Rails app world. | |
--- | |
actionpack/lib/action_controller.rb | 1 + | |
.../lib/action_controller/invalid_char_blocker.rb | 49 +++++++++ |
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 'rack' | |
class App | |
def call(env) | |
to = Rack::Request.new(env).params["to"] || "World" | |
body = Rack::Utils.escape_html(to) | |
[200, {"Content-Type" => "text/html"}, [body]] | |
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
(function($){ | |
$('.pagination a[data-remote=true]').live('ajax:success', function(e){ window.history.pushState('', '', $(e.target).attr('href')) }) | |
$(window).bind('popstate', function(){ $.ajax({url:window.location, dataType:'script'}) ; return true }); | |
})(jQuery); |
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 Person < ActiveRecord::Base | |
def self.column_default_values(defs) | |
defs.each do |cname, value| | |
columns.detect{|c| c.name.to_sym == cname.to_sym }.instance_variable_set('@default', value) | |
end | |
end | |
column_default_values(name: 'hibariya') | |
end |