Skip to content

Instantly share code, notes, and snippets.

View takahisa's full-sized avatar

Takahisa Watanabe takahisa

  • Cybozu, Inc
  • Tokyo, Japan
View GitHub Profile
@takahisa
takahisa / path.sh
Created September 11, 2023 09:26
abspath ⇔ relpath (bash)
function abspath() {
if [[ ! -r "${1}" ]]; then
echo >&2 "No such file or directory: $1"
return 1
fi
if [[ -d "${1}" ]]; then
echo "$(cd "${1}" || return 1; pwd)"
else
echo "$(cd "$(dirname "${1}")" || return 1; pwd)/$(basename "${1}")"
@takahisa
takahisa / Makefile
Last active March 4, 2022 15:04
dotfilesをコピーするMakefile
EXCLUDE_PATTERNS := Makefile
SOURCES := $(filter-out $(EXCLUDE_PATTERNS), $(shell git ls-files))
TARGETS := $(addprefix $(HOME)/, $(SOURCES))
$(TARGETS): $(HOME)/% : $(PWD)/%
@cp $< $@
all: $(TARGETS)
@takahisa
takahisa / Vagrantfile_bad.rb
Created October 25, 2021 14:55
Vagrantfile (動かない)
N = 3
Vagrant.configure(2) do |config|
(1..N).each do |node_id|
config.vm.define "node-#{node_id}"
end
# Triggerを使って最後のVMをセットアップする時だけAnsible Provisionを有効にする。
config.trigger.before :up do |trigger|
node_id = 1
trigger.ruby do |env, machine|
@takahisa
takahisa / extensible_interpreter_without_algebraic_effects.ml
Created July 26, 2020 06:02
Extensible Interpreter with Algebraic Effectsを例外のみで実装
type result = ..
type result +=
| IntVal of int
type expr = ..
type expr +=
| Int of int
| Add of expr * expr
| Sub of expr * expr
exception Extension of expr * (result -> result)
@takahisa
takahisa / extensible_interpreter_without_algebraic_effects.ml
Created July 26, 2020 06:02
Extensible Interpreter with Algebraic Effectsを例外のみで実装
type result = ..
type result +=
| IntVal of int
type expr = ..
type expr +=
| Int of int
| Add of expr * expr
| Sub of expr * expr
exception Extension of expr * (result -> result)
@takahisa
takahisa / extensible_interpreter_with_algebraic_effects.ml.ml
Last active July 24, 2020 20:38
Extensible Interpreter with Algebraic Effects
type 'a expr = ..
type 'a expr +=
| Int: int -> int expr
| Add: int expr * int expr -> int expr
| Sub: int expr * int expr -> int expr
effect Extension: 'a expr -> 'a
let rec eval1: type a. a expr -> a = function
| Int n0 -> n0
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv) {
int fd1 = open("./services", O_RDONLY);
int fd2 = open("./services", O_RDONLY);
module type EQ_CODE = sig
type t
val eq: (t -> t -> bool) code
end
@takahisa
takahisa / makeset.ml
Last active September 13, 2017 03:26
module MakeSet (Eq: EQ) = struct
type elt
type set
let member : (elt -> set -> bool) code
end
実行環境: Mac OSX 10.11.16, コンパイラ・バージョン: 4.04
linerlock:example linerlock$ ocamlfind ocamlc -ppx ../src/ppx_test -c example.ml
File "/var/folders/x_/r9b6vjld0d77n2cnzm0zqmph0000gn/T/camlppx8c76a8", line 1:
Error: I can't decide whether /var/folders/x_/r9b6vjld0d77n2cnzm0zqmph0000gn/T/camlppx8c76a8 is an implementation or interface file
File "example.ml", line 1:
Error: Error while running external preprocessor
Command line: ../src/ppx_pf '/var/folders/x_/r9b6vjld0d77n2cnzm0zqmph0000gn/T/camlppx8c76a8' '/var/folders/x_/r9b6vjld0d77n2cnzm0zqmph0000gn/T/camlppx0495de'