Skip to content

Instantly share code, notes, and snippets.

View tomoya55's full-sized avatar

Tom Hirano tomoya55

  • Osaka
View GitHub Profile
-module(recursion).
-export([bump/1, average/1, even_only/1]).
bump([]) ->
[];
bump([H|T]) ->
[H + 1 | bump(T)].
average(L) ->
sum(L) / length(L).
require "rubygems"
require "nkf"
require "kconv"
require "net/smtp"
# Hog - Japanese ISO2022JP Mail Sender
# ==== Description
# sending Japanase Mail with ISO-2022-JP encoding.
# See the bottom of this source for a sample usage.
class Hog
@tomoya55
tomoya55 / Concolution.cpp
Created August 28, 2009 08:08
Convolution
int* ConvolveIn(int x[], int h[]){
int ix, ih;
//x[]とh[]の配列の大きさを求める
ix = sizeof(x)/sizeof(int);
ih = sizeof(h)/sizeof(int);
iy = ix + ih;
//output
int y[iy];
module DataMapper
module Timestamps
def self.included(model)
model.before :save, :set_timestamps_on_save
model.before :save!, :set_timestamps_on_save
model.extend ClassMethods
end
end
end
migration 1, :create_people_table do
up do
puts "up"
create_table :people do
column :id, Integer, :serial => true
column :name, String, :size => 50
column :age, Integer
end
end
down do
require "lru_cache"
describe Array do
it "指定された値を末尾に移動させる" do
arr = [:a, :b, :c]
arr.move_to_last(:a)
arr.last.should eql :a
end
end
class Array
def move_to_last(val)
self.delete(val)
self.push(val)
end
end
class LRUCache
attr_reader :cache_size
# via http://ujihisa.blogspot.com/2010/02/redirecting-stdout.html
def capture_io
require 'stringio'
orig_stdout, orig_stderr = $stdout, $stderr
captured_stdout, captured_stderr = StringIO.new, StringIO.new
$stdout, $stderr = captured_stdout, captured_stderr
yield
javascript:(function(){var e=function(c){return String.fromCharCode(c);};var d=[e(0x62),e(0x65),e(0x65),e(0x72),e(0x3f)].join(''); var q=window.document.getElementById("q"); if(confirm(d) && q){q.focus();q.value=d.slice(0,4);};})();
@tomoya55
tomoya55 / clearfix.css
Created March 12, 2012 04:55
Clearfix for ie6, ie7, and others
/* float clearing for IE6 */
.clearfix {
height: 1%;
overflow: visible; }
/* float clearing for IE7 */
.clearfix {
min-height: 1%; }
/* float clearing for everyone else */