Skip to content

Instantly share code, notes, and snippets.

// java.util.List の初期化を一行で書く
List<String> list = new ArrayList<String>() {{add("a"); add("b"); add("c");}};
// 変更不可能な List で良い場合は
List list = Arrays.asList("a", "b", "c");
// Arrays.asList をジェネリックスを使って書くと
List<Integer> list = Arrays.<Integer>asList(1, 2, 3);
// asList を使いつつ、追加可能な List を作るには、冗長だが以下のようにする
List<Integer> list = new ArrayList<Integer>(Arrays.<Integer>asList(1, 2, 3));
require 'rubygems'
require 'cassandra'
include Cassandra::Constants
client = Cassandra.new('Keyspace1', '127.0.0.1:9160')
client.insert(:Standard1, 'bar', { 'name' => 'bar' } )
client.insert(:Standard1, 'bar', { 'age' => '99' } )
p client.get(:Standard1, 'bar')
require 'rubygems'
require 'cassandra'
include Cassandra::Constants
client = Cassandra.new('Keyspace1', '127.0.0.1:9160')
client.batch do
client.insert(:Standard1, '001', { 'first' => 'shin', 'last' => 'akiyama', 'age' => '31' })
client.insert(:Standard1, '002', { 'first' => 'foo', 'last' => 'bar', 'age' => '20' })
client.insert(:Standard1, '003', { 'first' => 'hoge', 'last' => 'fuga', 'age' => '15' })
require 'rubygems'
require 'cassandra'
include Cassandra::Constants
client = Cassandra.new('Keyspace1', '127.0.0.1:9160')
# SuperColumn として name を指定
client.insert(:Super1, 'foo', { 'name' => {'first' => 'bar', 'last' => 'baz'} } )
# SuperColumn はあってもなくても可
client.insert(:Super1, 'foo', { 'age' => '99' } )
@akishin
akishin / sync_sqldesigner_pos.rb
Created August 9, 2011 15:45
sync_sqldesigner_pos.rb
#!/usr/local/bin/ruby
#
# WWW SQL Designer を他の ER 図作成ツールと併用している場合に、
# 変更された DB から再インポートする度にテーブルの座標を直すのが面倒で作成したスクリプト。
# インポート後に実行すれば以前のバージョンで調整済みのダイアグラムの位置については同じになるので、
# 後は追加で変更した部分の座標のみ手で調整してやれば OK。
#
require 'rubygems'
@akishin
akishin / .irbrc
Created December 10, 2011 07:18
Windows用irbrc
require 'rubygems' rescue nil
require 'win32console'
require 'wirble'
require 'hirb'
# require 'hirb-unicode'
require 'pp'
require 'awesome_print'
# irb の設定
IRB.conf[:SAVE_HISTORY] = 100000
@akishin
akishin / setupvimplugin.sh
Created December 10, 2011 07:30
setupvimplugin.sh
#!/bin/sh
# backup file directory
if [ ! -d $HOME/tmp ]
then
echo "create directory $HOME/tmp"
mkdir $HOME/tmp
fi
# plugin directory
@akishin
akishin / .vimrc
Created December 16, 2011 08:14
.vimrc
" for vundle
if filereadable(expand("~/.vimrc.vundle"))
source ~/.vimrc.vundle
endif
" for neobundle
if filereadable(expand("~/.vimrc.neobundle"))
source ~/.vimrc.neobundle
endif
@akishin
akishin / tmail_19_patch.rb
Created February 8, 2012 04:18
Ruby 1.9 + tmail-1.2.7 環境での Encoding::CompatibilityError 対策用。
# encoding: utf-8
# Ruby 1.9 + tmail-1.2.7 環境での
#「Encoding::CompatibilityError (incompatible encoding regexp match (ASCII-8BIT regexp with ISO-2022-JP string))」
# エラー対策。
# Rails の場合 config/initializers 以下に配置する。
#
module TMail
class Encoder
def phrase( str )
str = normalize_encoding(str)
@akishin
akishin / .gvimrc
Created May 27, 2012 04:17
.gvimrc
" 縦幅
set lines=60
" 横幅
set columns=160
" クリップボード共有
set clipboard=unnamed
" ツールバーを削除