Skip to content

Instantly share code, notes, and snippets.

View eparejatobes's full-sized avatar

Eduardo Pareja Tobes eparejatobes

View GitHub Profile
@laughedelic
laughedelic / Readme.md
Last active August 29, 2015 14:23
Typing unicode symbols in Atom (temporary solution)

Temporary solution for typing unicode symbols in Atom

Usage

  1. Install autocomplete-plus and autocomplete-snippets plugins
  2. Add these snippets to your snippets.cson
  3. Try typing u and the LaTeX name of the symbol you want and you should get autocompletetion with a preview of the symbol

Notes

@mergeconflict
mergeconflict / all.scala
Created March 24, 2012 22:24
packaging and unpackaging multiple implicit conversions in an HList
object AllExamples extends App {
import shapeless._
final class All[L <: HList](val values: L) {
def apply[A](implicit selector: Selector[L, A]): A = values.select[A]
}
object All {
// package a value of type A, convertible to type B, into an HList containing just B
@marklister
marklister / AwsRequest.scala
Created September 12, 2012 21:28
Scala Amazon Web Service Signed Request Generator
package org.catch22.amazonws
/**
* This class derives from https://github.com/keplar/scalapac
* It's released under the Apache licence V2.0
* Copyright (c) 2012 Orderly Ltd. All rights reserved.
* Copyright (c) 2012 Mark Lister
*
*/
/** Constructing "singleton types" from compile-time literals
*
* val x = Example.foo(42)
* val y: x.T = 42 // compiles
* val z: x.T = 43 // doesn't
*
*/
package s
import scala.language.experimental.macros
object Ok {
trait Foo[A]
case class Bar(x: Int)
object Bar {
implicit class BarOps(bar: Foo[Bar]) {
val ok = "ok"
}
}
def usage(bar: Foo[Bar]) = bar.ok // Ok, the implicit conversion is found in the Bar companion object
/* A better way to tag types?
*
* 1) object Time: here we are distinguishing between different uses of a Long,
* yet there is no boxing whatsoever.
*
* main calls start: ()J
* main calls timed: (Function0, J)
* Function0 gives up the result: ()J
* timed calls now: ()J
* timed calls elapsed$extension: (JJ)J
@milessabin
milessabin / gist:6140251
Created August 2, 2013 14:25
HLists and singleton types encode records in Scala
scala> import shapeless._; import SingletonTypes._; import Record._
import shapeless._
import SingletonTypes._
import Record._
scala> val r = ("foo" ->> 23) :: ("bar" ->> true) :: ("baz" ->> 2.0) :: HNil
r: (String("foo"), Int) :: (String("bar"), Boolean) :: (String("baz"), Double) :: HNil =
(foo,23) :: (bar,true) :: (baz,2.0) :: HNil
scala> r.head // r is an HList of pairs of singleton-typed Strings and values ...
@milessabin
milessabin / gist:6707525
Created September 25, 2013 23:14
New in shapeless 2.0.0-SNAPSHOT (post M1): lazy recursive implicit values ... normally you would expect the recursion between List[T] and Cons[T] to cause the implicit resolution for Show[T] to blow up with a diverging implicit expansion.
import shapeless._
sealed trait List[+T]
case class Cons[T](hd: T, tl: List[T]) extends List[T]
sealed trait Nil extends List[Nothing]
case object Nil extends Nil
trait Show[T] {
def apply(t: T): String
}
@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 {
@rmmeans
rmmeans / DynamoJson.scala
Created October 19, 2015 16:29
Play Framework DynamoDB Json
object DynamoReader {
def typeReader[A](f: (JsObject => JsResult[A])) = new Reads[A] {
def reads(json: JsValue): JsResult[A] = json match {
case obj: JsObject => f(obj)
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("error.expected.jsobject"))))
}
}
}
object DynamoString {