Skip to content

Instantly share code, notes, and snippets.

View hkoba's full-sized avatar

Kobayasi, Hiroaki hkoba

View GitHub Profile
@hkoba
hkoba / tcl_eval.ml
Created March 24, 2013 14:56
With this snippet, you can easily eval tcl script. Note: I'm very new to OCaml. Any suggestions are welcome.
#load "labltk.cma";;
(* You must call Tk.openTk somewhere before tcl_eval *)
let top = Tk.openTk ()
let rec tcl_eval_str str =
tcl_eval_list (Protocol.splitlist str)
and tcl_eval_list lst =
Protocol.tkEval (list2tkArgs lst)
and list2tkArgs lst =
@hkoba
hkoba / tktable.ml
Created March 28, 2013 00:25
How to use [tktable](http://tktable.sourceforge.net/tktable/doc/tkTable.html) from OCaml labltk. (Not yet typesafe)
#directory "+labltk";;
#load "labltk.cma";;
let top = Tk.openTk ()
let rec tcl_eval_str str =
tcl_eval_list (Protocol.splitlist str)
and tcl_eval_list lst =
Protocol.tkEval (list2tkArgs lst)
and list2tkArgs lst =
@hkoba
hkoba / sexparse1.ml
Last active April 23, 2018 02:59
Toy S-expression parser in OCaml with recursive descent parsing. Only supports symbol, integer and list. (This is just a partial port of brilliant awklisp: https://github.com/darius/awklisp/blob/master/awklisp )
module CharClass =
struct
let is_space c = c = ' ' || c = '\t'
let strrange str s e =
String.sub str s (e-s)
let strseek str start fn =
let pos = ref start
and end_ = String.length str in
@hkoba
hkoba / gist:5606543
Created May 19, 2013 03:23
Short prolog util to emit (only parameter part of) truth table. (See inline comments)
% -*- mode: prolog; coding: utf-8 -*-
% Simple util to make truth table.
% tested under gnu prolog and swi prolog.
% ?- consult('truthtable1.pl').
% | ?- tt([[y,n], [y,n]], writeln).
% [y,y]
% [n,y]
@hkoba
hkoba / gist:5705004
Last active December 18, 2015 01:39
This way, like user_dir, you can host per-user fastcgi apps. Note: fcgi.sock must be readable by nginx. Usually, install -d -g nginx -m 2775 var/tmp is enough (If your nginx runs in nginx group).
# nginx_public_apps.conf
# http://example.com/-$USER-$APP_NAME/
# => /home/$USER/public_apps/apps/$APP_NAME/app/var/tmp/fcgi.sock
# Serve static files directly, with gzip_static.
location ~ ^/-(?<user>\w+?)-(?<app_name>[^/]+)/(?<static_fn>.*?\.(html|css|js|gif|jpg|png|ico|mp4|webm))$ {
set $app_root /home/$user/public_apps/apps/$app_name/app;
root $app_root/html;
try_files /$static_fn =404;
@hkoba
hkoba / op_default.ml
Last active January 3, 2016 02:09
Perl's '//' operator in OCaml, but this is type-safe.
let (//) optional default =
match optional with
| None -> default
| Some x -> x
(* You can use this like:
(Map.find t s // 0) + 1
*)
@hkoba
hkoba / rwo_nestedmod_ng.ml
Created January 15, 2014 04:04
Mysterious "open Core.Std" effect. (taken from Real World OCaml PDF edition, with mod) I want to know what is done under the hood.
(* open Core.Std
When I opened Core.Std here, no problem occured. But...
*)
module type ID = sig
type t
val of_string : string -> t
val to_string : t -> string
end
@hkoba
hkoba / redis.magic
Last active January 4, 2016 05:29
file(1) magic for Redis database file.
# file(1) magic for Redis database file. See https://github.com/sripathikrishnan/redis-rdb-tools/wiki/Redis-RDB-Dump-File-Format
0 string REDIS Redis database file,
>5 regex [0-9][0-9][0-9][0-9] version %s,
>9 string \xfe db number
>>10 byte x %d
@hkoba
hkoba / dryrun_skel.zsh
Created January 25, 2014 09:44
My Zsh idiom. How to write dryrun behavior in Zsh.
#!/bin/zsh
option_defs+=(
n=o_dryrun
s=o_silent
)
function DO {
if (($#o_dryrun || ! $#o_silent)); then
print -- $argv
fi
@hkoba
hkoba / ltsv2sql.pl
Last active August 29, 2015 13:56
LTSV to SQL(ite) converter
#!/usr/bin/env perl
use strict;
use warnings FATAL => qw/all/;
#========================================
use fields qw/o_table
o_create
o_transaction
columns