Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View komamitsu's full-sized avatar

Mitsunori Komatsu komamitsu

View GitHub Profile
@komamitsu
komamitsu / gist:1760759
Created February 7, 2012 17:05
Executors sample
package com.komamitsu;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class App {
private static class MyRunnable implements Runnable {
private int num = 0;
@Override
@komamitsu
komamitsu / calc.rb
Created February 11, 2012 14:11
simple calc (LL parser)
require 'strscan'
require 'test/unit'
class Calc
def run(str)
@scanner = StringScanner.new(str)
expr
end
def scan(re)
@komamitsu
komamitsu / mecab_mc.rb
Created February 15, 2012 14:29
practice for using MeCab and Markov chain
# Encoding: UTF-8
require 'MeCab'
mecab = MeCab::Tagger.new
node = mecab.parseToNode (ARGF.read)
x,y = nil,nil
acm = []
while node do
@komamitsu
komamitsu / nqueen.ml
Created April 20, 2012 15:59
N Queen problem in OCaml
let ($) f g = f g
let safe n q qs =
let (qx, qy) = q in
if List.exists begin
fun (x, y) -> qx = x || qy = y
end qs then false
else
let rec row_iter iy =
if iy >= n then true
@komamitsu
komamitsu / gist:2485599
Created April 25, 2012 02:24
decompiled Scala traits with javap
komamitsu@carrot ~/lab/scala/traitsample2 $ cat Hello.scala
trait T1 {
val age:Int
}
trait T2 {
def hello(name:String) = println("hello " + name)
}
class C extends T1 with T2 { val age = 42 }
class Hoge {
def fib(n: Int, i: Int, a: Int, b: Int) : Int = {
if (i >= n) b
else fib(n, i + 1, b, a + b)
}
def simple_tailrec(n: Int) : Int = {
if (n < 0) n else simple_tailrec(n - 1)
}
}
@komamitsu
komamitsu / HOge.scala
Created May 13, 2012 13:53
Trait as Stackable modifications
// Either is OK.
// abstract Base { def say(word: String) }
trait Base { def say(word: String) }
class Hoge extends Base { def say(word: String) = println(word) }
trait Smile extends Base { abstract override def say(word: String) = super.say(word + " :)") }
trait Hello extends Base { abstract override def say(word: String) = super.say("Hello " + word) }
@komamitsu
komamitsu / perm.ml
Created May 23, 2012 16:44
2 permutations in OCaml
let ($) f g = f g
let rec perm xs n l total =
if n <= 0 then l::total
else begin
List.flatten $
List.map (fun c -> perm xs (n - 1) (c::l) total) xs
end
let rec perm2 xs n =
@komamitsu
komamitsu / A.scala
Created June 2, 2012 09:54
[Scala] hashCode impl test
package com.komamitsu.hashcodetest
/**
* @author komamitsu
*/
case class Foo(id: Int)
case class Bar(id: Int)
class Hoge(foo: Foo, bar: Bar) {
override def hashCode : Int = foo.## + bar.##
}
  • fluentd#0
2015-10-11 23:35:00 +0900 counter.count: {"foodb.bartbl_count":262146,"foodb.bartbl_bytes":11010132,"foodb.bartbl_count_rate":262146.0,"foodb.bartbl_bytes_rate":11010132.0}
2015-10-11 23:35:01 +0900 counter.count: {"foodb.bartbl_count":174764,"foodb.bartbl_bytes":7340088,"foodb.bartbl_count_rate":174764.0,"foodb.bartbl_bytes_rate":7340088.0}
2015-10-11 23:35:02 +0900 counter.count: {"foodb.bartbl_count":262146,"foodb.bartbl_bytes":11010132,"foodb.bartbl_count_rate":262146.0,"foodb.bartbl_bytes_rate":11010132.0}
2015-10-11 23:35:03 +0900 counter.count: {"foodb.bartbl_count":349528,"foodb.bartbl_bytes":14680176,"foodb.bartbl_count_rate":349528.0,"foodb.bartbl_bytes_rate":14680176.0}
2015-10-11 23:35:04 +0900 counter.count: {"foodb.bartbl_count":174764,"foodb.bartbl_bytes":7340088,"foodb.bartbl_count_rate":174764.0,"foodb.bartbl_bytes_rate":7340088.0}
2015-10-11 23:35:05 +0900 counter.count: {"foodb.bartbl_count":87382,"foodb.bartbl_bytes":3670044,"foodb.bartbl_count_rate":87382.0,"foodb.bartbl_b