Skip to content

Instantly share code, notes, and snippets.

function role(roleplayer, role)
local mt = getmetatable(roleplayer)
setmetatable(role, mt)
setmetatable(roleplayer, role)
end
function striprole(roleplayer)
setmetatable(roleplayer, getmetatable(getmetatable(roleplayer)))
end
local function Battle(Lion, Bear)
-- add Bear role methods
function Bear.fight()
Bear.say("roar...")
Lion.fight()
end
-- add Lion role methods
function Lion.fight()
Lion.say("meow...")
@egonelbre
egonelbre / set.go
Last active August 29, 2015 14:07
sorted set iterator benchmark
package sortedset
type bucket uint16
const (
bits = 15 // bits per bucket
cbit = 1 << bits // continuation bit
mask = cbit - 1 // bits mask
)
From "Applicability Statement for Secure Health Transport" at 2.1 it says that
A Health Content Container (prior to signing and encrypting, as otherwise described in
this document) SHALL be an Internet Message Format document conforming to RFC 5322.
Now the Unwrapped message, as sent out by TTT, is not a proper IMF, it is missing the necessary headers.
The specification says that we must implement the following. (I'm using mathy notation because it will be easier to follow than words)
First we have an HCC: [2.1]
package set
type Hash int64
type Elem interface {
Hash() Hash
Equals(e Elem) bool
}
type Set struct {
buckets map[Hash][]Elem
package main
import (
"fmt"
"sync"
)
type errors []error
func (e errors) Error() string {
package main
import (
"fmt"
"gopkg.in/tomb.v2"
)
type Pipeline struct {
tomb.Tomb
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"sort"
"strings"
"time"
// State Machine Library
function Machine(first, $){
var cur = {}, next = $[first];
var self = {
go: function(to){ next = next ? next : ($[to] || $.undefined); },
trigger: function(event){ var t = cur.tx && cur.tx[event]; t && self.go(t); }
};
return function(){
if(next){
@egonelbre
egonelbre / astar_nodequeue.go
Last active June 29, 2023 09:43
Go A* implementation
package astar
import "container/heap"
type NodeQueue []Node
func NewNodeQueue() NodeQueue {
return make(NodeQueue, 0, 1000)
}