Skip to content

Instantly share code, notes, and snippets.

Avatar

Jawher Moussa jawher

View GitHub Profile
@jawher
jawher / enum.go
Created May 30, 2019
mow.cli enum custom type
View enum.go
package enum
import (
"fmt"
"strings"
"github.com/pkg/errors"
)
type Value struct {
View ThymeleafBenchmark.java
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 Jun 2, 2012
Why exceptions suck for a type-checker
View gist:2857929
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
S99 (partial) solutions in Litil, my toy language
View Language highlights
* 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
View Dream.java
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();
}
View flatMap with type params.sbt
[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 Jan 6, 2012
DaizyDiff sample usage
View DaizyDiff.java
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
JAX-RS JSON List<String>
View Resource.java
@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
A sample error stack trace generated by Immanix
View immanixStackTrace
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 Feb 21, 2011
Asus eee pc 1005, Ubuntu 10.10 - Mic works in Sound recorder but not in Skype
View 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 !