Skip to content

Instantly share code, notes, and snippets.

View aristus's full-sized avatar

Carlos Bueno aristus

View GitHub Profile
#!/usr/bin/python
## gitsh (pronounced like "glitch"), an interactive wrapper for git.
##
## gitsh parses the output of "git status" and numbers the files for
## you, for easy operations on multiple files.
##
## $ gitsh status
## 1) M foo/bar.py
## 2) M foo/baz.py
## 3) A blah.sh
@aristus
aristus / gist:5631426
Created May 22, 2013 22:23
sampling 10,000 random numbers 1:100
import random
runs = 10000
rate = 100
for _ in range(50):
real_sum = 0
real_cnt = 0
est_sum = 0
est_cnt = 0
from hashlib import md5
bloom = 0b0
num_bits = 512
def add_to_bloom(s):
global bloom
# int representation of the hashed value
hash = int(md5(s.encode('utf8')).hexdigest(), 16)
@aristus
aristus / healthcheck.py
Last active January 4, 2016 18:28
MemSQL healthcheck server
from flask import Flask
import torndb
## NB: this default query does not exercise leaf connectivity or
## partition health. For best results, use a query that selects
## a record from an actual data table.
SQL = "select count(1) from information_schema.processlist"
## SQL = "select * from dashboard.analytics limit 1"
## SQL = "show databases extended"
CREATE TABLE `analytics` (
`classifier_id` bigint unsigned,
`ts_msec` bigint unsigned,
`value` double,
PRIMARY KEY (`classifier_id`,`ts_msec`),
KEY `ts_msec` (`ts_msec`)
);
CREATE /*!90618 REFERENCE*/ TABLE `classifiers` (
`id` bigint(20) unsigned NOT NULL,
--- ext/standard/string.c (revision 301280)
+++ ext/standard/string.c (working copy)
@@ -1674,6 +1674,105 @@
}
/* }}} */
+#define FASTSEARCH_MIN 50
+
+/*
+ * Implementation of "fastsearch" algorithm devised by
@aristus
aristus / swap-usage.sh
Created June 9, 2014 16:03
swap-usage.sh
#!/bin/bash
# find-out-what-is-using-your-swap.sh
# -- Get current swap usage for all running processes
# --
# -- rev.0.3, 2012-09-03, Jan Smid - alignment and intendation, sorting
# -- rev.0.2, 2012-08-09, Mikko Rantalainen - pipe the output to "sort -nk3" to get sorted output
# -- rev.0.1, 2011-05-27, Erik Ljungstrom - initial version
#!/usr/bin/env python2.7
# Note: this script is for manual benchmarking!
# ./benchmark init-spatial
# time ./benchmark write-spatial
# ./benchmark read-spatial
from memsql.common import connection_pool
import random, math, sys
import basin
import string
from hashlib import sha1
## Fixed-length compact ids for compound keys. Given one or more strings, this will
## concat with delim (default '|'), sha1 hash the result, convert to the given base
## (default 62), truncate to the given length (default 12) and left-pad with zeros.
##
## *** WARNING MATH AHEAD ***
## Here's a handy way to approximate the birthday number for a given bitspace and a
@aristus
aristus / .pythonrc
Created November 16, 2015 21:55
Useful constants for capacity planning.
import math,re
# binary "oodles of magnitude"
KB = 2 ** 10
MB = 2 ** 20
GB = 2 ** 30
TB = 2 ** 40
PB = 2 ** 50
# decimal "oodles of magnitude"