Skip to content

Instantly share code, notes, and snippets.

@tigawa
tigawa / gist:6010234
Last active December 19, 2015 19:59
JavaSE7 switch文
public class Switch {
public static void main(String[] args) {
switch ("a") {
case "a":
System.out.println("A");
break;
case "b":
System.out.println("B");
break;
@tigawa
tigawa / cancat_adapter.rb
Created May 27, 2013 16:07
文字列の連結をoracle,mysql,sqlite,sqlServerに対応させたコード config/initializers/配下に配備 【使用例】 scope :name_search, lambda{|name| where("#{connection.concat('last_name', 'first_name')} LIKE ?", "%#{name}%") } end
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
# Will return the given strings as a SQL concationation. By default
# uses the SQL-92 syntax:
#
# concat('foo', 'bar') -> "foo || bar"
def concat(*args)
args * " || "
@tigawa
tigawa / gist:5573080
Created May 14, 2013 02:00
推奨しないメソッドにアノテーションを付ける
/**
* <省略>
*
* @deprecated 推奨しない理由
* @see #method(Long, String) <- 代替メソッド
*/
@Deprecated
public void method()
@tigawa
tigawa / gist:5537212
Last active December 17, 2015 02:39
javascriptのクラス定義
/* 実装 */
var StringUtils = function() {}
StringUtils.prototype = {
replace : function(str,from,to) {
実装 ~省略~
}
};
/* 使い方 */
@tigawa
tigawa / gist:5376441
Last active December 16, 2015 04:19
windowsで繰り返しjavaプログラムを実行する方法
FOR /L %%i IN (0,1,200) DO echo %%i & java -cp %CLASSPATH% %EXEC_CLASS%
@tigawa
tigawa / gist:5279940
Created March 31, 2013 08:05
rails 画像アップロード
# コントローラ
class FooController < ApplicationController
def index
@items = Item.all
end
def new
@item = Item.new
end
@tigawa
tigawa / gist:5201346
Created March 20, 2013 00:19
これはMP3プレイヤーのProductのmaker名をレコード数の多い順に並べてその結果のハッシュのkeyであるmaker名を配列として取得しています。
Product.where(category: "MP3 Player").group(:maker).order('count_maker desc').count('maker').keys
@tigawa
tigawa / gist:5168119
Created March 15, 2013 07:36
jsonのeach
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
<input id="in1" type="text" value ="山田">
<div id="out" ></div>
@tigawa
tigawa / gist:5043111
Created February 26, 2013 22:51
ruby 2.0 keyword param
def count_word_from_file(path: "~/default.txt", word:"default")
file = File.read(path)
return file.split.select{|w| w==word}.size
end
@tigawa
tigawa / gist:5043102
Created February 26, 2013 22:50
ruby 2.0 lazy
require 'date'
def each_fridays
friday = Date.new(2013,1,4)
loop do
yield friday
friday += 7
end
end
fridays = enum_for(:each_fridays)