Skip to content

Instantly share code, notes, and snippets.

View imeredith's full-sized avatar

Ivan Meredith imeredith

View GitHub Profile
@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
<disabledTestInjection>true</disabledTestInjection>
val a = print("Hello ").pure[IO]
val b = println("World!").pure[IO]
println("Now printing HW")
a >|> b unsafePerformIO
def instanceState(id: String)(implicit c: AWSEC2Client, region: String = null) = {
for {
instance <- c.getInstanceServices.describeInstancesInRegion(region, id).headOption
runningInstance <- instance.headOption
} yield runningInstance.getInstanceState
}
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 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)))
}
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"))
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)
})
trait Monad[F[_], A] {
def map[B](f: A => B): F[B]
def flatMap[B](f: A => F[B]): F[B]
}
case class IntS[A](k: Int => (Int, A)) extends Monad[IntS, A] {
def map[B](f: A => B): IntS[B] = IntS((i: Int) => {
k(i) match {
case (s, a) => (s, f(a))
def sum(f: Int => Int)(a: Int, b: Int): Int = {
if (a > b) 0 else f(a) + sum(f)(a + 1, b)
}
def sumInts = sum(x => x) _