Skip to content

Instantly share code, notes, and snippets.

View gabro's full-sized avatar

Gabriele Petronella gabro

View GitHub Profile
@gabro
gabro / sublime.tex
Created December 2, 2012 00:25
LaTeX example
\documentclass{article}
\title{LaTeX is now Sublime}
\author{Gabriele Petronella}
\begin{document}
\maketitle
\section{My first section}
@gabro
gabro / main.tex
Created December 7, 2012 19:23
An example of a multi-part LaTeX document
\documentclass{article}
\title{A long document}
\author{Gabriele Petronella}
\date{\today}
\begin{document}
\maketitle
@gabro
gabro / gist:4322163
Created December 17, 2012 20:57
A parametric algebraic data type in Haskell
data UnionFindElement valueType =
RootElement valueType |
ElementWithParent valueType (UnionFindElement valueType)
deriving (Eq, Show)
@gabro
gabro / Money Chicago
Last active December 11, 2015 03:08
Money Chicago
var money =
"@people: luca gio dani gabro claudio jaja mike paolo\n"+
"@group: luca gio dani gabro claudio jaja\n"+
"@date: debiti e payback\n"+
"~Debiti (Dani 52.13 Luca 356.37 Gabro 13.18) claudio 309.88 gio 28.98 jaja 17.25 mike 64.51\n"+
"15 gio -> dani\n"+
"400 claudio -> gabro\n"+
"10 dani -> jaja\n"+
@gabro
gabro / user.js
Created February 27, 2013 22:45
node-example
var userSchema = new Schema(
fb_id : String,
firstName : String,
lastName : String,
messages : [{
content : String,
positive : Boolean,
author : User,
created_at : {type : Date, default : Date.now},
updated_at : {type : Date, default : Date.now}
@gabro
gabro / git-working-history
Last active March 27, 2023 09:47
Github-like working directory history
#!/bin/bash
FILES=`git ls-tree --name-only HEAD .`
MAXLEN=0
IFS=$(echo -en "\n\b")
for f in $FILES; do
if [ ${#f} -gt $MAXLEN ]; then
MAXLEN=${#f}
fi
done
package buildo
import anorm._
import shapeless._
import shapeless.ops.hlist._
import shapeless.record._
import shapeless.syntax.std.traversable._
import shapeless.syntax.singleton._
@gabro
gabro / gist:b192a7258ec5072bd1e0
Created September 12, 2014 10:17
Beautiful validation with scalaz. Fail fast in the for-comprehension and fail slow with the application builder
def editResult(testId: LabOnlineId[Test], worklistId: LabOnlineId[Worklist], result: TestResult): Future[ActionResult] =
for {
test <- ensureExists(testId)(testData.findOne(_))
sample <- ensureExists(test._sampleId)(sampleData.findOneWithWorklist(_, worklistId))
} yield {
(ensureNotClosed(sample, worklistId) |@|
ensureNotClosed(test, worklistId))((_,_)) match {
case Failure(errors) => ActionResult.UserError(errors.toList: _*)
case Success(_) => /* run a stored procedure */ ActionResult.Ok
}
@gabro
gabro / A
Created September 13, 2014 14:56
Var length generator
def gen(n: Int, limit: Int, k: Int = 1): Iterator[List[Int]] = {
val range = (k until limit).iterator
n match {
case _ if n > 0 => for {
x <- range
y <- gen(n - 2, limit, x)
} yield x :: y
case _ => range.map(List(_))
}
}
@gabro
gabro / Main.scala
Last active August 29, 2015 14:11
Automatic get parameters generator from case class for spray routing
package example
import scala.language.existentials
import shapeless._; import record._; import ops.record._; import ops.hlist._
import spray.routing.SimpleRoutingApp
trait AutoGetParametersModule { self: SimpleRoutingApp =>
import spray.routing.{ Directive, Directive1, Directive0, HListDeserializer }