Skip to content

Instantly share code, notes, and snippets.

View holysugar's full-sized avatar

HORII Keima holysugar

  • Aiming, Inc
  • Tokyo
View GitHub Profile
@holysugar
holysugar / annotate_models.rake
Created August 26, 2011 14:18
auto annotate after db:migrate
# gem 'rake-hooks' # https://github.com/guillermo/rake-hooks
require 'rake/hooks'
after 'db:migrate' do
if Rails.env.development?
puts `annotate`
end
end
@holysugar
holysugar / prevent-wheel.js
Created October 5, 2011 08:36
prevent wheel events
// require jquery
jQuery(function(){
var WheelControl = {
_enabled: true,
enable: function(enabled) {
Aiming.WheelControl._enabled = enabled;
},
@holysugar
holysugar / gist:1294637
Created October 18, 2011 04:58
Ripper causes Encoding::CompatibilityError
# coding: utf-8
text = <<EOS
# coding: utf-8
'あ
あ'
EOS
require 'ripper'
Ripper.new(text).parse
@holysugar
holysugar / gist:1298406
Created October 19, 2011 14:15
order sample?
# "created_at/desc" とか書けるようにしていいなら(delimiter は相談.)
order_strings.map{|o|
name, order = o.split('/', 2)
column_names,
order = 'asc' if order != 'desc'
column_names.include?(name) ? "#{name} #{order}" : nil
@holysugar
holysugar / pre-commit
Created October 27, 2011 03:15
git pre-commit warning to trailing whitespaces
#!/bin/sh
function error() {
echo "'$1' has trailing spaces.\n" >&2
}
git diff --cached --name-only | (while read f; do
ERROR=0
if grep -n '[[:space:]]$' "$f" ; then
error $f
@holysugar
holysugar / rails.watchr
Created November 11, 2011 14:36
My watchr script for rails
# vim: ft=ruby fileencoding=utf-8
# --------------------------------------------------
# Notifier to screen
# --------------------------------------------------
def hardstatus
status = open("#{ENV['HOME']}/.screenrc"){|f| f.grep(/^hardstatus/)[-1] } || ""
status.chomp.rstrip
end
@holysugar
holysugar / rails3_acts_as_paranoid_example.rb
Created November 14, 2011 08:47
spec example for model which includes acts_as_paranoid
# for model which includes 'acts_as_paranoid'
# example (for User class):
# describe "acts_as_taggable" do
# let (:scope) { Question }
# it_behaves_like 'soft delete'
# it_behaves_like 'with_deleted scopes'
# end
shared_examples_for "soft delete" do
@holysugar
holysugar / gist:1366051
Created November 15, 2011 03:35
reading as binary
ruby-1.9.2-p290 :008 > bytes = open(filename, 'r:binary'){|f| f.read }; nil
=> nil
ruby-1.9.2-p290 :010 > bytes.encoding
=> #<Encoding:ASCII-8BIT>
@holysugar
holysugar / Action Mailer
Created January 27, 2012 01:53 — forked from fxn/Action Mailer
Ruby on Rails v3.2.1 CHANGELOGs (in ja-JP)
## Rails 3.2.1 (January 26, 2012) ##
* 変更なし
@holysugar
holysugar / ticketLink
Created February 16, 2012 13:26
Google SpreadSheets Auto Link Script