Skip to content

Instantly share code, notes, and snippets.

View mnn's full-sized avatar

monnef mnn

View GitHub Profile
addStyle = (css) !-> $ '<style type="text/css"></style>' .html(css) .appendTo(\head)

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 ^ -- 
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
@mnn
mnn / gist:05d30609240571b1f25ab4b6b050d782
Created April 25, 2016 05:44
ImageMagick - montage column of pictures without resizing
montage -geometry +0+0 -tile 1
@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 / 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
// 2016.3.2
object Utils {
implicit class FooPimps(f: Foo) {
def implicitMethod(): Unit = println(s"implicit foo method")
}
}
@mnn
mnn / CustomCondOp.scala
Created November 8, 2016 09:36
Custom conditional operator in Scala with widening support
import util.Random
import scalaz._
import Scalaz._
import CustomCondOp._
trait Card {
println(s"Constructing ${getClass.getSimpleName}")
}
class BigCard extends Card
@mnn
mnn / JoiFromTypeScript.hs
Created January 20, 2017 12:34
JoiFromTypeScript - Converts TypeScript interface and type statements to Joi schema generators.
#!/usr/bin/env runhaskell
{-|
Module : JoiFromTypeScript
Description : Converts TypeScript interface and type statements to Joi schema generators.
Copyright : monnef
Maintainer : [email protected]
Stability : experimental
= Dependencies
@mnn
mnn / Udash_JSON_GenCodec[Option[T]].scala
Created April 1, 2017 05:59
Udash Option JSON codec
/**
* Udash Option JSON codec for (de)serializing it this way:
* Some(x) will be serialized as x.
* None will be serialized as null.
*/
implicit def optionCodec[T: GenCodec]: GenCodec[Option[T]] =
create[Option[T]](
i => i.inputType match {
case InputType.Null =>
i.readNull()