Skip to content

Instantly share code, notes, and snippets.

View imeredith's full-sized avatar

Ivan Meredith imeredith

View GitHub Profile
new Monad[IntS] {
def map[A, B](f: A => B) = (a: IntS[A]) => IntS((i: Int) => {
val res = a.k(i)
(res._1, f(res._2))
})
def flatMap[A, B](f: A => IntS[B]) = (a: IntS[A]) => IntS((i: Int) => {
val res = a.k(i)
f(res._2).k(i)
})
scala> trait Functor[F[_]] { def a[A, B](b: A => B): F[A] => F[B]}
defined trait Functor
scala> object Test extends Functor[Option] { def a[A, B](b: A=>B) = (a: Option[A]) => a map b}
defined module Test
scala> Test.a((a: String) => a.length)
res8: (Option[String]) => Option[Int] = <function1>
scala> res8(Some("teSt"))
def repeatWithIndex(field: play.api.data.Field, min: Int = 1)(f: (play.api.data.Field, Int) => Html) = {
(0 until math.max(if (field.indexes.isEmpty) 0 else field.indexes.max + 1, min)).map(i => f(field("[" + i + "]", i)))
}
def createContext = {
ContextBuilder.newBuilder(new AWSEC2ProviderMetadata)
.credentials("<>", "<>")
.buildView(classOf[AWSEC2ComputeServiceContext])
.unwrap(classOf[RestContext[AWSEC2Client, AWSEC2AsyncClient]])
}
implicit def syncApi = createContext.getApi
def createInstance(imageId: String, hwType: String, group: String, key: String)(implicit c: AWSEC2Client, region: String = null) = {
def instanceState(id: String)(implicit c: AWSEC2Client, region: String = null) = {
for {
instance <- c.getInstanceServices.describeInstancesInRegion(region, id).headOption
runningInstance <- instance.headOption
} yield runningInstance.getInstanceState
}
val a = print("Hello ").pure[IO]
val b = println("World!").pure[IO]
println("Now printing HW")
a >|> b unsafePerformIO
<disabledTestInjection>true</disabledTestInjection>
@imeredith
imeredith / gist:2504809
Created April 27, 2012 01:20
revert changes by a specific user and cherry-pick the rest
This is what I did to revert a lot of changes I had made to a branch over a 2 week period, but still keep other commits that weren't mine.
git branch old-master
git reset <commitId> --hard
for i in `git log master..old-master | grep -v "Author: Ivan Meredith" |grep -B 1 Author |grep commit | awk '{print $2}'`|tail -r; do git cherry-pick $i;done
git push origin master --force
git push origin old-master
@imeredith
imeredith / testing.txt
Created April 23, 2012 08:33
testing sublime
Testing gist from sublime this is cool
trait Category[~>[_, _]] {
def compose[A, B, C](f: B ~> C)(g: A ~> B): A ~> C
def id[A]: A ~> A
}
case class Lens[A, B](
get: A => B
, set: (A, B) => A
)