Skip to content

Instantly share code, notes, and snippets.

I may be (infinitely) slow to respond 😎

Yawar Amin yawaramin

I may be (infinitely) slow to respond 😎
Block or report user

Report or block yawaramin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 / main.dart
Created Aug 5, 2019
Dart subclass covariance
View main.dart
void main() {
void test(Dog dog) {
class Animal {
void speak() {}
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 Mar 22, 2019
Proposed design for an ergonomic OCaml/Reason web framework built on top of an existing server like httpaf
// src/ReWeb/
let set(~status=`Ok, ~body=`Null, ~headers=[], ~cookies=[], response) =
failwith "Not implemented";
let render(~status=`Ok, ~assigns=`Null, ~template, response) = 0o644
|> Unix.(openfile(template, [O_RDONLY]))
|> Lwt_io.(of_unix_fd(~mode=input))
|> => set(~status, ~body=`String(body), response));
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 13, 2019
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 May 15, 2018
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,
open Cmdliner
let mycli _ _ = print_endline "Success!"
let interface =
let docv = "INTERFACE" in
let doc = "parse AST as an interface (true or false)" in
Arg.(required & pos 0 (some bool) None & info ~docv ~doc [])
yawaramin / Main.scala
Last active Jul 28, 2016
Monoid over function composition
View Main.scala
trait Monoid[A] {
def append(a1: A, a2: A): A
def zero: A
object Monoid {
A little convenience method to easily get the Monoid[A] instance.
def apply[A: Monoid]: Monoid[A] = implicitly
You can’t perform that action at this time.