Skip to content

Instantly share code, notes, and snippets.

View mossprescott's full-sized avatar

Moss Prescott mossprescott

View GitHub Profile

I don't like any of those names. matryoshka.∘ is compose for types, so why are we using the "map" operator? Just because there's no suitable "dot"?

Furthermore Delay is applying its second argument. So really wouldn't it make more sense to have these?

type Curry[F[_], G[_]] = G ~> (FG)#λ
type Flip[F[_], G[_]] = (FG)#λ ~> (GF)#λ  // But that probably makes no sense.
@mossprescott
mossprescott / QSpec.scala
Created August 17, 2016 13:25
Reducing bytecode size by extending an abstract class instead of a trait (per paulp)
/** Use Qspec if you can, QuasarSpecification only if you must.
* An abstract class allows the many trait forwarders to be reused
* by all the subclasses. Mixing in the trait means that your
* specification sprouts hundreds of pure forwarders.
*/
abstract class Qspec extends QuasarSpecification
trait QuasarSpecification extends AnyRef
with org.specs2.mutable.SpecLike
with org.specs2.matcher.ShouldExpectations
@mossprescott
mossprescott / coproduct.scala
Created June 15, 2016 22:52
Testing performance with Coproduct and `:+:` op
trait T0[A]
trait T1[A]
trait T2[A]
trait T3[A]
trait T4[A]
trait T5[A]
trait T6[A]
trait T7[A]
trait T8[A]
@mossprescott
mossprescott / recovery.scala
Created June 15, 2016 16:17
Recovering from query failure in PostgreSQL
// Alternative for handling failure in MetaStoreAccess.createGroup0
lineage(path0).traverse_(p =>
for {
sp <- HC.setSavepoint
r <- Queries.insertGroup(p).run.attempt
_ <- r.swap.traverse_(κ(HC.rollback(sp)))
} yield ())
// What a general combinator might look like:
def attemptAndRecover(prg: ConnectionIO[Unit]): ConnectionIO[Unit] =
@mossprescott
mossprescott / deepSized.scala
Created December 28, 2015 22:04
Scalacheck generators that distribute the size parameter across the generated structure
/** Generator that distributes the available size to two component generators,
* and then combines the results. Can be used to generate nested structures
* where the total number of component/leaf elements is effectively controlled
* by the size parameter.
*/
def deepSized[A, B, C](ga: Gen[A], gb: Gen[B])(f: (A, B) => C): Gen[C] =
for {
n <- Gen.size
x <- Gen.choose(0, n)
a <- Gen.resize(x, ga)
@mossprescott
mossprescott / .mongorc.js
Created December 16, 2015 17:36
Functions for cleaning up mongo databases; place in ~
function dropTemps() {
var colls = db.getCollectionNames();
for (i in colls) {
var name = colls[i];
if (name.length > 20 || name.startsWith("tmp.")) {
var col = db.getCollection(name);
print("dropping " + name + " (" + col.totalSize() / (1024 * 1024.0) + " MB)");
var dropped = col.drop();
if (!dropped) print(" failed");
@mossprescott
mossprescott / betterdiff.patch
Created December 10, 2015 18:44
A hack to capture source values in RenderTree and use them in diff()
diff --git a/core/src/main/scala/quasar/RenderTree.scala b/core/src/main/scala/quasar/RenderTree.scala
index 9114fe9..ca9db46 100644
--- a/core/src/main/scala/quasar/RenderTree.scala
+++ b/core/src/main/scala/quasar/RenderTree.scala
@@ -26,12 +26,18 @@ import argonaut._; import Argonaut._
import scalaz._; import Scalaz._
import simulacrum.typeclass
-final case class RenderedTree(nodeType: List[String], label: Option[String], children: List[RenderedTree]) {
- def simpleType: Option[String] = nodeType.headOption
@mossprescott
mossprescott / savezip.py
Created December 3, 2015 22:08
Write zip files with different bits for same content?
# [error] 'ByteVector(240 bytes, 0x504b03041400080808005875e74600000000000000000000000003000000666f6f63601805a360140c770000504b070880170b060b000000e8030000504b03041400080808005975e7460000000000000000000000000300000062617263601805a360140c770000504b070880170b060b000000e8030000504b010214001400080808005875e74680170b060b000000e8030000030000000000000000000000000000000000666f6f504b010214001400080808005975e74680170b060b000000e803000003000000000000000000000000003c000000626172504b0506000000000200020062000000780000000000)'
# [error] is not equal to
# [error] 'ByteVector(240 bytes, 0x504b03041400080808005975e74600000000000000000000000003000000666f6f63601805a360140c770000504b070880170b060b000000e8030000504b03041400080808005975e7460000000000000000000000000300000062617263601805a360140c770000504b070880170b060b000000e8030000504b010214001400080808005975e74680170b060b000000e8030000030000000000000000000000000000000000666f6f504b010214001400080808005975e74680170b060b000000e803000003000000000000000000000000003c00000062617
@mossprescott
mossprescott / ppjson1.py
Created November 25, 2015 00:16
Command-line pretty-priner for JSON (one value, can be multi-line)
#! /usr/local/bin/python
# Slightly modified from the module's own __main__ behavior (according to the interwebs).
import sys, json
infile = sys.stdin
outfile = sys.stdout
with infile:
@mossprescott
mossprescott / ppjson.py
Created November 25, 2015 00:14
Command-line pretty-printer for line-delimited JSON
#! /usr/local/bin/python
# Adapted from the module's own __main__ behavior (according to the interwebs).
# This variant reads one JSON object per line from the input, and emits any
# non-JSON lines as is, prefixed by '>>> '.
import sys, json
infile = sys.stdin
outfile = sys.stdout