Skip to content

Instantly share code, notes, and snippets.

@Haroperi
Haroperi / gist:3436d0b4ad1a52b2c945
Created June 21, 2015 19:40
mecabでkyteaらしい出力を行う
mecab --node-format="%m/%h/%f[7] " --unk-format="%M" --eos-format="\n" --eon-format=' ' | sed -e 's/ $//'
@Haroperi
Haroperi / 2014-09-24
Last active August 29, 2015 14:06
Diary
SB棟の低層区の市民はエレベータの下のボタンを押しつつも、エレベータが高層区の乗降でしばらく下に来ないと分かるやいなや、階段で一階まで降りる。その結果高層区からエレベータで降りてくる市民は、乗客いない階で足止めを食らう。高層区の市民は自分より下の階にエレベータは不要であると思っているし、また、全ての市民は自分より上の階は崩れればいいと思っている。このような憎しみ合いの結果、だるま落としの上手い巨人でも現れない限り、SB棟は最上階から順に徐々に崩れ、いずれはSB棟を平屋建てにするだろう。
@Haroperi
Haroperi / lasso regression
Created September 5, 2014 06:12
minimal example of lars-lasso regression
require(lars)
y <- iris[,1]
x <- iris[,2:4]
x <- as.matrix(x)
result <- lars(x=x, y=y, type="lasso")
coefs <- predict.lars(result, x, type='coefficients')
print(coefs)
[~/work/now/mlr/third_party/dtm_release/dtm]$ gdb main haro@harombp 2013/09/27 10:19:13
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ..... done
(gdb) run
@Haroperi
Haroperi / slidepuzzle.pl
Last active December 22, 2015 03:59
list rules for slide puzzle written in Prolog
% スライドパズルの移動のルール
move_one([0,B,C,D,E,F,G,H,I], [B,0,C,D,E,F,G,H,I]).
move_one([A,0,C,D,E,F,G,H,I], [0,A,C,D,E,F,G,H,I]).
move_one([0,B,C,D,E,F,G,H,I], [D,B,C,0,E,F,G,H,I]).
move_one([A,B,C,0,E,F,G,H,I], [0,B,C,A,E,F,G,H,I]).
move_one([A,0,C,D,E,F,G,H,I], [A,C,0,D,E,F,G,H,I]).
move_one([A,B,0,D,E,F,G,H,I], [A,0,B,D,E,F,G,H,I]).
move_one([A,0,C,D,E,F,G,H,I], [A,E,C,D,0,F,G,H,I]).
move_one([A,B,C,D,0,F,G,H,I], [A,0,C,D,B,F,G,H,I]).
@Haroperi
Haroperi / fdtd.rb
Last active December 14, 2015 12:49
FDTD algorithm in Ruby
include Math
require 'pp'
X = 10
T = 4
PI = 3.14
dt = 1
dx = 1
@Haroperi
Haroperi / komachi.pl
Last active December 13, 2015 20:09
Komachi calculation
% komachi
digit(X) :- member(X, [0,1,2,3,4,5,6,7,8,9]).
is_composed_of(N, X, Y) :-
digit(X),
digit(Y),
(Z is X+Y;
Z is X-Y;
Z is Y-X;
@Haroperi
Haroperi / gist:3721290
Created September 14, 2012 10:56
convert from space separated to matrix (wolfram alpha format)
l = gets
num_list = l.split(/\s/)
n = Math.sqrt(num_list.size).to_i
print '{'
n.times {
print '{'
(n-1).times {
print "%s, " % num_list.shift
}
@Haroperi
Haroperi / gist:3661820
Created September 7, 2012 00:22
most long repeat
l = gets
l.chomp!
while /^(.+)\1+/ =~ l
l = $1
end
puts l
@Haroperi
Haroperi / gist:3024941
Created June 30, 2012 18:25
動的言語でファイルのcloseをデストラクタにまかせる場合のちょっとした落とし穴
# generate a file (1000 lines)
def make_1000lines
f = open("hoge", 'w')
1000.times do |i|
f.puts i.to_s * 100
end
end
make_1000lines()
puts `wc -l hoge` # 989 is printed in my environment.