Skip to content

Instantly share code, notes, and snippets.

View martijndwars's full-sized avatar

Martijn Dwars martijndwars

View GitHub Profile
plugins {
id 'java'
}
repositories {
jcenter()
}
dependencies {
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
@martijndwars
martijndwars / demo.md
Created July 1, 2019 07:06
PGX JShell demo

Demo

Start shell

$ ./jshell/pgx.sh

Show predefined variables

@martijndwars
martijndwars / gist:5e9c2cc72820f00699d1e3388072ef4f
Created June 11, 2019 11:25
Compile on Java 8, run on Java 11
martijn@dhcp-10-175-42-124:/p/t/javatest$ cat Main.java
import sun.misc.Unsafe;
import java.lang.reflect.Field;
public class Main {
public static void main(String[] args) throws Exception {
Unsafe unsafe = getUnsafe();
System.out.println("Page size = " + unsafe.pageSize());
}
@martijndwars
martijndwars / build.gradle
Last active January 23, 2019 11:16
Gradle incrementality/task dependency example
task C {
doLast {
println("Do C")
}
}
task A(dependsOn: C) {
doLast {
println("Do A")
}
@martijndwars
martijndwars / Instructions.md
Last active December 12, 2017 10:34
Parse a string in a .spoofax-language using Scala's REPL

Create an empty project with SBT:

sbt new sbt/scala-seed.g8

Update build.sbt to contain the Metaborg repository:

import Dependencies._
@martijndwars
martijndwars / README.md
Created November 27, 2017 14:36
Java 8 stream are lazy. Or not?

I've always learned that Java 8 streams are lazy. As such, I would expect that:

Optional<Integer> intOpt = Stream
  .of(1, 2, 3)
  .flatMap(i -> Stream.of(4, 5, 6))
  .filter(i -> {System.out.println(i); return true;})
  .findAny();
@martijndwars
martijndwars / notes.md
Last active September 27, 2016 17:59
IN4303 Lab 2 notes

This document explains some aspects of Spoofax that we got questions about. It also describes some common mistakes and pitfalls. Finally, it describes Spoofax' internals more in-depth, with the goal of clarifying some of its behaviour.

  • Disambiguation tests. Disambiguation tests are tests of the form test ... [[1+2+3]] parse to [[(1+2)+3]]. SPT will parse both fragments and compare the ASTs. A common mistake is to introduce a constructor when parsing parenthesized expressions, e.g. Exp.Parens = <(<Exp>)>. When you make this mistake, the AST for the second fragment will contain Parens nodes and hence be different from the AST for the first fragment.

The solution is to not introduce a constructor. This is semantically cleaner anyway, as a Parens node does not convey any semantic content (remember: the AST is a tree, not a string, and as such it already encodes what you would otherwise achieve by adding parenthesis). Spoofax will show an error "Missing bracket attribute or constructor name" whi

@martijndwars
martijndwars / push.js
Created August 30, 2016 21:43
push.js
$(function () {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(initialiseState);
} else {
console.warn('Service workers are not supported in this browser.');
}
});
function initialiseState() {
if (!('showNotification' in ServiceWorkerRegistration.prototype)) {
### Keybase proof
I hereby claim:
* I am martijndwars on github.
* I am martijndwars (https://keybase.io/martijndwars) on keybase.
* I have a public key ASCjzLNxLHlexZfNDGu9sVMBtIxE-kax2HPwmJh5rPWDtgo
To claim this, I am signing this object: