Skip to content

Instantly share code, notes, and snippets.

View tomoya55's full-sized avatar

Tom Hirano tomoya55

  • Osaka
View GitHub Profile
class Array
def move_to_last(val)
self.delete(val)
self.push(val)
end
end
class LRUCache
attr_reader :cache_size
require "lru_cache"
describe Array do
it "指定された値を末尾に移動させる" do
arr = [:a, :b, :c]
arr.move_to_last(:a)
arr.last.should eql :a
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
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
@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];
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
-module(recursion).
-export([bump/1, average/1, even_only/1]).
bump([]) ->
[];
bump([H|T]) ->
[H + 1 | bump(T)].
average(L) ->
sum(L) / length(L).