Skip to content

Instantly share code, notes, and snippets.

@viktorklang
viktorklang / Gistard.scala
Last active June 9, 2017 07:27
Gistard — an sbt autoplugin for depending on Gists — such as Gistard itself
/*
Copyright 2015 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
import macros
macro `=>`(p, b: expr): expr {.immediate.} =
echo treeRepr(p)
#echo(treeRepr(b))
var params: seq[PNimrodNode] = @[newIdentNode("auto")]
case p.kind
of nnkPar:
for c in children(p):
@travisbrown
travisbrown / macro-interp.scala
Created March 11, 2013 19:13
String interpolation with macro-supported access to positions.
sealed trait Piece
case class Place(p: String) extends Piece
case class Name(n: String) extends Piece
case class LocatedPieces(located: Seq[(String, Piece, (Int, Int))])
object S2 extends ReflectionUtils {
import scala.language.experimental.macros
import scala.language.reflectiveCalls
import scala.reflect.macros.Context
@travisbrown
travisbrown / MacroSAM.scala
Created March 6, 2013 19:52
Creating single abstract method class instances from function literals in Scala.
import scala.language.experimental.macros
import scala.language.higherKinds
import scala.reflect.macros.Context
object MacroSAM {
def sam[F[_, _], A, B](f: A => B) = macro sam_impl[F, A, B]
def sam_impl[F[_, _], A: c.WeakTypeTag, B: c.WeakTypeTag](c: Context)
(f: c.Expr[A => B])(implicit tag: c.WeakTypeTag[F[_, _]]) = {
import c.universe._
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: