Skip to content

Instantly share code, notes, and snippets.

@evacchi
evacchi / Blue.java
Created January 2, 2014 21:09
Blue.Pill -- RuntimeException with NoStackTrace for Java (inspired by Scala's NoStackTrace trait)
/**
* You take the Blue.Pill. You wake up in your bed and believe whatever you want to.
* Usage: <code>throw Blue.Pill</code>, then, somewhere else:
* try { ... } catch (Blue Pill) { /* possibly do something */ }
*
* @author edoardovacchi
*/
public abstract class Blue extends RuntimeException {
public static Blue.Pill Pill = new Blue.Pill();
#!/bin/sh
if [ "$1" == "" ]; then echo USAGE: pdfcompress filename; exit; fi
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$1-compressed.pdf $1.pdf
trait Tree
data object Empty : Tree
data class Leaf(val value: Int) : Tree
data class Node(val left: Tree, val right: Tree) : Tree
fun max(x:Int, y:Int):Int = if (x > y) x else y
fun depth(t: Tree): Int = when (t) {
is Empty -> 0
is Leaf -> 1
@evacchi
evacchi / MyVaadinUI.java
Created January 29, 2015 12:09
HierarchicalMongoContainer Example
package org.tylproject.demos;
import com.mongodb.MongoClient;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Tree;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@evacchi
evacchi / CachingContainerProxy.java
Last active August 29, 2015 14:15
A proxy to Vaadin's Containers that caches items in a Map<Object,SoftReference<Item>>
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.util.filter.UnsupportedFilterException;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.HashMap;
@evacchi
evacchi / grappa_exe.cpp
Created July 10, 2015 16:16
Grappa DYLIB Minimal
// grappa_exe.cpp
namespace PyGrappa {
extern "C" void run();
};
int main(int argc, char **argv){
PyGrappa::run();
}
@evacchi
evacchi / grandchild.scala
Last active January 4, 2016 10:00
Scala-Prolog
trait John
trait Carl
trait Tom
trait Child[T,U]
trait GrandChild[T,U]
implicit val john_carl = new Child[John,Carl]{}
implicit val carl_tom = new Child[Carl,Tom ]{}
implicit def grandChild[X,Y,Z](
@evacchi
evacchi / grandchild.scala
Last active January 21, 2016 12:04
GrandChild (2)
trait John
trait Carl
trait Tom
trait Child[T,U]
trait GrandChild {
type Left
type Right
}
object GrandChild {
type Left[T] = GrandChild { type Left = T }
@evacchi
evacchi / lecturer-example.tex
Last active June 1, 2016 07:33
lecturer.tex playground
\documentclass{article}
\usepackage{luatex85}
\usepackage{luaotfload}
\usepackage{fontspec}
\usepackage{lecturer}
\usepackage{xcolor}
\setmainfont{Gill Sans}
@evacchi
evacchi / sbt-surprising.md
Last active January 1, 2017 17:07
Make SBT less surprising

Inspired by the effort towards better documentation, I'd like to raise a few points about SBT, that I wish could be addressed. I, myself, am not against the DSL per se, but I'd like things to be more explicit. Here's a few examples:

  • an empty or missing build.sbt is a valid project (unless you use sbt-extras)
  • "bare" keys are not scoped per-build, but per-project, although there is no explicit project definition
  • when an explicit root project is missing, sub-projects are auto-aggregated. As you introduce a root project, you'll lose auto-aggregation
  • the project macro fills in the name of the project by "reading" it from the val identifier in lazy val foo = project. This is surprising because it does not behave like regular code. I'd even argue that just using Project might be clearer

other personal observations:

  • scoping is still unclear (to me), because I'd expect subprojects to inherit keys from parents, while we are expected to use inThisBuild or commonSettings