Skip to content

Instantly share code, notes, and snippets.

@stupidbodo
stupidbodo / consistent-hashing.py
Created December 31, 2015 02:46
Consistent Hashing Example - Python
from hashlib import md5
from bisect import bisect
class Ring(object):
def __init__(self, server_list, num_replicas=3):
nodes = self.generate_nodes(server_list, num_replicas)
hnodes = [self.hash(node) for node in nodes]
hnodes.sort()
@stupidbodo
stupidbodo / supervisord.init
Created April 8, 2015 19:17
Supervisord Init
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath <[email protected]> (based off yumupdatesd)
# Jason Koppe <[email protected]> adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Mikhail Mingalev <[email protected]> Merged
# redhat-init-jkoppe and redhat-sysconfig-jkoppe, and
@stupidbodo
stupidbodo / cron.go
Last active November 3, 2020 18:15
Golang - Keep more than 1 program running forever (similar to cron job but shorter interval)
package main
import (
"fmt"
"runtime"
"time"
)
var (
INTERVAL_SEC = 10
@stupidbodo
stupidbodo / testing-example.py
Last active August 29, 2015 14:16
Python Testing Example - How to mock property for testing
import unittest
import mock
class Trainer(object):
@property
def column_names(self):
return ["one", "two"]
@stupidbodo
stupidbodo / aerospike-scan.go
Last active August 29, 2015 14:14 — forked from khaf/gist:50809b45ba5645f9f80c
Aerospike Golang Scan
package main
import (
"log"
"math"
"runtime"
"time"
as "github.com/aerospike/aerospike-client-go"
)
@stupidbodo
stupidbodo / aes_encryption.go
Last active January 3, 2024 10:29
AES Encryption Example in Golang
// Playbook - http://play.golang.org/p/3wFl4lacjX
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
@stupidbodo
stupidbodo / aes_encryption.py
Last active August 7, 2020 11:09
AES Encryption Example in Python
from base64 import urlsafe_b64encode, urlsafe_b64decode
from Crypto.Cipher import AES
from Crypto import Random
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s: s[:-ord(s[len(s) - 1:])]
base64pad = lambda s: s + '=' * (4 - len(s) % 4)
@stupidbodo
stupidbodo / timezone.py
Created December 19, 2014 19:51
Timezone Choices
TIMEZONE_CHOICES = (
('US/Hawaii', '(UTC-1000) Hawaii time'),
('America/Atka', '(UTC-0900) Alaska time'),
('Pacific/Pitcairn', '(UTC-0800) Pitcairn time'),
('America/Dawson', '(UTC-0700) Dawson time'),
('America/Dawson_Creek', '(UTC-0700) Dawson Creek time'),
('America/Hermosillo', '(UTC-0700) Hermosillo time'),
('America/Los_Angeles', '(UTC-0700) Los Angeles time'),
('America/Vancouver', '(UTC-0700) Vancouver time'),
('America/Phoenix', '(UTC-0700) Phoenix time'),
@stupidbodo
stupidbodo / csv.go
Last active February 12, 2024 07:05
Golang - Read CSV/JSON from URL
package main
import (
"encoding/csv"
"fmt"
"net/http"
)
func readCSVFromUrl(url string) ([][]string, error) {
resp, err := http.Get(url)
@stupidbodo
stupidbodo / pyscript.py
Last active December 2, 2018 14:31 — forked from nhoffman/pyscript.py
#!/usr/bin/env python
"""A simple python script template.
"""
import os
import sys
import argparse