Skip to content

Instantly share code, notes, and snippets.

View joa's full-sized avatar

Joa Ebert joa

View GitHub Profile
@joa
joa / Unchecked.java
Created October 7, 2013 17:37
Unchecked exception handling in Java 8
package brutus.compiler.util;
/**
* import static Unchecked.unchecked
* unchecked(() -> throw new IOException());
*/
public final class Unchecked {
@FunctionalInterface
public static interface UncheckedFunction {
public void apply() throws Throwable;
@joa
joa / Madness.java
Last active December 22, 2015 11:08
package;
public final class Madness {
public static void main(final String[] args) {
final Stack<Integer> stack = new Stack<>();
stack.add(1);
stack.add(2);
stack.add(3);
stack.push(4);
./d8 --print_opt_code script.js
--- Raw source ---
() {
var a = 1|0;
var b = 0|0;
for(var i = 0; i < n; i++) {
t = b;
b = (a+b)|0;
a = t;
implicit class Iif[T](val x: T) extends AnyVal { def iif(cond: => Boolean): Option[T] = if(cond) Some(x) else None }
"yey" iif true == true getOrElse "ney" //yey
"yey" iif true != true getOrElse "ney" //ney
val file = "index.html" iif req.uri == "/" getOrElse req.uri
@joa
joa / App.java
Created August 26, 2012 12:34
HW example
import hiddenwood.concurrent.*;
import hiddenwood.display.*;
import hiddenwood.gl.*;
import hiddenwood.http.*;
class App {
private static final String URL =
"http://www.random.org/integers/?num=1&min=1&max=100000&col=1&base=10&format=plain&rnd=new";
public static void main(String[] args) {
@joa
joa / whitespace.html
Created April 3, 2012 16:19
Having fun with HTML whitespace behaviour
<!DOCTYPE html>
<html>
<head>
<style>
b { font-weight: normal; background-color: #f0f; }
i { font-style: normal; background-color: #ff0; }
pre { background-color: #0ff; }
.arrg { white-space: pre; background-color: #f00; }
body { background: #333; }
</style>
@joa
joa / hiddenwood_javac_madness.java
Created February 24, 2012 18:54
What is the output?
public final class Main {
public static void main(final String[] args) {
while(true) {
try {
System.out.println("1");
continue;
} finally {
System.out.println("2");
break;
}
@joa
joa / ceylon-vs-scala
Created November 18, 2011 14:17
The difference between Ceylon and Scala
// the difference between ceylon and scala
//
shared
class Polar(Float angle, Float radius) {
shared
Float angle = angle;
shared
Float radius = radius;
@joa
joa / webAudioApiTest.js
Created August 30, 2011 09:22
Web Audio API Playback
// #1 Launch Chrome
// #1.1 If you are on the Beta channel you are fine
// #1.2 If you are not on the Beta channel enable Web Audio API in about:flags
// #2 Ctrl+Shift+C or Apple+Shift+J
// #3 Open Console
// #4 Paste
var bufferSize = 2048
var ctx = new webkitAudioContext()
var js = ctx.createJavaScriptNode(bufferSize, 0, 1)
var phase = 0.0
//lift version 2.3-M1
object ErrorSnippet extends DispatchSnippet {
val showBug = true
def dispatch = {
case _ => bug
}
def bug = {
val id = nextFuncName