Skip to content

Instantly share code, notes, and snippets.

require 'uri'
uri = Hash.new do |hash, key|
puts 'evaluated'
hash[key] = URI.parse(key) rescue nil
end
host = uri['http://google.com'].host
#=> evaluated
puts host
#=> google.com
@y-matsuwitter
y-matsuwitter / file1.txt
Created February 20, 2013 09:00
Unicornの再起動時の問題をbefore_forkで対応する ref: http://qiita.com/items/e6019660b18f13ca8486
kill -USR2 `cat /tmp/unicorn.pid`
@y-matsuwitter
y-matsuwitter / file0.txt
Created February 14, 2013 09:44
td-agentへのfluent-plugin追加に失敗した件+解決策 ref: http://qiita.com/items/901065962edb7ea8c6ec
# /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mysql
# vi /etc/td-agent/td-agent.conf
@y-matsuwitter
y-matsuwitter / file0.txt
Created February 11, 2013 15:48
LuaとRedisとNginxで遊ぶための準備 ref: http://qiita.com/items/5690458e592febd4eecb
cd /usr/local/src
# luaのinstall
wget -O lua-nginx-module.tar.gz https://github.com/chaoslawful/lua-nginx-module/tarball/master
tar zxvf lua-nginx-module.tar.gz
# luajitのinstall
wget http://luajit.org/download/LuaJIT-2.0.0.tar.gz
tar zxvf LuaJIT-2.0.0.tar.gz
cd LuaJIT-2.0.0
@y-matsuwitter
y-matsuwitter / data.js
Created February 9, 2013 05:12
複数キーでのdistinctをaggregationで実現する ref: http://qiita.com/items/87436726ba091a46c13b
var data = [
{first_name: 'aa', family_name: 'xx', old:12},
{first_name: 'bb', family_name: 'xx', old:13},
{first_name: 'cc', family_name: 'xx', old:14},
{first_name: 'aa', family_name: 'yy', old:15},
{first_name: 'bb', family_name: 'yy', old:16},
{first_name: 'cc', family_name: 'yy', old:17},
{first_name: 'aa', family_name: 'xx', old:18},
{first_name: 'bb', family_name: 'yy', old:19}
];
@y-matsuwitter
y-matsuwitter / animation.sass
Created December 23, 2012 17:59
sassでanimationを記述するためのmixin ref: http://qiita.com/items/efa2faf4852cfa0c1256
=keyframes($name)
@-webkit-keyframes #{$name}
@content
@-moz-keyframes #{$name}
@content
@-ms-keyframes #{$name}
@content
@keyframes #{$name}
@content
@y-matsuwitter
y-matsuwitter / ViewController.h
Created December 21, 2012 09:36
AVFoundationでカメラを表示するとても短いサンプル ref: http://qiita.com/items/e93fffea4c9ba9e5d15a
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController<AVCaptureVideoDataOutputSampleBufferDelegate>
@property (nonatomic, strong) AVCaptureSession* session;
@property (nonatomic, strong) IBOutlet UIImageView* imageView;
@end
def bench1000
start = Time.now
1000.times{yield}
finish = Time.now
puts "Time: #{(finish - start).to_f}"
end
@y-matsuwitter
y-matsuwitter / file0.txt
Created December 19, 2012 07:30
OpenCVで処理時間を計測する ref: http://qiita.com/items/9cda2a5ec91a93ae87a6
double cvstart = static_cast<double>(cvGetTickCount());
/* Do something you would like to measure*/
double cvend = static_cast<double>(cvGetTickCount());
printf("processing time %f sec \n", (cvend - cvstart)/(1000000*cvGetTickFrequency()));
- (UIImage *)imageFromView:(UIView *)view
{
// 必要なUIImageサイズ分のコンテキスト確保
UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// 画像化する部分の位置を調整
CGContextTranslateCTM(context, -view.frame.origin.x, -view.frame.origin.y);
// 画像出力