Skip to content

Instantly share code, notes, and snippets.

yawaramin / openapi.k
Created August 11, 2023 02:57
OpenAPI spec schemas in KCL -
View openapi.k
Bindings for OpenAPI 3.0.0 -
ℹ️ JSON Schema validation for OpenAPI 3.0.0 must conform to this version:
schema Ref:
$ref: str
yawaramin /
Last active August 26, 2023 13:44
Example of encoding Unicode graphemes as string and taking its length
(* Re: *)
(* Use this if using the REPL, otherwise use dune to build with the library dependency *)
#require "uutf";;
(* Converts an array of ints (Unicode graphemes) into a UTF-8 encoded string. *)
let utf8_to_string uchars =
let buf = Buffer.create (2 * Array.length uchars) in
Array.iter (fun uchar -> Uutf.Buffer.add_utf_8 buf (Uchar.of_int uchar)) uchars;
Buffer.contents buf
yawaramin / ecb_rates.sql
Last active June 17, 2021 01:28
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 February 16, 2021 03:28
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 21:10
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 June 18, 2019 03:11
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 September 24, 2018 18:58
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 October 3, 2017 03:43
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...