Skip to content

Instantly share code, notes, and snippets.

View joa's full-sized avatar

Joa Ebert joa

View GitHub Profile
server {
listen 80;
server_name konklone.com;
return 301 https://$host$request_uri;
}
# optional: the 'spdy' at the end of the listen command below turns on SPDY support.
server {
listen 443 ssl spdy;
// this will optimize-deoptimize leading to v8 giving
// up on the function
String.prototype.hashCode = function() {
var n = this.length;
var hash = 0;
if(n != 0) {
for(var i = 0; i < n; ++i)
hash = Math.imul(31, hash) + this.charCodeAt(i) | 0;
return hash;
@joa
joa / HTMLOptionElement.js
Created August 1, 2014 12:23
Little JavaScript gem I found
// what does the following code print?
//
// a) false, true
// b) true, true
// c) true, false
// d) none of the above
console.log(new Option() instanceof HTMLOptionElement)
console.log(new HTMLOptionElement() instanceof HTMLOptionElement)
// http://jsperf.com/double2int
function double2int=function(x){
if(isNaN(x))
return 0;
if(x==Infinity||x>0x7fffffff)
return 0x7fffffff;
if(x==-Infinity||x<-0x80000000)
return -0x80000000;
return x|0;
};
// java source
public static void main(String[] args) {
for(int i = 0; i < 10; ++i) {
System.out.println(Color.normalize(255));
System.out.println(i);
}
}
// defrac js
main = function(args){
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.List;
public final class Foo {
public static void main(String[] args) {
final Constructor<?>[] ctors = A.class.getDeclaredConstructors();
for(Constructor<?> ctor : ctors) {
System.out.println(Arrays.toString(ctor.getParameterTypes()));
System.out.println(Arrays.toString(ctor.getGenericParameterTypes()));
//lift version 2.3-M1
object ErrorSnippet extends DispatchSnippet {
val showBug = true
def dispatch = {
case _ => bug
}
def bug = {
val id = nextFuncName
@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
@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 / 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;
}