u16suzuの blog

日々学んだことのメモブログです。

2013-01-01から1年間の記事一覧

How to write with Markdown

title # large(one sharp) ## medium(two sharp) ### small(three sharp) link This is [link to google](http://google.com/) <http://google.com/> quotation > This is a kind of quotation. emphasis *italic* **bold** ***bold and italic*** list 1. hoge 1. aaa 2. fff 3.</http://google.com/>…

crontab

# +------------ 分 (0 - 59) # | +---------- 時 (0 - 23) # | | +-------- 日 (1 - 31) # | | | +------ 月 (1 - 12) # | | | | +---- 曜日 (0 - 6) (日曜日=0) # | | | | | # * * * * * 実行されるコマンド

後ろから4つとって、作成日を今日から1日ずつずらす。

後ろから4つとって、作成日を今日から1日ずつずらす。 >> Post.last(4).each_with_index{|p, index| p.created_at = index.days.ago; p.save }

UIViewを角丸にする

これだけでかっこ良さ3割増し。 #import <QuartzCore/QuartzCore.h> view.layer.cornerRadius = 5; view.layer.masksToBounds = YES;</quartzcore/quartzcore.h>

like search

1.9.1 :052 > Post.where('name like "%hoge%"') こっちでもよい 1.9.1 :008 > User.where('user_name like ?', "%hoge%" )

Hatena blog mark down での Objective-C シンタックスハイライトの方法

it's not Objective-C, but objc.

JSFlatButtonの使い方

JSFlatButtonという大好きなObjective-C のライブラリがありまして、それの使い方です。 // ボタン JSFlatButton *button = [[JSFlatButton alloc]initWithFrame:CGRectMake(0, 100, 320, 50)]; button.buttonBackgroundColor = [UIColor colorWithRed:0.74f…

rails runner で条件分岐

rails runner (one liner) で無理やり条件分岐 spring rails runner "if true; p 'true'; else; p 'false' end;" セミコロンをつけていくだけだが、なかなか苦しい。(汗 ruby script の場合は -e が必要 ruby -e " if true; p 4; else; p 3 end;"

MySQLのコマンドメモ

最新のslow queryを10件表示 結構時間かかる。 mysql > use mysql; mysql > SELECT * FROM slow_log ORDER BY start_time DESC LIMIT 10 ¥G; indexを確認 mysql> show index from users; explain mysql> explain select * from users limit 1 \G; select 結…

ボタンに影をつける

button の layerに setShadow系のメソッドを呼べば良い。 - (void)addShadow:(UIButton*)button { [button.layer setShadowColor:[[UIColor blackColor] CGColor]]; [button.layer setShadowOffset:CGSizeMake(0, 3)]; [button.layer setShadowOpacity:0.925…

MySQL show table status でテーブルごとの使用ディスクサイズを確認する

show table status でテーブルごとの使用ディスクサイズを確認できる。 mysql> show table status like 'users'\G;データベース内の全テーブルの Data Length , Data Freeを取得する mysql> SELECT TABLE_SCHEMA,TABLE_NAME,DATA_LENGTH, DATA_FREE FROM INF…

ActiveRecord snipets

# user_id 10000から20000 で、 photo が nullでない UserImageを検索 UserImage.where("photo is not null").where( :user_id => 10000..20000).first 100# OR search User.where("chat_id = ? or chat_id =?", "smith", "john")# And search User.where("c…

指定したマイグレーションのみ実行

指定したマイグレーションのみ実行 & 戻す これらの実行は、DBのマイグレーションのバージョン管理テーブルに記録されない。 db:migrateの代わりにはならないので注意。開発中に使うと便利な感じ。 $ rake db:migrate:up VERSION=200806010112 $ rake db:mig…

ローカルにないブランチを持ってくる

ローカルにないリモートのブランチをもってくる。 $git fetch --all $git checkout -b b_name origin/b_nameorigin のbranch を元に、ローカルに同じ名前のbranch を作っている。

read_attribute and write_attribute can use both symbol and string as arguments.

In ruby on rails read_attribute and write_attribute can use both symbol and string as arguments.If you use attributes method you can use only string as argument.via: http://blog.eiel.info/blog/2012/12/17/read-attribute-activerecord/

Ruby useful methods; Object#try and Object#presence

Object#try user ? user.name : 'no user'it can be convert to user.try(:name) || 'no user'Object#presence name = params[:name] ? params[:name] : 'no name'it can be convert to name = params[:name].presence || 'no name'

amazon ELB distribute traffic via instance's availability zone.

amazon ELB distribute traffic via instance's availability zone.The message is shown at AWS. Note: You do not have an equal number of instances in each availability zone. We recommend having the same number of instances in each availability…

Testflightで使用しているプロビジョニングを更新する

透明なモーダルビューを自作する

こんな感じ。MyViewControllerは表示したいものを指定。windowに addSubviewする。 MyViewController *vc = [[MyViewController alloc]init]; AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [delegate.window addSub…

ブロック変数を定義する

NSString* (^test)(NSString*, NSString*) = ^(NSString* head, NSString* tail){ return [NSString stringWithFormat:@"%@%@", head, tail]; }; NSLog(@"%@", test(@"hoge", @"fuga"));

Sending 'void' to parameter of incompatible type 'void (^)()'

Sending 'void' to parameter of incompatible type 'void (^)()'引数を取らないブロックをとるメソッドに対して、引数を持つブロックを引数として与えたら発生した。

Ruby のArrayの要素を入れたり取り出したりするメソッドについて

This is memorandum about Ruby's Array class' instance methods. Take some notes for my understand. I still haven' store them.Manipulate to tail push: add to tail pop: remove from tail Manipulate to head unshift: add to head shift: remove fr…

古いメソッドという意味の単語3つ

Open source なライブラリや、そうでないライブラリなどでよく使われる言葉。以下の3つは古いメソッドで、新しい別のメソッドがあるのでそちらを使うべきという意味でIT系では使われる。 IT用語で普通に辞典で調べても、非難するとか反対するという意味しか…

cannot load such file — mysql2/mysql2 というエラーが発生した。

原因は .bundle/configに書いてあるパスと 実際に gem が入っている場所が異なっていたためだった。はじめはbundle install --path vendor/でgemを入れていた。しかし .bundle/config にはvendor/bundle と書かれていた。bundle install --path vendor/bundl…

First Responder を取得する

First Responder とはフォーカスが当たっているUIViewのこと。 キーボード入力などの 画面タップ以外の イベントを受け取る UIViewになる。 UIWindow *window = [[UIApplication sharedApplication] keyWindow]; UIView * firstResponder = [window performS…

Rails4でwebrick が起動しない場合

rails server コマンドを実行すると rails newコマンドが実行されてしまい、サーバが起動できなかった。 この場合 以下のコマンドを実行すれば良い。 rake rails:update:binrails の bin の場所が変わったことが原因。参考: http://stackoverflow.com/questi…

attempt to insert nil object

NSArray に initialize してないオブジェクトを入れると落ちる。コード例 NSString *hoge ; @[@2, @3, hoge];コード例で発生するエラーメッセージ 2013-03-29 13:31:15.396 classSpike[22240:303] *** Terminating app due to uncaught exception 'NSInvalid…

tmuxで カレント pane を新しい window で開く方法

tmux を使っていて、window をいくつかの paneに分割して作業しているとき、もっとひろい領域で編集したくなる事がたまにあります。そのような場合 $tmux break-pane を使うと解決できます。コマンドを叩くと、カレントpaneを新しいwindowを作ってそこに移動…

therubyracerとexecjsをインストールしたのに execjsがないというエラーが出る場合の解決方法

こんなエラー Could not find a JavaScript runtime . See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)node.js入れて, therubyracerと execjsをGemfileから消して bundle updateしたら治りまし…

聖剣伝説2のようなUIがカッコいいiPhoneゲームiPokeMon

iPokeMonはGPS情報を利用したポケットモンスターのようなゲームで、実際の町、国で異なるポケモンが出現し、捕まえることができる。このゲームは 去年 Kjuly さんが大学の卒業プロジェクトとして開発し、実際にアップルに申請した。 しかし、コピーライトの…