Skip to content

Instantly share code, notes, and snippets.

@akabe
akabe / centos-zmq.sh
Created July 28, 2017 03:41
Install zeromq-devel on CentOS7
#!/bin/sh -xeu
sudo yum install -y epel-release
sudo yum install -y zeromq-devel
@akabe
akabe / type-level-list.cpp
Last active November 23, 2022 04:35
Type-level list and compile-time sort in C++
template <int n>
struct Int { static const int val = n; }; // Wrap an integer
template <class fst, class snd>
struct pair {
typedef fst first;
typedef snd second;
};
struct nil {
@akabe
akabe / maze_solver.ml
Last active October 13, 2019 16:34
A maze solver by A* algorithm on OCaml
(* ========================================================================== *
* General implementation of A-star algorithm
* ========================================================================== *)
module Astar :
sig
type 'a t =
{
cost : 'a -> 'a -> int;
goal : 'a;
@akabe
akabe / extensible_record_by_lens.ml
Last active September 4, 2019 01:43
Extensible record by Lens trick in OCaml
(** The Lens trick: getter and setter for fields *)
type ('s, 'v) lens =
{
get: 's -> 'v;
set: 'v -> 's -> 's;
}
let id_lens = {
get = (fun x -> x);
set = (fun v _ -> v);
@akabe
akabe / install_opam.sh
Last active October 12, 2018 02:43
OPAM/OCaml scripts for CI
#!/usr/bin/env sh -xeu
##
## Usage:
## curl -sL https://gist.githubusercontent.com/akabe/24979afbf95c4cf4393f589cda997e1b/raw/install_opam.sh | sh -xeu
##
## Variables:
## - $OPAM_PREFIX Path to install opam
## - $OPAM_VERSION Version of OPAM to be installed
## - $OCAML_VERSION Version of OCaml to be installed
@akabe
akabe / bucklescript_headless_chrome.ml
Last active January 11, 2018 04:45
A short example of bindings of `chrome-launcher` and `chrome-remote-interface` in OCaml BuckleScript
(* This is a short example of bindings of `chrome-launcher` and `chrome-remote-interface`
(for node libraries manipulating headless-mode Google Chrome) in OCaml BuckleScript (https://bucklescript.github.io/).
Usage:
$ npm install -g chrome-launcher chrome-remote-interface
$ bsc -bs-main bucklescript_headless_chrome.ml
Headless browsers (such as PhantomJS, Chrome, Firefox) are useful for, e.g.,
- integration tests of JavaScript products on a real browser, or
- Web scraping for pages containing complex JavaScript.
@akabe
akabe / SafeList.scala
Last active June 24, 2016 00:48
A simple example of type-safe head, tail, and zip of List by Peano-style type-level natural number via phantom type in Scala
object SafeList {
trait Z // phantom type "zero" (corresponding to 0)
trait S[N] // phantom type "successor" (correspoding to n => n+1)
class SList[N, E] private[SafeList] (private[SafeList] val list: List[E])
// SList[N, E] is a list of elements of type E, and length N.
def empty[E] = new SList[Z, E](Nil)
def cons[N, E] (x: E, xs: SList[N, E]) = new SList[S[N], E](x :: xs.list)
@akabe
akabe / recursiveNeuralNetwork.ml
Created January 7, 2015 11:54
Recursive Neural Networks and Online Backpropagation Through Structure (BPTS)
(* recursiveNeuralNetwork.ml --- Recursive Neural Networks and
Online Backpropagation Through Structure (BPTS)
[MIT License] Copyright (C) 2015 Akinori ABE
Compilation:
$ ocamlfind ocamlopt -linkpkg -package slap recursiveNeuralNetwork.ml
This program requires Sized Linear Algebra Library (SLAP), a linear algebra
library for OCaml with static size checking for matrix operations (see
@akabe
akabe / subtyping1.ml
Last active November 22, 2015 06:51
A subtyping encoding by phantom types [Fluet and Pucella, JFP 2006]
open Format
(** The types of the source language
(Hindley-Milner + subtyping + bounded polymorphism) *)
module SL =
struct
type 'a typ =
| Base of 'a (** base type *)
| Var of string (** type variable *)
| Arrow of 'a typ * 'a typ (** function type *)
@akabe
akabe / subtyping2.ml
Created November 19, 2015 11:39
A subtyping encoding by phantom types
open Format
(** The types of the source language
(Hindley-Milner + subtyping + bounded polymorphism) *)
module SL =
struct
type 'a typ =
| Base of 'a (** base type *)
| Var of string (** type variable *)
| Arrow of 'a typ * 'a typ (** function type *)