Skip to content

Instantly share code, notes, and snippets.

yawaramin / ecb_rates.sql
Last active Jun 17, 2021
European Central Bank historical rates import SQLite script
View ecb_rates.sql
-- Run with:
-- $ sqlite3 ecb_rates.db
-- sqlite> .read ecb_rates.sql
drop table if exists eurofxref_hist;
drop table if exists ecb_rates;
create table ecb_rates (
date text not null,
curr text not null,
yawaramin / comment
Created Feb 16, 2021
Get or set file comment (Linux)
View comment
#!/usr/bin/env sh
usage() {
cat <<EOF
$(basename $0) FILENAME [COMMENT]
Get or set file comment.
(* Good morning everyone, I'm currently learning ocaml for one of my CS class and needed to implement
an avl tree using ocaml. I thought that it would be interesting to go a step further and try
to verify the balance property of the avl tree using the type system. Here's the resulting code
annotated for people new to the ideas of type level programming :)
(* the property we are going to try to verify is that at each node of our tree, the height difference between
the left and the right sub-trees is at most of 1. *)
yawaramin /
Last active May 1, 2020
ReasonML/BuckleScript bindings for Formik
[@bs.module "formik"]
external make: (
~initialValues: Js.t('a),
~validate: (. Js.t('a)) => Js.Dict.t(string),
~onSubmit: (. Js.t('a), {. "setSubmitting": [@bs.meth] bool => unit }) => unit,
~children: (. {. "isSubmitting": bool }) => React.element,
) => React.element = "Formik";
module Form = {
View typed-express.js
// @flow
import type { $Request, $Response, Middleware, NextFunction, Router } from 'express'
type Path = express$Path | express$Path[]
export type TypedMiddleware<A> =
| ((req: $Request & A, res: $Response, next: NextFunction) => mixed)
| ((error: Error, req: Request & A, res: $Response, next: NextFunction) => mixed)
yawaramin / json-schema.js
Created Jun 18, 2019
Flow type description of JSON Schema (WIP)
View json-schema.js
/* @flow */
type NonNegativeInt = number
type PositiveNumber = number
type Regex = string
type SchemaType = {
description?: string,
yawaramin /
Last active Sep 24, 2018
Local imports in Scala

Local imports in Scala

Local imports are very nice tool to minimize the impact of your imports and protect yourself from accidentally polluting too wide namespaces with imports that you need only in small, local context. That's especially important when using wildcard imports (see later).

Cay Horstmann, Scala for the Impatient, §7.8 (Imports can be anywhere)

In Scala, an import statement can be anywhere, not just at the top of a file.

yawaramin /
Last active Oct 3, 2017
A language-agnostic documentation tool

I propose here a new convention and design for a tool to auto-generate API documentation for source code in any language, with no dependencies or intricate build commands. Here are my assumptions:

  • Source code in plain text format
  • Language supports comments, either single- or multi-line (multi-line would be easier to use for documentation)
  • A convention to interpret comments starting with a certain character as documentation comments, e.g. for OCaml we would use (** to mark the start of documentation comments.

Given the above, we can create a tool that has the following UI:

doctool [--output-dir DIR] --start STARTSTR --end ENDSTR --lang LANGUAGE FILE...
yawaramin / sig
Last active Sep 14, 2021
Bourne Shell script to print out Merlin's inferred signature of an OCaml file (module)
View sig
#!/usr/bin/env sh
# Works with merlin version 2.5.4. Using protocol described at
usage ()
echo Usage: either of the following will work:
echo ' sig'
yawaramin / sql.fs
Last active Nov 6, 2019
Type-safe SQL query using phantom types to model query parts as state transitions
View sql.fs
An incomplete implementation of a type-safe SQL query in F#.
The idea is that a query is built up clause by clause, by representing
each additional clause being added on to the query as a state transition
between different types of queries. We capture these different types as
phantom types to make sure that only valid transitions (query clause
additions) as defined by us can be carried out.
The final result is a 'total query' that can be converted to a string,