Skip to content

Instantly share code, notes, and snippets.

@dcsobral
dcsobral / puppet3.pp
Created December 13, 2012 12:56
annotated file
puppet lcode class main::sub {
puppet lcode include substuff
puppet lcode }
@dcsobral
dcsobral / puppet2.pp
Created December 13, 2012 12:55
annotated file
puppet lcode import "classes/*.pp"
puppet lcode import "definitions/*.pp"
@dcsobral
dcsobral / puppet3.pp
Created December 13, 2012 12:54
normal file
class main::sub {
include substuff
}
@dcsobral
dcsobral / puppet2.pp
Created December 13, 2012 12:52
normal file
import "classes/*.pp"
import "definitions/*.pp"
@dcsobral
dcsobral / gist:3949827
Created October 25, 2012 00:41
Miles Sabin Exercise
scala> class Tester[R <: ResourceManager#Resource] {
| def apply(r: R) = assert(r.hash == "9e47088d", "Expected: 9e47088d, Found: "+r.hash)
| }
defined class Tester
scala> def testHash[RM <: ResourceManager](rm: RM) = new Tester[rm.Resource]
testHash: [RM <: ResourceManager](rm: RM)Tester[rm.Resource]
@dcsobral
dcsobral / modifyZIP.scala
Created September 28, 2012 16:24
Adds a fake header to ZIP files to produce valid ZIP files that ZipInputStream cannot decode
#!/bin/sh
exec scala "$0" "$@"
!#
import java.io._
if (args.length != 2)
sys.error("Please pass input and output files as parameters")
val inputFile = new File(args(0))
val outputFile = new File(args(1))
@dcsobral
dcsobral / gist:3767946
Created September 22, 2012 21:50 — forked from xeno-by/gist:2559714
Mixing in a trait dynamically
Answers http://stackoverflow.com/questions/10373318/mixing-in-a-trait-dynamically.
Compile as follows:
scalac Common_1.scala Macros_2.scala
scalac Common_1.scala Test_3.scala -cp <path to the result of the previous compilation>
Tested in 2.10.0-M3, will most likely not compile by the time 2.10.0 final is released, because we're actively rehashing the API.
However the principles will remain the same in the final release, so the concept itself is okay.
upd. Code updated for 2.10.0-M7.
scala> -0.0 == 0.0
res0: Boolean = true
scala> -0.0 < 0.0
res1: Boolean = false
scala> -0.0 > 0.0
res2: Boolean = false
scala> -0.0 compareTo 0.0
@dcsobral
dcsobral / ListZipper.scala
Created August 30, 2012 23:18 — forked from tonymorris/ListZipper.scala
List Zipper
case class ListZipper[+A](lefts: List[A], x: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
sys.error("todo")
// map with zipper context
def coFlatMap[B](f: ListZipper[A] => B): ListZipper[B] =
sys.error("todo")
def findRight(p: A => Boolean): Option[ListZipper[A]] =
sys.error("todo")
@dcsobral
dcsobral / repositories
Created August 20, 2012 17:48
SBT repositories
[repositories]
local
my-maven-repo: http://artifactory.ebc/artifactory/repo/
my-ivy-artifacts: http://artifactory.ebc/artifactory/repo/, [organization]/[module]/[revision]/[type]s/[type].[ext], [organization]/[module]/[revision]/[type]s/[module].[ext]
my-ivy-classifiers: http://artifactory.ebc/artifactory/repo/, [organization]/[module]/[revision]/[type]s/[type].[ext], [organization]/[module]/[revision]/[type]s/[module]-[classifier].[ext]