Skip to content

Instantly share code, notes, and snippets.

@thsutton
thsutton / DynamoDB.scala.patch
Last active November 8, 2017 06:19
Reduce some duplication (by more duplication)
diff --git a/dynamodb/src/main/scala/io/atlassian/aws/dynamodb/DynamoDB.scala b/dynamodb/src/main/scala/io/atlassian/aws/dynamodb/DynamoDB.scala
index e87be02..8331411 100644
--- a/dynamodb/src/main/scala/io/atlassian/aws/dynamodb/DynamoDB.scala
+++ b/dynamodb/src/main/scala/io/atlassian/aws/dynamodb/DynamoDB.scala
@@ -120,19 +120,7 @@ object DynamoDB {
def query[PK, V](ck: Column[PK], cv: Column[V])(q: QueryImpl): DynamoDBAction[Page[PK, V]] =
DynamoDBAction.withClient {
_.query(q.asQueryRequest)
- }.flatMap { res =>
- DynamoDBAction.attempt {
trait Queries {
type K
trait Query {
def from(k: K): Query
}
def select(where: String) = Select(where)
@thsutton
thsutton / git-retch
Created October 5, 2017 03:38
$ git retch
#!/usr/bin/env bash
cat <<"EOF"
.-'"'-.
/ `. ,' \
| ,' `. |
| ___ |
\ ( . ) /
'-.:.-'
.:.
@thsutton
thsutton / main.hs
Created August 8, 2014 05:52
Monad logger
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Control.Monad.Except
import Control.Monad.IO.Class ()
import Control.Monad.Reader
@thsutton
thsutton / Comb.scala
Last active August 1, 2017 06:24
Some generators for choices, permutations, shuffling, etc.
import scalaprops._
/** Generate a permutation of the given values.
*
* > permute("ABC").sample
* Vector(A,C,B)
* > permute("ABC").sample
* Vector(B,A,C)
*/
def permute[A](values: IndexedSeq[A]): Gen[IndexedSeq[A]] =
@thsutton
thsutton / StrictSubtype.scala
Created July 27, 2017 23:10
Bound a type parameter to be strictly a subtype.
object Test extends App {
// From https://stackoverflow.com/a/6944070
trait =!=[A, B]
implicit def neq[A, B] : A =!= B = null
// This pair excludes the A =:= B case
implicit def neqAmbig1[A] : A =!= A = null
TARGET=.
REPORT=/tmp/foo.sha
find $TARGET -type f -print0 | sort -z | xargs -0 sha1sum | tee >(sha1sum >> $REPORT) > $REPORT
@thsutton
thsutton / lol.sql
Created December 1, 2015 09:34
SQLite derp
sqlite> create table foo ( id int not null );
sqlite> insert into foo values (1);
sqlite> insert into foo values (2);
sqlite> insert into foo values ("hello");
sqlite> select * from foo;
1
2
hello
@thsutton
thsutton / fix-packt-epubs.sh
Created September 23, 2013 11:28
Shell script to fix the "unique" identifiers in EPUB files sold by Packt Publishing.
#!/bin/sh
#
# fixpacktepubs.sh
#
# Process the EPUB files in the current directory and recreate them with the
# ISBN as the unique value. This script was written because Packt Publishing
# sell EPUBs with non-unique unique identifiers and it assumes that the EPUBs
# being process are structured like Packt's.
#
@thsutton
thsutton / e.idr
Created December 23, 2015 03:54
Half working Idris code for the E language from PFPL
module Main
data Nt : Type where
Zn : Nt
Sn : Nt -> Nt
mutual
data Even : Nt -> Type where
EvenZn : Even Zn
EvenSn : Odd n -> Even (Sn n)