Skip to content

Instantly share code, notes, and snippets.

View satococoa's full-sized avatar

Satoshi Ebisawa satococoa

View GitHub Profile
# $ brew install reattach-to-user-namespace してから
set-option -g default-command "reattach-to-user-namespace -l zsh"
class HogeSweeperObserver < ActionController::Caching::Sweeper
observe Hoge
def after_update(hoge)
expire_cache_for(hoge)
end
private
def expire_cache_for(hoge)
ActionController::Base.expire_page(
@satococoa
satococoa / selectable_image_view.rb
Created August 22, 2012 04:48
iPhone標準の写真アプリみたいに選択するとチェックマークが付くUIImageView
class SelectableImageView < UIImageView
include BW::KVO
attr_accessor :is_selected
def initWithFrame(rect)
super
@is_selected = false
observe(self, :is_selected) do |old_val, new_val|
if old_val != new_val
anim = CABasicAnimation.animationWithKeyPath('transform')
anim.fromValue = 0
anim.toValue = 2 * Math::PI
anim.valueFunction = CAValueFunction.functionWithName(KCAValueFunctionRotateZ)
anim.duration = 2
anim.repeatCount = Float::MAX
=begin
2012-08-16 15:01:39.964 ruby[37392:f0b] unrecognized runtime type `{_CMTime=qiIq}' (TypeError)
Can't compile stub for selector `setDuration:': unrecognized runtime type `{_CMTime=qiIq}' (TypeError)
@satococoa
satococoa / bg_image.rb
Created August 15, 2012 08:49
UIViewに背景画像を使用する
def loadView
self.view = UIView.new.tap do |v|
bg_image = UIImage.imageNamed('bg_black.png')
v.backgroundColor = UIColor.colorWithPatternImage(bg_image)
end
@satococoa
satococoa / ui_web_view.rb
Created July 25, 2012 05:39
UIWebView#scrollView
class UIWebView
alias_method :original_init, :init
def initWithScrollView
original_init
unless self.respond_to?(:scrollView)
def scrollView
self.subviews.each do |view|
return view if view.kind_of?(UIScrollView)
end
end
@satococoa
satococoa / resize.rb
Created July 25, 2012 02:51
ImageMagickで50%に画像を縮小(元ファイルはファイル名に@2xつけてコピー)
require 'pp'
require 'pathname'
input_dir = 'orig'
output_dir = 'out'
Pathname.glob("#{input_dir}/**/*.png").sort.each do |path|
dist = Pathname(path.to_s.gsub(input_dir, output_dir))
dist.dirname.mkpath unless dist.dirname.exist?
system('cp %s %s' % [path.to_s, dist.to_s.gsub('.png', '@2x.png')])
@satococoa
satococoa / app_delegate.rb
Created July 23, 2012 13:16
UIAlertView, UIActionSheet
class MyViewController < UIViewController
def viewDidLoad
super
view.backgroundColor = UIColor.whiteColor
button = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap do |b|
b.frame = [[30.0, 30.0], [200.0, 30.0]]
b.setTitle("Click", forState:UIControlStateNormal)
b.addTarget(self, action: 'open_action_sheet:', forControlEvents: UIControlEventTouchUpInside)
end
@satococoa
satococoa / gist:2978822
Created June 23, 2012 16:07
Preferences.sublime-settings
{
"font_face": "Ricty-Regular",
"font_size": 16.0,
"highlight_line": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"word_wrap": true
}
@satococoa
satococoa / config.rb
Created May 26, 2012 19:23
RubyMotion 1.6でdeployment_targetを4.3にしたときにcrashするのを修正
# ./lib/motion/project/config.rb
# RakefileからrequireすればOK
# そのうち直るとは思うけれどもとりあえず。。。
class Motion::Project::Config
def target(platform)
File.join(platform_dir(platform), 'Developer/SDKs',
platform + deployment_target + '.sdk')
end
def frameworks_dependencies