Skip to content

Instantly share code, notes, and snippets.

View martijndwars's full-sized avatar

Martijn Dwars martijndwars

View GitHub Profile
### 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:
org.metaborg.core.analysis.AnalysisException: Analysis for eclipse:///MiniJava/tests/lab6/constraints/main-class/main-class-instantiation.spt failed
at org.metaborg.spoofax.core.analysis.legacy.StrategoAnalyzer.analyze(StrategoAnalyzer.java:203) ~[org.metaborg.spoofax.core_2.0.0.20160612-002403-master.jar:na]
at org.metaborg.spoofax.core.analysis.legacy.StrategoAnalyzer.analyze(StrategoAnalyzer.java:99) ~[org.metaborg.spoofax.core_2.0.0.20160612-002403-master.jar:na]
at org.metaborg.spoofax.core.analysis.legacy.StrategoAnalyzer.analyze(StrategoAnalyzer.java:1) ~[org.metaborg.spoofax.core_2.0.0.20160612-002403-master.jar:na]
at org.metaborg.core.analysis.AnalysisService.analyze(AnalysisService.java:27) ~[org.metaborg.core_2.0.0.20160612-002403-master.jar:na]
at org.metaborg.spoofax.core.analysis.SpoofaxAnalysisService.analyze(SpoofaxAnalysisService.java:17) ~[org.metaborg.spoofax.core_2.0.0.20160612-002403-master.jar:na]
at org.metaborg.spoofax.core.analysis.SpoofaxAnalysisService.analyze(SpoofaxAnalysis
@martijndwars
martijndwars / Encrypted.java
Created March 6, 2016 21:51
Web push in Java
import java.security.PublicKey;
public class Encrypted {
private final PublicKey publicKey;
private final byte[] salt;
private final byte[] ciphertext;
public Encrypted(final PublicKey publicKey, final byte[] salt, final byte[] ciphertext) {
this.publicKey = publicKey;
this.salt = salt;
@martijndwars
martijndwars / names.nab
Last active December 15, 2015 09:11
NaBL required reference
module names
namespaces
Global
binding rules
Class(c, _):
defines Global c
@martijndwars
martijndwars / combinations.str
Last active January 31, 2019 15:25
Permutations and combinations of a list in StrategoXT
/**
* Given a length m and elements xs, generate all combinations of length m
* from the elements in xs.
*
* @type (int, List(a)) -> List(List(a))
*/
combinations:
(0, _) -> [[]]
combinations:
@martijndwars
martijndwars / OptionValue.scala
Last active January 4, 2016 12:29
Algorithm to value a path-independent American put option in the binomial model. Up-factor u=2, down-factor d=1/u, s=4 and expiry is at time N, such that the risk neutral probabilities p=q=1/2. The function g determines the intrinsic value (value if exercises immediately). By changing the function g one can value different kinds of American opti…
object OptionValue {
val N = 2
val u: Double = 2
val d: Double = 1/u
def main(args: Array[String]): Unit = {
println(v(0,4,(s: Double) => 0.0 max (4.0-s)))
}
def v(n: Double, s: Double, g: Double => Double): Double =
@martijndwars
martijndwars / valuation.r
Last active December 25, 2015 14:09
R code to calculate option value recursively backward in the binomial asset pricing model.
p <- 1/2;
u <- 2;
d <- 1/u;
r <- 1/4;
v <- function(n, s) {
if (n == 3) {
return(pmax(s-10, 0));
}
@martijndwars
martijndwars / rc4drop.js
Last active December 20, 2015 14:59
Nodes crypto module provides a rc4 cipher, but it lacks the ability to drop the first bytes from the keystream. This gist simply encrypts as many bytes as you want to drop, effectively causing those bytes from the keystream to get dropped. For full implementations of RC4Drop, please see: - https://github.com/gwjjeff/cryptojs - https://gist.githu…
crypto = require 'crypto'
class RC4
constructor: (@key, drop) ->
@cipher = crypto.createCipher 'rc4', key
if drop > 0
this.cipher.update new Buffer drop
encrypt: (data) ->
@cipher.update data