Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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
/*
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 / 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]
@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
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 / doctool.md
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...
@yawaramin
yawaramin / scala-local-imports.md
Last active September 24, 2018 18:58
Local imports in Scala

Local imports in Scala

https://github.com/ghik/opinionated-scala/wiki/Packages-and-imports#local-imports

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
yawaramin / json-schema.js
Created June 18, 2019 03:11
Flow type description of JSON Schema (WIP)
/* @flow */
type NonNegativeInt = number
type PositiveNumber = number
type Regex = string
type SchemaType = {
description?: string,
}
@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),
// @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)