Skip to content

Instantly share code, notes, and snippets.

View pacuna's full-sized avatar

Pablo Acuna pacuna

  • Spotify
  • Austin, TX
View GitHub Profile
@pacuna
pacuna / lmdb.tcl
Created January 5, 2021 13:57 — forked from antirez/lmdb.tcl
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <[email protected]>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!
sudo port install automake libtool autogen autoconf
wget https://github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz
tar -xzvf protobuf-3.14.0.tar.gz
cd protobuf-3.14.0
./autogen.sh
./configure
make
sudo make install
go install google.golang.org/protobuf/cmd/protoc-gen-go # run outside of project with module, add $GOBIN to $PATH
@pacuna
pacuna / vm-setup.sh
Created October 4, 2020 14:48 — forked from nf/vm-setup.sh
Script for setting up Debian Jessie VM with my development environment
#!/bin/bash -e
echo '
PATH=$HOME/go/bin:$PATH
export GOPATH=$HOME
export CDPATH=.:$HOME/src/golang.org/x:$HOME/go/src:$HOME/src/github.com:$HOME/src/github.com/nf:$HOME/src/github.com/adg
export EDITOR=vim
' >> ~/.profile
sudo apt-get update
@pacuna
pacuna / skiplist.go
Created October 3, 2020 23:17
SkipList in Go (from original paper)
// Implementation of a SkipList using the original paper's algorithm:
// https://15721.courses.cs.cmu.edu/spring2018/papers/08-oltpindexes1/pugh-skiplists-cacm1990.pdf
//
// Example usage:
// sl := db.NewSkipList()
// sl.Insert([]byte("foo"), []byte("bar"))
// sl.Insert([]byte("foo"), []byte("world"))
// fmt.Println(string(sl.Search([]byte("foo"))))
//
package db
@pacuna
pacuna / sqlite_table_valued.py
Last active October 3, 2020 23:20
Implementing SQLite UDFs and table-valued functions in Python
from peewee import *
from playhouse.sqlite_ext import TableFunction
import json
# https://github.com/coleifer/peewee/
# Basic connection and sql execution
db = SqliteDatabase('foo.db')
db.connect()
db.execute_sql(
"CREATE TABLE IF NOT EXISTS pageAds (pageid STRING, adid_list JSON);")
func (l *list) Remove(item []byte) bool {
key, _ := hashstructure.Hash(item, nil)
l.head.lock()
pred := l.head
curr := pred.next
curr.lock()
for curr.key < key {
pred.unlock()
func (l *list) Add(item []byte) bool {
key, _ := hashstructure.Hash(item, nil)
l.head.lock()
pred := l.head
curr := pred.next
curr.lock()
// Displace locks during each iteration.
// We keep the lock for curr when unlocking pred.
type node struct {
mu sync.Mutex
item []byte
key uint64
next *node
}
func (n *node) lock() {
n.mu.Lock()
}
package main
import (
"fmt"
"sortedlist/coarselist"
"sync"
)
func main() {
l := coarselist.New()
func (l *list) Add(item []byte) bool {
var pred, curr *node
key, _ := hashstructure.Hash(item, nil)
l.mu.Lock()
defer l.mu.Unlock()
pred = l.head
curr = pred.next
for curr.key < key {