Skip to content

Instantly share code, notes, and snippets.

View satococoa's full-sized avatar

Satoshi Ebisawa satococoa

View GitHub Profile
@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 / 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
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 / 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
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(
# $ brew install reattach-to-user-namespace してから
set-option -g default-command "reattach-to-user-namespace -l zsh"
@satococoa
satococoa / monit.conf
Created October 23, 2012 03:19
Google Appsのメールサーバをmonitのアラート送信に使う
set mailserver smtp.gmail.com port 587
username "user@example.com" password "password"
using tlsv1
with timeout 30 seconds
@satococoa
satococoa / app_delegate.rb
Created October 30, 2012 05:19
crash when deployment_target='5.1' or '5.0'
class MyViewController < UIViewController
def viewDidLoad
super
view.backgroundColor = UIColor.whiteColor
end
def viewDidAppear(animated)
super
if TWTweetComposeViewController.canSendTweet
tw = TWTweetComposeViewController.new.tap do |c|
@satococoa
satococoa / migrate_one_to_two.rb
Created November 21, 2012 01:45
RubyMotion でシンプルな CoreData のマイグレーションを行うコード
module MigrateOneToTwo
module_function
def store_path
File.join(App.documents_path, 'store.sqlite')
end
def tmp_store_path
File.join(App.documents_path, 'store_tmp.sqlite')
end
@satococoa
satococoa / development.rb
Last active December 10, 2015 03:58
Rails.logger カスタマイズ
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(config.paths['log'].first))
config.logger.formatter = lambda {|severity, datetime, progname, msg|
"%s, [%s #%d], %5s -- %s\n" % [severity[0..0], datetime.strftime('%Y-%m-%d %H:%M:%S')+('.%06d' % datetime.usec), $$, severity, msg]
}
config.logger.level = Logger::DEBUG