Skip to content

Instantly share code, notes, and snippets.

Tomohiro Matsuyama m2ym

Block or report user

Report or block m2ym

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@m2ym
m2ym / Main.scala
Last active Mar 3, 2016
Scala.js + Scalaz Concurrent Task
View Main.scala
import org.scalajs.dom
import dom.document
import scala.scalajs.js.JSApp
import scalaz.Nondeterminism
import scalaz.concurrent.Future
import scalaz.concurrent.Task
import scalaz.Free.Trampoline
import scalaz.\/._
import scala.collection.mutable.Queue
import scalaz._
@m2ym
m2ym / show.ml
Created Apr 8, 2015
Try to implement Haskell's show in OCaml using ppx_overload
View show.ml
module type Show = sig
val show : 'a -> string
end
module Show = struct
external show : 'a -> string = "%OVERLOADED"
module Int = struct
let show = string_of_int
end
@m2ym
m2ym / extract.ml
Created Jan 25, 2015
Extract webpage metadata in OCaml
View extract.ml
open Core.Std
let libguess_determine_encoding =
let open Ctypes in
Foreign.foreign "libguess_determine_encoding" (string @-> int @-> string @-> returning string)
type metadata = {
title : string option;
type_ : string option;
description : string option;
@m2ym
m2ym / guess.ml
Created Jan 24, 2015
libguess を ocaml-ctypes で使ってみる
View guess.ml
$ sudo apt-get install libguess-dev
$ ocamlfind ocamlc -package ctypes.foreign -linkpkg -custom -cclib -lguess -o guess guess.ml
$ ./guess "こんにちは世界"
UTF-8
$ ./guess $(echo "こんにちは世界" | nkf -Ws)
SJIS
$ ./guess $(echo "こんにちは世界" | nkf -We)
EUC-JP
View slow_recursive_query.sql
WITH RECURSIVE t AS (
SELECT source, target FROM edge
UNION
SELECT e.source, t.target FROM edge e INNER JOIN t ON e.target = t.source
)
SELECT target FROM t WHERE source = 123
@m2ym
m2ym / ppx_test_async.ml
Created Dec 16, 2014
ppx_test for Async
View ppx_test_async.ml
module Test = struct
include Ppx_test.Test
let eval = Async_unix.Thread_safe.block_on_async_exn
let test_unit loc name deferred =
test_unit loc name (fun () -> eval deferred)
let test loc name deferred =
test loc name (fun () -> eval deferred)
@m2ym
m2ym / ゆるふわJavaScriptプログラミング.ml
Created Oct 1, 2014
ゆるふわJavaScriptプログラミング in OCaml
View ゆるふわJavaScriptプログラミング.ml
open Easyjs
let () = begin%js
let foobar = {| jQuery("#foobar") |} in
let value = of_string "Hello, World!" in
let callback _ = {| ${foobar}.text(${value}) |} in
ignore {| window.setTimeout(${fn callback}, 1000) |}
end
@m2ym
m2ym / fun_of_modular_implicits.ml
Last active Aug 29, 2015
Fun of Modular Implicits
View fun_of_modular_implicits.ml
module type Show = sig
type t
val show : t -> string
end
let show (implicit S : Show) x = S.show x
module Show_instances = struct
implicit module Show_unit = struct
type t = unit
@m2ym
m2ym / async_pool.ml
Last active Aug 29, 2015
Simple resource pooling with Async
View async_pool.ml
open Core.Std
open Async.Std
type 'a t = {
capacity : int;
generate : unit -> 'a Deferred.t;
validate : 'a -> bool Deferred.t;
mutable in_use : int;
free : 'a Queue.t;
waiters : 'a Ivar.t Queue.t;
@m2ym
m2ym / PGOCaml_async.ml
Created Aug 15, 2014
PGOCaml with Async backend
View PGOCaml_async.ml
open Core.Std
open Async.Std
module type PGOCaml_async_thread =
PGOCaml_generic.THREAD
with type 'a t = 'a Deferred.t
module PGOCaml_async_thread : PGOCaml_async_thread = struct
type 'a t = 'a Deferred.t
You can’t perform that action at this time.