Skip to content

Instantly share code, notes, and snippets.

@sdether
sdether / doobietest.scala
Created March 6, 2018 01:42
Desugaring Doobie for comprehension
case class Foo(id: Int, name: String)
case class Bar(id: Int, name: String)
case class FooWithBar(foo: Foo, bars: List[Bar])
// The for-comprehension way
def get1(id: Int): ConnectionIO[Option[FooWithBar]] = for {
fooOpt <- sql"""SELECT id, name FROM foo WHERE id=$id""".query[Foo].option
fooOpt2 <- fooOpt match {
@sdether
sdether / abnf.scala
Last active January 19, 2017 06:50
Expressing ABNF syntax as types and building grammar from those types
trait Rule {}
object ALPHA extends Rule
object DIGIT extends Rule
object OCTET extends Rule
case class Alternative(rules: Rule*) extends Rule
* File -> New -> Project ...
* Scala -> SBT
** next
* Pick name, location, DSK, SBT version (latest) and Scala version
* Check all checkboxes
** Finish
The Project will open, open build.sbt. Initially all lines will be red, which means
the project hasn't yet imported. Now the waiting game begins. Once the IntelliJ has
no more red marks, the project is fully imported and ready.
@sdether
sdether / AsyncInitializer.scala
Last active March 19, 2018 15:54
An async initialization mix-in for Akka Actors
import akka.actor.{ActorRef, Actor, Stash}
import akka.pattern.pipe
import scala.concurrent.Future
trait AsyncInitializer[DEPENDENCIES] extends Stash {
import context._
case class Initialized(dependencies: DEPENDENCIES)
@sdether
sdether / gist:ba2810107b191a390971
Created June 12, 2015 22:07 — forked from oscarrenalias/gist:3914875
Play Enumerator, Iterator cheatsheet
// --- cheat sheet ---
//
// Enumerator &> -> filters the output of the enumerator through an Enumeratee
// Enumerator >>> -> alias for andThen; adds the output of the second enumerator after the first one is done
// Enumerator |>> -> feeds the output of the enumerator into the given iteratee for processing
// --- end of cheat sheet ---
// Example
// Iteratee that sums up the size of the input:
@sdether
sdether / gist:18232768dc5393460e40
Created July 14, 2014 00:07
A slightly altered SQL syntax would stop the needless repetition in parent/child table joins and make parsing, auto-completion a lot easier
-- single result set (duplicated data, requires de-mux on client)
-- cannot auto-complete (table defined after field use)
SELECT p.person_id, p.fname, p.lname, a.address_id, a.street, a.zip, a.state, a.type
FROM person p
INNER JOIN address a
ON a.person_id = p.person_id
WHERE p.status = 1
|person_id|fname|lname|address_id|street|zip|state|type|

Keybase proof

I hereby claim:

  • I am sdether on github.
  • I am sdether (https://keybase.io/sdether) on keybase.
  • I have a public key whose fingerprint is 1E83 115C 8C94 D1D8 835A 6D1E 3509 4810 D432 A80B

To claim this, I am signing this object:

@sdether
sdether / gist:9532422
Created March 13, 2014 17:01
Easy immutable object derivation
public class Immutable {
public class Person {
public readonly string Firstname;
public readonly string Lastname;
public Person(string firstname, string lastname) {
Firstname = firstname;
Lastname = lastname;
@sdether
sdether / gist:3223897
Created August 1, 2012 05:15
Happenstance whois API
GET:/who/joe
{
_sig: '366e58644911fea255c44e7ab6468c6a5ec6b4d9d700a5ed3a810f56527b127e',
id: 'joe@droogindustries.com',
name: 'Joe Smith',
status_uri: 'http://droogindustries.com/status',
feed_uri: 'http:/droogindustries.com/status/feed'
}
public class IPageHierarchyTestBase {
protected bool _passed;
protected IPageHierarchyBL _hierarchy;
[Test]
public virtual void Can_get_page_by_id() {
Console.WriteLine("running test");
Assert.IsNotNull(_hierarchy);
}