Skip to content

Instantly share code, notes, and snippets.

@iwazer
iwazer / gist:902953
Created April 5, 2011 03:06
resize image
UIImage *img = [[UIImage imageNamed:@"image.png"] _imageScaledToSize:CGSizeMake(32.0f, 32.0f) interpolationQuality:1];
@iwazer
iwazer / variadic-script.scala
Created May 11, 2011 00:37
可変長引数の渡し方
def a(ss: String*) = ss.toList.foreach(println(_))
// Error!!
// def b(ss: String*) = a(ss)
// Success
def b(ss: String*) = a(ss:_*)
@iwazer
iwazer / gist:980101
Created May 19, 2011 02:53
Rubyで名前、値のペアで格納されている配列をハッシュに変換する
a = ["foo", 1, "bar", 2, "hoge", 100]
h = Hash[*a] # {"hoge"=>100, "foo"=>1, "bar"=>2}
@iwazer
iwazer / gist:982162
Created May 20, 2011 01:21
JavaでBasic認証(ただしマルチスレッドなサーバでは使えない…)
import java.net.Authenticator;
import java.net.PasswordAuthentication;
// Basic認証のAuthenticatorを作成
class HttpAuthenticator extends Authenticator {
public String username;
public String password;
public HttpAuthenticator(String username, String password) {
this.username = username;
this.password = password;
@iwazer
iwazer / gist:994513
Created May 27, 2011 02:07
Solrを検索した結果をMongoDBに入れる(RSolr、MongoMapperを利用)
# MongoDBに格納するためのModelクラス
class PEntry
include MongoMapper::Document
end
@iwazer
iwazer / gist:994722
Created May 27, 2011 05:55
Rubyで拡張子を指定して一時ファイルを生成する
require 'tempfile'
Dir.mkdir('tmp') unless FileTest.exist?('tmp')
tempfile = Tempfile.new(['xx', '.txt'], 'tmp')
puts tempfile.path
# => /Users/iwazawa/tmp/xx20110527-4157-1cev5di.txt
@iwazer
iwazer / gist:998385
Created May 30, 2011 02:38
PhantomJS用ターミナル出力のカラー表示
function terminalColor(msg, fg, bg, dc) {
if (!fg && !bg && !dc) return msg;
var m = {black:"0",red:"1",green:"2",yellow:"3",blue:"4",magenta:"5",cyan:"6",white:"7",
uline:"4",bold:"1"};
if (m[fg]) msg = "\u001b[3"+m[fg]+"m"+msg+"\u001b[39m";
if (m[bg]) msg = "\u001b[4"+m[bg]+"m"+msg+"\u001b[49m";
if (dc) {
var decos = dc.split(',');
for (var i=0; i<decos.length; i++) {
if (m[decos[i]]) msg = "\u001b["+m[decos[i]]+"m"+msg+"\u001b[0m";
@iwazer
iwazer / gist:1097047
Created July 21, 2011 11:55
Bashで固定数のループ
# 固定数のループ
for i in {1..100}; do
echo $i
done
@iwazer
iwazer / gist:1099257
Created July 22, 2011 11:09
SSLのエラーを無視しちゃう(だがしかし、こりゃ危険か…)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
@iwazer
iwazer / gist:1121960
Created August 3, 2011 05:19
Base of UnitFlatSpec ShouldMatchers BeforeAndAfterEach
import play._
import play.test._
import org.scalatest._
import org.scalatest.junit._
import org.scalatest.matchers._
class BasicTests extends UnitFlatSpec with ShouldMatchers with BeforeAndAfterEach {
override def beforeEach() {