Skip to content

Instantly share code, notes, and snippets.

@jeffp123
jeffp123 / get-all-bucket-keys.py
Last active May 19, 2023 10:07
This is a small script to get all keys from a Riak bucket using only standard Python libraries. It can be used as-is to list all keys from a bucket line-by-line, or can be used with other code to do things like purge an entire bucket, or perform some action over all keys in a bucket, etc. It takes advantage of Riak's streaming to grab a list of …
#!/usr/bin/env python
import sys
from optparse import OptionParser
from urlparse import urljoin
import urllib2
import json
DEFAULT_RIAK_URL = "http://localhost:8098/"
@jeffp123
jeffp123 / exec-with-time-limit
Created June 3, 2014 03:54
Exec a script in bash with a time limit
#!/bin/bash
# Get time limit (default is 60 seconds)
if [ $1 == "-t" ]; then
shift
time_limit=$1
shift
else
time_limit=60
fi
@jeffp123
jeffp123 / copy-bucket.py
Last active August 30, 2018 15:13
Copy a Riak Bucket from one server to another
#!/usr/bin/env python
"""Copy two riak buckets"""
import sys
from optparse import OptionParser
import fileinput
import logging
from riak import RiakClient
from multiprocessing import Pool
@jeffp123
jeffp123 / MemoryProfiler
Last active August 29, 2015 14:23
Python 2.3 Compatible Memory Profiler
class MemoryProfiler:
def mem(self, size="rss"):
"""Generalization; memory sizes: rss, rsz, vsz."""
return os.popen('ps -p %d -o %s | tail -1' % (os.getpid(), size)).read()
def rss(self):
"""Return ps -o rss (resident) memory in kB."""
return self.convert_kilobytes(self.mem("rss"))
@jeffp123
jeffp123 / Sample a Motorola SB6121 Surfboard's Signal
Created August 21, 2015 00:28
This script is meant to be run with the Motorola SB6121 Surfboard Modem.
#!/usr/bin/env python
"""Sample the modem's signal
This script is meant to be run with the Motorola SB6121 Surfboard Modem.
If you run it on a different modem, it might not work, but it's worth a try...
It should be run as a cron job, every minute (or whatever interval you'd like)
into a text file. The file can later be used by a json parser to analyze the
signal over time, which can be used to come to conclusions that you can argue
@jeffp123
jeffp123 / nines.py
Created November 6, 2015 01:48
A script to demonstrate the idea that starting at a multiple of 9 and dividing by 2 will yield digits that add up to 9
"""A script to demonstrate the idea that starting at a multiple of 9 and dividing by 2
will yield digits that add up to 9"""
import sys
from decimal import *
DEFAULT_STARTING_VALUE = 360
DECIMAL_PRECISION = 255