Skip to content

Instantly share code, notes, and snippets.

View joa's full-sized avatar

Joa Ebert joa

View GitHub Profile
@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 / 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) {
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
./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;
@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);
@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 / gist:7446637
Created November 13, 2013 10:07 — forked from anonymous/gist:7446622
static int[] t = {0, 5, 1, 6, 4, 3, 2, 7};
int foo(final byte value) {
int x = value & 0xff;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x *= 0x1d;
x &= 0xff;
x >>= 5;
@joa
joa / Shadowing.java
Created December 15, 2013 17:20
Shadowing fun in Java The first references to x are this.x and afterwards the local variable. The code looks exactly the same but does something completely different.
class Shadowing {
private float x;
public Shadowing(float x) {
this.x = x;
}
public void foo() {
if(x < 0.5f) {
x = Math.round(x);
@joa
joa / gist:8472165
Created January 17, 2014 11:47
Calling super method of an instance does not work in Java, unless you call it on the this pointer from within a Class. C++ even allows you to do this: Derived* x = new Derived(); x->Base::meth();
class Base {
void meth() {
System.out.println("Base::meth");
}
}
class Derived extends Base {
public static void main(String[] args) {
Base x = new Derived();
x.meth();
@joa
joa / glc_circles.js
Created January 6, 2016 12:12
glc circles
function onGLC(glc) {
glc.loop();
glc.size(400, 400);
glc.setDuration(2);
glc.setFPS(60);
glc.setMode('single');
glc.setEasing(false);
var list = glc.renderList,
width = glc.w,
height = glc.h,