Skip to content

Instantly share code, notes, and snippets.

@EnigmaCurry
EnigmaCurry / murmur3_hash.py
Last active August 29, 2015 13:57
Example of murmur3 hashing in Jython
from org.apache.cassandra.dht import Murmur3Partitioner
from org.apache.cassandra.utils import ByteBufferUtil
from java.lang import Integer
p = Murmur3Partitioner()
int_token = p.getToken(ByteBufferUtil.bytes(Integer(10)))
string_token = p.getToken(ByteBufferUtil.bytes("asdf"))
Verifying that +enigmacurry is my Bitcoin username. You can send me #bitcoin here: https://onename.io/enigmacurry
@EnigmaCurry
EnigmaCurry / default_logger.py
Created September 16, 2014 19:30
avoding KeyErrors in log formatting
import logging
from collections import defaultdict
from functools import partial
class DefaultFormatter(logging.Formatter):
"""Logging formatter that won't complain of missing fields, replacing them with '...'"""
def __init__(self, fmt=logging.BASIC_FORMAT):
logging.Formatter.__init__(self, fmt)
def format(self, record):
record.__dict__ = defaultdict(partial(str,'...'), record.__dict__)
@EnigmaCurry
EnigmaCurry / temp_nat_dhcp_server.sh
Created December 28, 2014 00:18
A temporary network sharing script - NAT + DHCP
#!/bin/bash
# A temporary internet sharing and DHCP server script.
# Most useful for attaching a raspberry pi directly to a wifi
# connected laptop.
WAN_DEVICE=wlan0
LAN_DEVICE=eth0
SERVER_IP=172.19.22.1
SUBNET=172.19.22.0
@EnigmaCurry
EnigmaCurry / build_python.sh
Created March 22, 2015 15:27
Building an older version of Python for use in virtualenv
PREFIX=/opt/python
VERSION=2.7.8
mkdir -p $PREFIX/src
cd $PREFIX/src
wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tar.xz
tar xfv Python-$VERSION.tar.xz
cd Python-$VERSION
./configure --prefix=/opt/python/Python-$VERSION
make
@EnigmaCurry
EnigmaCurry / client_secrets.md
Created April 26, 2015 17:10
cstar_perf client_secrets.json

cstar_perf uses Google APIs for authentication purposes. If you are installing cstar_perf for yourself you will need to generate your own API token for use with your installed version.

Image

Enter whatever Project Name you want (maybe use cstar-perf.) Use the suggested Project ID (doesn't matter, just has to be unique.)

It will take a minute for the project to be created, once it has:

#!/bin/bash
## Run a script inside a screen session.
## Keeps the screen session active after the process is done.
## Logs to a file with the same name as SCREEN_NAME
if [ $# != 2 ] ; then
echo "Usage: run_screen SCREEN_NAME SCRIPT"
exit 1;
fi
@EnigmaCurry
EnigmaCurry / |etc|dhcpcd.conf
Last active August 29, 2015 14:22
Local DNS server for choosing different upstream DNS servers based on domain name
#At the end of the file, makes it so resolv.conf isn't overwitten by dhcp
#Probably not necessary since we chattr +i the file though
nohook resolv.conf
@EnigmaCurry
EnigmaCurry / copy_ssh_id.sh
Last active August 29, 2015 14:23
A better ssh-copy-id
# Copy an SSH key to multiple accounts on multiple machines.
# Better than ssh-copy-id because it works with systems that don't
# use passwords over ssh.
echo "Enter the ssh pub key: "
read PUBKEY
echo "Enter the hosts to copy the key to (separated by space)"
read HOSTS
HOSTS=(${HOSTS// / })
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Hyperlink JIRA ticket numbers for DataStax projects
;;
;; For example, all of these tickets should be clickable when
;; bug-reference-prog-mode or bug-reference-mode are enabled :
;;
;; CASSANDRA-8099
;; PYTHON-363
;; TESTINF-386
;; DSP-6091