Skip to content

Instantly share code, notes, and snippets.

View marconi's full-sized avatar

Marconi Moreto Jr marconi

View GitHub Profile
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func main() {
@marconi
marconi / hash_func_and_stuff.go
Created April 2, 2016 03:20
Hash functions and incomplete consistent hashing.
package main
import (
"fmt"
"hash/adler32"
"hash/crc32"
"hash/fnv"
"github.com/spaolacci/murmur3"
)
@marconi
marconi / ring_buffer.go
Created April 2, 2016 03:18
Ring buffer example.
package main
import "fmt"
type RingBuffer struct {
size int
buffer []int
head int
tail int
}
package main
import (
"fmt"
"log"
"net/http"
"strings"
"time"
)
@marconi
marconi / flatten.py
Last active March 10, 2016 02:44
Flatten arbitrarily nested arrays of integers.
import numbers
def flatten(xs):
"""
# Flatten arbitrarily nested arrays of integers
# e.g. [[1, 2, [3]], 4] -> [1, 2, 3, 4]
"""
# if not list, return single item list but only if its a number
if not isinstance(xs, list):
@marconi
marconi / compress-url-list.py
Created November 7, 2014 12:33
Space complexity using trie
from pprint import pprint
class Node(dict):
char = None
def __init__(self, char):
self.char = char
def __str__(self):
@marconi
marconi / gist:8129975
Created December 26, 2013 04:56
Compute total number of hours of all avi, mkv and mp4 videos on a directory.
import os
import sys
from hachoir_metadata import extractMetadata
from hachoir_parser import createParser
def getinfo(rootdir, extensions=(".avi", ".mp4", ".mkv")):
if not isinstance(rootdir, unicode):
rootdir = rootdir.decode(sys.getfilesystemencoding())
for dirpath, dirs, files in os.walk(rootdir):
...
var tplCache *template.Template
...
func init() {
CacheTemplates()
}
@marconi
marconi / gofetch.go
Last active February 12, 2016 11:07
Downloads file by splitting it into multiple download workers making download faster.
package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"math"
"net/http"
@marconi
marconi / postgis_template.sh
Created July 10, 2013 19:15
Creating template_postgis template for postgresql database in OSX mountain lion with components installed via homebrew.
createdb template_postgis -E UTF-8
createlang plpgsql template_postgis
psql -d template_postgis -f /usr/local/Cellar/postgis/2.0.3/share/postgis/postgis.sql
psql -d template_postgis -f /usr/local/Cellar/postgis/2.0.3/share/postgis/spatial_ref_sys.sql
psql -d postgres
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
createdb -T template_postgis <db name>