Skip to content

Instantly share code, notes, and snippets.

View timperrett's full-sized avatar
🚧

Timothy Perrett timperrett

🚧
View GitHub Profile
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
scala> List("foo","bar","baz") andThen {
| case "bar" => 1.0
| case _ => 0.0
| }
res0: PartialFunction[Int,Double] = <function1>
scala> res0(0)
res1: Double = 0.0
scala> res0(1)
[error] SERVER ERROR: Service Unavailable url=http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.apache.maven/maven-aether-provider/3.1.0/jars/maven-aether-provider.jar
curl -X POST \
--header "Content-Type: application/json" \
--header "im-wskid:1386609095" \
--header "im-secret:hLGJURZG0X5h9k6B07Hh55jqdYYlE/AOVnsQxdJ5bhXlbLhldyaSY1hpJ5mHfyIfGBuhAd4h7iIFq251vFoA2yKA4KXk6Ypp0hO28LblJA4nI+IwP8nCmJvkHWFSnKZADqhKV/7iScaay7PcWvctgAN+1JksASCYGfwR0sN0EKhhMmKOKq6hghGM3wazLAiuS61mnObfKB0xGv9nWJmKtg==" \
-d '{"to":["qwertyuiop"],"kind":"device:global","preferred":[{"kind":"services-intel-developer","config":{"foo":"bar"}}],"minimum":[]}' \
-v https://imqa-su3264.svc.m.infra-host.com:9443/allocations
===================
@timperrett
timperrett / gist:6224373
Created August 13, 2013 18:49
Shapeless typed element selection
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._, HList._
import shapeless._
import HList._
scala> "foo" :: 124 :: HNil
res0: shapeless.::[java.lang.String,shapeless.::[Int,shapeless.HNil]] = foo :: 124 :: HNil
@timperrett
timperrett / futures.scala
Last active December 11, 2015 21:28
Example of composing 2.10 futures with scalaz.Validation
package scalaz.akkaz
import scala.language.higherKinds
import scalaz.{Monad, Monoid, Comonad, Traverse, Applicative}
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.concurrent.duration._
/**
* @see [[scalaz.akkaz.future]] for examples
*/
@timperrett
timperrett / candy-build.sbt
Last active December 10, 2015 19:29
Solution to the candy machine problem from FP in Scala MEAP.
scalaVersion := "2.10.0"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.0-M7"
resolvers += "sontatype.releases" at "https://oss.sonatype.org/content/repositories/releases/"
@timperrett
timperrett / gist:4417294
Created December 31, 2012 04:08
Kryo2 scala example
package demo
class User(name: String, age: Int)
object Example {
import com.esotericsoftware.kryo.{Kryo,io}, io.{Output,Input}
val kryo = new Kryo
kryo.register(classOf[User])
@timperrett
timperrett / utter_rubbish.php
Created October 2, 2012 22:41
Stupid stuff PHP does.
<?php
// set a value
$theCount = 123;
// set a string that happens to be the same name as the
// previous (unrelated) value
$someString = 'theCount';
// print out the string... oh... WAT.
echo $$someString; // echo's 123
echo "\n";
@timperrett
timperrett / js.scala
Created September 28, 2012 10:17
light js dsl
trait js {
implicit def arrayExpr[A](es: Seq[A])(implicit f: A => Expr): ArrayExpr =
ArrayExpr(es.map(f))
implicit def objectExpr[A](fs: Seq[(String, A)])(implicit f: A => Expr): ObjectExpr =
ObjectExpr(fs.map { case (k, v) => (k, f(v)) })
implicit def booleanLiteral(b: Boolean): LiteralBoolean = LiteralBoolean(b)
implicit def nodeSeqLiteral(ns: NodeSeq): LiteralNodeSeq = LiteralNodeSeq(ns)
implicit def numericLiteral[A: Numeric](n: A): LiteralNumeric[A] = LiteralNumeric(n)
implicit def stringLiteral(s: String): LiteralString = LiteralString(s)
implicit def symbolReference(in: Symbol): Reference = Reference(in.name)