Skip to content

Instantly share code, notes, and snippets.

import java.util.Hashtable;
public class Bank {
public static class InsufficientFunds extends Exception {}
final public interface Account {
Integer balance();
void increase (Integer amount);
void decrease (Integer amount);
}
@egonelbre
egonelbre / optimize.patch
Last active August 29, 2015 14:19
encoding optimizations
diff --git a/src/encoding/base64/base64.go b/src/encoding/base64/base64.go
index ad3abe6..bff443f 100644
--- a/src/encoding/base64/base64.go
+++ b/src/encoding/base64/base64.go
@@ -22,7 +22,7 @@ import (
// (RFC 1421). RFC 4648 also defines an alternate encoding, which is
// the standard encoding with - and _ substituted for + and /.
type Encoding struct {
- encode string
+ encode [64]byte
@egonelbre
egonelbre / main.go
Last active August 29, 2015 14:17
Encoding of snapshots
// The latest implementation and stats are at
//
// https://github.com/egonelbre/exp/tree/master/physicscompress
//
//
// Response to Data Compression Challenge
// http://gafferongames.com/2015/03/14/the-networked-physics-data-compression-challenge/
//
// The main insight that this compression uses is
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#define BLOCK (1<<16)
#define MASK (BLOCK - 1)
typedef struct wordcount {
int w0[BLOCK];
int w1[BLOCK];
int w2[BLOCK];
package main
import (
"database/sql"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"
@egonelbre
egonelbre / v1.go
Created January 31, 2015 19:54
bufio.Copy
package egonelbre
import (
"errors"
"io"
)
const (
maxChunk = 16 << 10
)
@egonelbre
egonelbre / egonelbre.go
Last active August 29, 2015 14:14
bufio.Copy
package egonelbre
import (
"io"
"sync/atomic"
)
type process struct {
quit chan struct{}
sleep chan struct{}
@egonelbre
egonelbre / table.go
Last active August 29, 2015 14:14
Hash Table implementation
package main
import (
"crypto/rand"
"fmt"
"time"
)
const (
keysize = 35 // bytes
@egonelbre
egonelbre / foo.go
Last active August 29, 2015 14:10 — forked from rgarcia/foo.go
package foo
type Foo struct {
}
type DB interface {
Find(string) (Foo, error)
}
@egonelbre
egonelbre / imprecision.h
Created October 12, 2014 13:43
making floats packable
// add here more values if more range is needed
#define ilog(x) x < 2 ? 1 : x < 4 ? 2 : x < 8 ? 3 : x < 16 ? 4 : x < 32 ? 8 : x < 64 ? 9 : x < 128 ? 10 : \
x < 256 ? 11 : x < 512 ? 12 : 13
// imprecision macro P4 ( 4 bytes for float )
// (0.00 .. 1.99)
// avg err = 0.00375
// max err = 0.0075
// (2.00 .. 3.99)
// avg err = 0.0075