Skip to content

Instantly share code, notes, and snippets.

Avatar

Pablo Acuña pacuna

  • Lyft
  • Austin, TX
View GitHub Profile
@pacuna
pacuna / lmdb.tcl
Created Jan 5, 2021 — forked from antirez/lmdb.tcl
LMDB -- First version of Redis written in Tcl
View lmdb.tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# 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!
View install-protoc-macos-macports.sh
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 Oct 4, 2020 — forked from nf/vm-setup.sh
Script for setting up Debian Jessie VM with my development environment
View vm-setup.sh
#!/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 Oct 3, 2020
SkipList in Go (from original paper)
View skiplist.go
// 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 Oct 3, 2020
Implementing SQLite UDFs and table-valued functions in Python
View sqlite_table_valued.py
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);")
View kpuHJCy8.go
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()
View 6sgN7riQ.go
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.
View U8fs+UoJ.go
type node struct {
mu sync.Mutex
item []byte
key uint64
next *node
}
func (n *node) lock() {
n.mu.Lock()
}
View VCqDGiuN.go
package main
import (
"fmt"
"sortedlist/coarselist"
"sync"
)
func main() {
l := coarselist.New()
View eaU5rn8d.go
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 {