Skip to content

Instantly share code, notes, and snippets.

View fukayatsu's full-sized avatar
🏠
Working from home

Atsuo Fukaya fukayatsu

🏠
Working from home
View GitHub Profile
@fukayatsu
fukayatsu / happy-new-year.rb
Created January 1, 2012 12:27
happy new year!
def A(o)
p "A "+o.s
end
class Happy
def initialize(s)
@s=s
end
def s
@fukayatsu
fukayatsu / Cakefile
Created February 12, 2012 17:11
srcディレクトリに変更があったらビルドして、成功したらテストする
fs = require 'fs'
{print} = require 'util'
{spawn} = require 'child_process'
build = (callback) ->
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
@fukayatsu
fukayatsu / Cakefile
Created March 20, 2012 04:26
テストケースやテスト対象に変更があったら自動的にビルドとテストが走るようにする。
###
前提:
必要なパッケージ
npm install -g coffee-script
npm install -g jasmine-node
ディレクトリ構成
/src #*.coffee
/lib #*.js
/spec #*.spec.coffee
###
@fukayatsu
fukayatsu / tree.spec.coffee
Created April 1, 2012 10:49
オブジェクトを階層化(?)する
describe 'tree', ->
describe 'キーにコロンを含まないとき', ->
it 'そのままのオブジェクトが返ってくること', ->
expect({'a': 1}).toEqual {a: 1}
expect({'a': 1,'b': 2}).toEqual {a:1, b:2}
describe 'キーがコロンでセパレートされているとき', ->
it '階層化されて返ってくること', ->
expect( tree {'a:b':1, 'c:d':2} ).toEqual {a:{b:1},c:{d:2}}
expect( tree {'a:b:c':1, 'a:b:d':2} ).toEqual {a:{b:{c:1, d:2}}}
@fukayatsu
fukayatsu / nico-rank-resort.user.js
Created April 15, 2012 18:42
ニコニコ動画の毎時総合で24時間以内のものを上位に持ってくるuser-script for chrome
// ==UserScript==
// @name nico-rank-resort
// @namespace nico-rank-resort
// @include http://www.nicovideo.jp/ranking/fav/hourly/all
// @author fukayatsu
// @description resort ranking of nico nico douga
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
@fukayatsu
fukayatsu / Calc.java
Created April 26, 2012 12:45
チャレンジプログラム4(jRuby)
package main.java;
import java.util.ArrayList;
import org.jruby.Ruby;
import org.jruby.RubyRuntimeAdapter;
import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.runtime.builtin.IRubyObject;
public class Calc {
@fukayatsu
fukayatsu / Calc.java
Created April 26, 2012 13:10
チャレンジプログラム4(JavaScript)
package main.java;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Calc {
public static void main(String[] args) throws ScriptException {
if (args.length == 1) {
@fukayatsu
fukayatsu / mysql-test.rb
Created May 17, 2012 05:28
MySQL接続サンプルのruby版
require 'mysql'
db = Mysql.connect('localhost', 'root', '', 'ca')
while(true) do
print "name(empty to exit) > "; name = gets.chomp
break if name == ''
print "password > "; password = gets.chomp
#prepared Statement
@fukayatsu
fukayatsu / PreparedStatement-ex.java
Created May 17, 2012 06:52
PreparedStatementを使う時の注意
//String sql = "SELECT * FROM user where name = '?'"; //エラー
String sql = "SELECT * FROM user where name = ?"; //OK
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, userName);
ResultSet rs = ps.executeQuery();
@fukayatsu
fukayatsu / redis.coffee
Created May 19, 2012 16:57
redis with coffee
redis = require 'redis'
rc = redis.createClient()
rc.on 'error', (err)->
console.log 'Error: ' + err
rc.set 'hoge', 'piyo', redis.print
rc.get 'hoge', redis.print