Skip to content

Instantly share code, notes, and snippets.

@jawher
jawher / enum.go
Created May 30, 2019 12:16
mow.cli enum custom type
package enum
import (
"fmt"
"strings"
"github.com/pkg/errors"
)
type Value struct {
public class ThymeleafBenchmark implements Benchmark {
private Context context;
private TemplateEngine engine;
public ThymeleafBenchmark(Collection<Todo> todos) {
engine = new TemplateEngine();
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templating/clash/thymeleaf/");
templateResolver.setCacheable(true);
engine.setTemplateResolver(templateResolver);
@jawher
jawher / gist:2857929
Created June 2, 2012 11:36
Why exceptions suck for a type-checker
It depends whether you want to implement java-like checked exceptions or not.
In my case, that's not a goal, i.e. I don't want to enforce what exceptions can be thrown in a method, not what exceptions can/must be caught in a catch clause.
I'm using a Hindley-Milner (HM) type system, and a central piece in HM type checking is unification, i.e. trying to make 2 types the same.
For example, when trying to type-check an if-then-else expression, the algorithm will separately analyze the types of the then and else arms, then try to unify them, so you won't end up with something like:
if x > 0 then 5 else "b"
But once you have exceptions in your type system, the unification process gets messier:
@jawher
jawher / Language highlights
Created May 30, 2012 21:36
S99 (partial) solutions in Litil, my toy language
* Hindley-Milner (total) type inference
* Parametric Polymorphism
* Primitive types, Tuples and Algebraic Data Types
* Deep/Structural pattern matching
* Destructuring
* Functions are curried by default
* Clutter-free syntax, and indentation-based blocs à la Python
@jawher
jawher / Dream.java
Created February 23, 2012 16:30
Solution to the puzzles dream : http://wouter.coekaerts.be/2012/puzzle-dreams
class Dream {
public void dream(final Sleeper s) {
new Thread(new Runnable() {
@Override
public void run() {
s.enter(new Dream() {
public void dream(Sleeper s) {
synchronized (s) {
s.notify();
}
@jawher
jawher / flatMap with type params.sbt
Created January 14, 2012 23:01
Really Scala ? Really ?
[info] Compiling 20 Scala sources to /Users/jawher/Dropbox/coding/moulder-s/target/scala-2.9.1/classes...
[error] /Users/jawher/Dropbox/coding/moulder-s/src/main/scala/moulder/moulds/Repeater.scala:19: type mismatch;
[error] found : (A, Int) => List[org.jsoup.nodes.Node]
[error] required: (A, Int) => scala.collection.GenTraversableOnce[org.jsoup.nodes.Node]
[error] data.zip(0 until data.length).flatMap[Node, List[Node]]((item: A, index: Int) => {
[error] ^
@jawher
jawher / DaizyDiff.java
Created January 6, 2012 10:58
DaizyDiff sample usage
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.util.Locale;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
@jawher
jawher / Resource.java
Created May 31, 2011 22:39
JAX-RS JSON List<String>
@Path("/test")
public class Resource {
@GET
@Produces("application/json")
public List<String> pascal() {
return Arrays.asList("a", "b");
}
}
@jawher
jawher / immanixStackTrace
Created May 20, 2011 21:42
A sample error stack trace generated by Immanix
Characters failed: Was expecting 'Characters' but got '</AuthorsText>'
((Until <AuthorsText>)) ~> (Characters) failed due to the previous error
(((Until <AuthorsText>)) ~> (Characters)) <~ ((Until </AuthorsText>)) failed due to the previous error
((((Until <AuthorsText>)) ~> (Characters)) <~ ((Until </AuthorsText>))) <~ ((((Until <PublisherText>)) ~> (Characters)) <~ ((Until </PublisherText>))) failed due to the previous error
(((Until <BookData>)) ~ (((((Until <Title>)) ~> (Characters)) <~ ((Until </Title>))) <~ ((((Until <TitleLong>)) ~> ([Characters])) <~ ((Until </TitleLong>))))) ~ (((((Until <AuthorsText>)) ~> (Characters)) <~ ((Until </AuthorsText>))) <~ ((((Until <PublisherText>)) ~> (Characters)) <~ ((Until </PublisherText>)))) failed due to the previous error
(((Until <BookData>) ~ ((((Until <Title>)) ~> (Characters)) <~ ((Until </Title>))) <~ ((((Until <TitleLong>)) ~> ([Characters])) <~ ((Until </TitleLong>))) ~ ((((Until <AuthorsText>)) ~> (Characters)) <~ ((Until </AuthorsText>))) <~ ((((Until <P
@jawher
jawher / Asus eee pc 1005, Ubuntu 10.10 - Mic works in Sound recorder but not in Skype
Created February 21, 2011 20:06
Asus eee pc 1005, Ubuntu 10.10 - Mic works in Sound recorder but not in Skype
- In skype, options, Sound, uncheck the "Allow skype to adjust mixer levels"
- sudo apt-get install pavucontrol
- pavucontrol
- Go to the input devices tab, and set one of the channels (left/right) volume to 0
- Voila !