Skip to content

Instantly share code, notes, and snippets.

import * as fg from "fast-glob";
import * as fs from "fs";
import { format } from "sql-formatter";
/**
* We need to create our own sql formatter as prettier-plugin-sql is busted.
* Won't support passing of paramTypes to underlying sql-formatter.
*/
// find files recursively if not provided as argument
const files =
@jayp
jayp / gist:1620ba90e466506783ec
Created January 21, 2015 02:57
Smallest Change
(defspec smallest-change
(prop/for-all [[coinset amount] gen-amount-from-coinset]
(let [change (make-change coinset amount)]
(= 1 (count change)))))
@jayp
jayp / add-params.clj
Last active August 29, 2015 14:11
How does one writhe add-params-to-func?
repl=> (defmacro add-params [expr & params]
#_=> `(~@expr ~@params))
;; add-params works as intended for regular functions
repl=> (macroexpand '(add-params (+ 5 6) 7 8 9))
(+ 5 6 7 8 9)
repl=> (add-params (+ 1 2) 3 4 5)
15
@jayp
jayp / gist:1246575
Created September 27, 2011 23:44
Problems with built-in XML support for Scala
bash-3.2$ scala
Welcome to Scala version 2.9.1.RC4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val checked: Option[xml.Text] = None
checked: Option[scala.xml.Text] = None
scala> val a = <input checked={checked} />
a: scala.xml.Elem = <input ></input>
@jayp
jayp / pattern-only.scala
Created September 27, 2011 23:43
An approach using pattern matching
val command: String = params("Command").getOrElse("")
val response: String = command match {
// valid for any user
"help" => help(...)
"info" => info(...)
// only admin can execute the following commands
"add" =>
if (isAdmin)
addUser(...)
else
@jayp
jayp / pattern-guard.scala
Created September 27, 2011 23:42
An approach with pattern matching with pattern guards
val command: String = params("Command").getOrElse("")
val response: String = command match {
// valid for any user
"help" => help(...)
"info" => info(...)
// only admin can execute the following commands
"add" if isAdmin => addUser(...)
"delete" if isAdmin => deleteUser(...)
_ => "unknown or unauthorized command"
}