Skip to content

Instantly share code, notes, and snippets.

View mtsd's full-sized avatar

Kosuke Matsuda mtsd

  • Tokyo, Japan
View GitHub Profile
@mtsd
mtsd / deploy_plot.txt
Created February 13, 2011 13:25
start plot
$ git clone git://github.com/matsuda/plot.git myplot
$ cd myplot
$ heroku create
$ git push heroku master
$ heroku open
@mtsd
mtsd / unicade_encoding.rb
Created February 23, 2011 09:10
Rubyでの文字コードの扱い
=begin
チルダ問題
| \xE3\x80\x9C | 0x301c |
| \xEF\xBD\x9E | 0xff5e |
| \x7E | 0x7e |
| \xCB\x9C | 0x2dc |
| \xE2\x88\xBC | 0x223c |
@mtsd
mtsd / validations_step_fu.rb
Created March 22, 2011 06:31
execute validations step by step
module ActiveModel
module ValidationsStepFu
extend ActiveSupport::Concern
private
def validates_step_by(*attrs)
attrs = attrs.map(&:to_sym)
self.class.validators.each do |validator|
if (validator.attributes & attrs).present?
validator.validate(self)
@mtsd
mtsd / gist:882764
Created March 23, 2011 07:46
Rails3 utilityies
# -*- coding: utf-8 -*-
module I18n
class << self
#
# nilの場合は無視する
#
def localize_with_nil(object, options = {})
return if object.nil?
locale = options.delete(:locale) || config.locale
format = options.delete(:format) || :default
@mtsd
mtsd / gist:1161588
Last active September 26, 2015 21:27
Objective-CのUIView関連のスニペット
/*
UIWebViewのUserAgentを取得
*/
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *ua = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSLog(@"userAgent >>> %@", ua);
[webView release];
// ASIHTTPRequestにUserAgentを設定
// [ASIHTTPRequest setDefaultUserAgentString:ua];
@mtsd
mtsd / UIImage+Resize.h
Created August 22, 2011 03:25
画像のリサイズ
#import <Foundation/Foundation.h>
@interface UIImage (Resize)
- (CGFloat)aspectRatio:(CGSize)size;
- (CGSize)resizedSize:(CGSize)size;
- (UIImage *)resizedImage:(CGSize)size;
@end
@mtsd
mtsd / gist:1167423
Created August 24, 2011 06:31
可変テキストの文字列サイズ
/*
[self sizeOfText:text withFont:[UIFont systemFontOfSize:14] inWidth:200]
*/
- (CGSize)sizeOfText:(NSString *)text withFont:(UIFont *)font inWidth:(NSInteger)width
{
UITextView *t = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, width, 0)] autorelease];
t.font = font;
t.text = text;
[t sizeToFit];
return t.contentSize;
@mtsd
mtsd / gist:1280512
Created October 12, 2011 07:12
install Cocoa Emacs with Homebrew
$ brew install --cocoa emacs
==> Downloading http://ftpmirror.gnu.org/emacs/emacs-23.3a.tar.bz2
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching
@mtsd
mtsd / gist:1280514
Created October 12, 2011 07:12
install readline by Homebrew
$ brew install readline
==> Downloading http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file vi_mode.c
patching file callback.c
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.1 --mandir=/usr/local/Cellar/readline/6.2.1/share/man --infodir=/usr/local/Cellar/readline/6.2.1/share/info --enable-multibyte
==> make install
@mtsd
mtsd / gist:1280518
Created October 12, 2011 07:13
install and set up rbenv and ruby-build
########################################################################
# https://github.com/sstephenson/rbenv
########################################################################
$ brew install rbenv
==> Downloading https://github.com/sstephenson/rbenv/tarball/v0.2.1
######################################################################## 100.0%
/usr/local/Cellar/rbenv/0.2.1: 32 files, 156K, built in 2 seconds
$ brew install ruby-build