Skip to content

Instantly share code, notes, and snippets.

View dwijnand's full-sized avatar

Dale Wijnand dwijnand

View GitHub Profile
@travisbrown
travisbrown / noncompilation.scala
Last active January 13, 2016 18:00
Testing for compiler errors with untyped macros.
scala> import scala.language.experimental.macros
import scala.language.experimental.macros
scala> import scala.reflect.macros.{ Context, TypecheckException }
import scala.reflect.macros.{Context, TypecheckException}
scala> object NoncompilationTests {
| def compiles(code: _): Boolean = macro compiles_impl
| def compiles_impl(c: Context)(code: c.Tree) = c.literal(
| try {
// Quasiquoted excerpt
def cdef = q"""
class $ClassName[..$classTypeParams](..$primaryParams) extends ..$classParents {
..$primaryAccessors
def get = this
def isEmpty = ${quasi.isEmpty}
def copy(..$primaryWithDefaults) = $ObjectName(..$primaryNames)
@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
class Bippy(override val toString: String)
trait A { implicit def lowPriority: Bippy = new Bippy("A") }
object B extends A { implicit def highPriority: Bippy = new Bippy("B") }
object C { implicit def highPriority: Bippy = new Bippy("C") }
object Test {
def main(args: Array[String]): Unit = {
import B._, C._
println( implicitly[Bippy] ) // Prints: A
@stew
stew / either.py
Last active February 9, 2016 08:50
from abc import ABCMeta, abstractmethod
import sys
# lets get one thing straight right out of the box:
def fail(e):
import traceback
with open("/tmp/tb", "w") as f:
traceback.print_exc(e, f)
@dwijnand
dwijnand / fixed-strings.txt
Last active April 6, 2021 10:22
Dual strings of the same length
lo/hi
enc/dec
fst/snd
get/put/del
new/add/mod/del/(rem)
old/new
req/rsp
src/dst
usr/pwd
@xuwei-k
xuwei-k / PlayMini.scala
Last active February 20, 2016 13:14
came back play mini!
#!/usr/bin/env scalas
/***
scalaVersion := "2.11.7"
libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.4.6"
*/
import play.core.server._
import play.api.routing.sird._
import play.api.mvc._
@paulp
paulp / cast.go
Last active November 17, 2017 00:00
/** TL;DR Of course we want to savagely truncate our data!
* You know we want that because earlier you saw us cast between
* same-sized types (because you offer no other way) and all casts
* are the same.
*/
package main
import . "fmt"
type Foo int16
@alexandru
alexandru / task-proposal.md
Last active April 1, 2018 14:57
Task: A diverging design from Future and Scalaz Task
@paulp
paulp / demo.sh
Last active June 8, 2018 09:16
Enabling sbt plugins from the command line in any sbt project
% sbtx dependencyGraph
... blah blah ...
[info] *** Welcome to the sbt build definition for Scala! ***
[info] Check README.md for more information.
[error] Not a valid command: dependencyGraph
[error] Not a valid project ID: dependencyGraph
% sbtx -Dplugins=graph dependencyGraph
... blah blah ...