Skip to content

Instantly share code, notes, and snippets.

@deeeki
deeeki / positionpaper.textile
Created April 17, 2011 03:49
Rails勉強会@東京用
@deeeki
deeeki / oneliners.sh
Last active September 26, 2015 09:08
One-liners
#create ctags file
ctags -f tags --totals -R `pwd`
#grep under spaced filename
find . -print0 | xargs -0 grep searchword
#show hidden files on Mac. via: http://d.hatena.ne.jp/shunsuk/20090714/1247567640
defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder
#hide hidden files on Mac
defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder
#urlencode
echo '' | nkf -MQ | tr = %
@deeeki
deeeki / Gemfile
Created September 9, 2011 16:38
Ameblo images downloader
source "http://rubygems.org"
gem 'mechanize'
@deeeki
deeeki / gist:1376304
Created November 18, 2011 12:16
細かすぎて伝わらないRails

※主観的かつ個人的な試行錯誤の備忘録です

Coding Style

クラスマクロの順序

  • Model
  • associations
  • attr_accessors
  • scopes
  • validations
@deeeki
deeeki / wp_static_method_hook.php
Created December 11, 2011 08:23
クラスメソッドでフック
class wp_atnd_widget extends WP_Widget {
//クラスメソッド
static public function register() {
register_widget('wp_atnd_widget');
}
//...
}
//クラスメソッドでフック
add_action('widgets_init', array('wp_atnd_widget', 'register'));
@deeeki
deeeki / output.sh
Created December 14, 2011 07:04
rails_best_practices (1.6.0) error
/Users/deeeki/dev/src/myapp/vendor/bundle/ruby/1.9.1/gems/rails_best_practices-1.6.0/lib/rails_best_practices/core/routes.rb:27:in `controller_name_with_namespaces': undefined method `camelize' for nil:NilClass (NoMethodError)
from /Users/deeeki/dev/src/myapp/vendor/bundle/ruby/1.9.1/gems/rails_best_practices-1.6.0/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb:82:in `block in after_review'
from /Users/deeeki/dev/src/myapp/vendor/bundle/ruby/1.9.1/gems/rails_best_practices-1.6.0/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb:80:in `each'
from /Users/deeeki/dev/src/myapp/vendor/bundle/ruby/1.9.1/gems/rails_best_practices-1.6.0/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb:80:in `after_review'
from /Users/deeeki/dev/src/myapp/vendor/bundle/ruby/1.9.1/gems/rails_best_practices-1.6.0/lib/rails_best_practices/core/check.rb:224:in `block (2 levels) in included'
from /Users/deeeki/dev/src/myapp/vendor/bundle/ruby
@deeeki
deeeki / hituji.rb
Created March 9, 2012 18:57
hituji_tokyo_emptyrooms
require 'mechanize'
SITE_URL = 'http://www.hituji.jp'
INFO_URL = "#{SITE_URL}/comret/info"
a = Mechanize.new
links = a.get(INFO_URL).search('.searchAreaElement').at('td').search('a').map do |city|
city['href']
end
@deeeki
deeeki / tokyosharehouse_emptyrooms.rb
Created March 10, 2012 05:59
tokyosharehouse_emptyrooms
# coding: utf-8
require 'mechanize'
SITE_URL = 'http://tokyosharehouse.com'
AREA_URL = "#{SITE_URL}/jpn/houses/area"
a = Mechanize.new
rows = [%w(name area status price line access cond comment url).join(',')]
catch(:break) do
a.get(AREA_URL)
@deeeki
deeeki / memo.md
Created July 22, 2012 13:51
RailsにおけるRESTfulなURL設計勉強会
  • legacy wild controller route ':controller(/:action(/:id))(.:format)' は使わない派

  • 利用するURLを明示しておきたい

  • named_route使えないとリンクの記述が冗長になるのでは

  • namespaceなど少し複雑なことをやろうとすると何かしらルーティングを書くことになり、統一感がなくなる

  • 確認画面

    • confirmアクションの追加
      • 各アクションがすっきりする
      • 新規と編集で挙動が変わる場合 (edit_confirmアクション?)
  • パラメータ(mode=confirm)またはモデルの確認用プロパティ(http://bit.ly/mRQ8I5)