Skip to content

Instantly share code, notes, and snippets.

@yawaramin
yawaramin / sig
Last active June 12, 2022 05:03
Bourne Shell script to print out Merlin's inferred signature of an OCaml file (module)
#!/usr/bin/env sh
# Works with merlin version 2.5.4. Using protocol described at
# https://github.com/ocaml/merlin/blob/master/doc/dev/OLD-PROTOCOL.md#type-checking
usage ()
{
echo Usage: either of the following will work:
echo
echo ' sig module.ml'
@yawaramin
yawaramin / sql.fs
Last active November 6, 2019 19:34
Type-safe SQL query using phantom types to model query parts as state transitions
(*
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
yawaramin / Main.scala
Last active April 22, 2016 18:11
Asynchronous and streaming file word counter
import java.nio.file.{ Files, Path, Paths }
import resource._
import scala.collection.JavaConversions.iterableAsScalaIterable
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ Await, Future }
object Main {
/** An asynchronous function (inspired by Finagle). */
type Async[A, B] = A => Future[B]
/*
Low-priority implicits
Thanks to
http://www.slideshare.net/NLJUG/scala-design-patterns-age-mooij for
pointing me in the right direction
*/
trait Ord[A] {
/** Returns a1 <= a2 */
def lteq(a1: A, a2: A): Boolean
@yawaramin
yawaramin / ParseTags.rs
Last active July 30, 2019 00:08
Parse text tags (Rust)
/// Parsed fragment of a document, containing borrowed slices of text
/// from the original document itself.
#[derive(Debug, PartialEq)]
pub enum DocPart<'a> {
/// Placeholder markup containing variable or expression that can be
/// interpolated with values.
Tag(&'a str, Vec<&'a str>),
/// Plain text.
Run(&'a str),
@yawaramin
yawaramin / ParseTags.hs
Last active September 18, 2016 14:59
Parse text tags
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
{- A document part is like a piece of syntax. -}
data DocPart =
Tag T.Text [T.Text] | Run T.Text
@yawaramin
yawaramin / sample-db.sql
Created October 3, 2013 00:51
Sample Access ANSI-92 SQL database creation script
alter table tblAddresses
drop constraint Addresses_NeedAtLeastOnePart;
alter table tblPeople
drop constraint People_AddressID;
alter table tblPeople
drop constraint People_NeedAtLeastOneName;
alter table tblPeople