Skip to content

Instantly share code, notes, and snippets.

View mnn's full-sized avatar

monnef mnn

View GitHub Profile
@mnn
mnn / Deserialization.scala
Created June 29, 2016 18:19 — forked from ramn/Deserialization.scala
Object serialization example in Scala
import java.io._
@SerialVersionUID(15L)
class Animal(name: String, age: Int) extends Serializable {
override def toString = s"Animal($name, $age)"
}
case class Person(name: String)
// or fork := true in sbt
@mnn
mnn / SerializationTest.scala
Created June 23, 2016 10:52
Scala serialization issue, pickling library.
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}
import scala.pickling.Defaults._, scala.pickling.binary._
object Main extends App {
SerializationTest.run()
}
case class IntSeqHolder(seq: Seq[Int])
case class Pupper(name: String)
@mnn
mnn / gist:05d30609240571b1f25ab4b6b050d782
Created April 25, 2016 05:44
ImageMagick - montage column of pictures without resizing
montage -geometry +0+0 -tile 1
import groovy.transform.CompileStatic
@CompileStatic
void swap(int[] a, int i, int j) {
int temp = a[i]
a[i] = a[j]
a[j] = temp
}
@CompileStatic

Find the last commit that affected the given path. As the file isn't in the HEAD commit, this commit must have deleted it.

git rev-list -n 1 HEAD -- <file_path>

Then checkout the version at the commit before, using the caret (^) symbol:

git checkout ^ -- 
addStyle = (css) !-> $ '<style type="text/css"></style>' .html(css) .appendTo(\head)
java -Dsbt.main.class=sbt.ScriptMain -Dsbt.boot.directory=c:/users/<user>/.sbt/boot -jar c:/users/<user>/.conscript/sbt-launch.jar %*
@mnn
mnn / install.sh
Last active May 17, 2017 14:01
Ammonite REPL installation with MinGW
mkdir -p ~/.ammonite && wget -O ~/.ammonite/predef.scala --no-check-certificate https://git.io/v6r5y
wget -O amm --no-check-certificate https://git.io/vioDM && chmod u+x amm && ./amm
@mnn
mnn / gist:5844da17db537d05443a
Created February 3, 2015 22:13
IO benchmark with `dd`
dd conv=fdatasync if=/dev/zero of=/tmp/output.img bs=8k count=128k; rm /tmp/output.img
import scala.runtime.ScalaRunTime.stringOf
import scala.collection.JavaConverters._
// stuff for verifying results, skip to case defs (comment -- 1 --)
def doVerify[A](name: String, origRes: A, myRes: A) {
val equals = origRes match {
case a: Array[_] => a.sameElements(myRes.asInstanceOf[Array[_]])
case _ => origRes.equals(myRes)
}
if (equals) println(s"Case '$name' fine: ${stringOf(myRes)}")