Skip to content

Instantly share code, notes, and snippets.

Avatar

Mitsunori Komatsu komamitsu

View GitHub Profile
@komamitsu
komamitsu / myecho.ml
Created Nov 13, 2011
a Lwt echo server for practice
View myecho.ml
(* ocamlfind c -w A -linkpkg -package lwt,lwt.unix,lwt.syntax -syntax camlp4o,lwt.syntax myecho.ml -o myecho *)
(* This code refers to https://github.com/avsm/ocaml-cohttpserver/blob/master/server/http_tcp_server.ml *)
open Lwt
let server_port = 12345
let so_timeout = Some 20
let backlog = 10
let try_close chan =
catch (fun () -> Lwt_io.close chan)
View gist:1528682
package com.komamitsu;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
View gist:1698799
let split_rev cut xs =
let (_, f, s) =
List.fold_left
(fun (i, f, s) x ->
if i < cut then (i + 1, x::f, s) else (i + 1, f, x::s))
(0, [], []) xs
in
(f, s)
let rec ms xs =
View gist:1760759
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 Feb 11, 2012
simple calc (LL parser)
View calc.rb
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 Feb 15, 2012
practice for using MeCab and Markov chain
View mecab_mc.rb
# Encoding: UTF-8
require 'MeCab'
mecab = MeCab::Tagger.new
node = mecab.parseToNode (ARGF.read)
x,y = nil,nil
acm = []
while node do
View AndroidManifext.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
@komamitsu
komamitsu / nqueen.ml
Created Apr 20, 2012
N Queen problem in OCaml
View nqueen.ml
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 Apr 25, 2012
decompiled Scala traits with javap
View gist:2485599
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 }
View Hoge.scala
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)
}
}