Skip to content

Instantly share code, notes, and snippets.

@Turin86
Turin86 / RateLimiter.py
Last active August 29, 2015 14:23
Small Python class for generic throttling
from datetime import datetime
class RateLimiter:
def __init__(self, seconds=1):
self.count = 0
self.last_time = datetime.now()
self.seconds = float(seconds)
self.step = 1
def stepping(self):
@Turin86
Turin86 / colortext.py
Last active May 12, 2017 07:17
Color text based on ANSI color codes
# http://en.wikipedia.org/wiki/ANSI_escape_code
color_code_template = """\x1b[{}m"""
colors = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
color_codes = dict(zip(colors, range(len(colors))))
bold_code = 1
clear_code = 0
def get_code(code):
return color_code_template.format(code)
@Turin86
Turin86 / Backoff.py
Last active December 18, 2017 10:33
Utility class for exponential backoff
# https://code.google.com/p/google-api-python-client/source/browse/samples/threadqueue/main.py?spec=svn67b8dcf946169e1ad62ecb0555942865b9186ea8&r=67b8dcf946169e1ad62ecb0555942865b9186ea8
from __future__ import print_function
from random import randint
import sys
from time import sleep
class Backoff:
"""Exponential Backoff
@Turin86
Turin86 / capnames.py
Last active August 29, 2015 14:23
Utility function to properly capitalize names
def capnames(line):
if isinstance(line, basestring):
was_string = isinstance(line, str)
if was_string:
line = line.decode('utf-8')
line = line.lower() \
.replace(u'otoole', u'o\'toole') \
.replace(u'\\', u'')
line = u'-'.join(_.strip() for _ in line.split(u'-'))
line = u"'".join(_.strip() for _ in line.split(u"'"))
@Turin86
Turin86 / WSSoapClient.php
Last active April 24, 2023 19:37 — forked from johnkary/WSSoapClient.php
WS-Security for PHP SoapClient
<?php
/**
* This class can add WSSecurity authentication support to SOAP clients
* implemented with the PHP 5 SOAP extension.
*
* It extends the PHP 5 SOAP client support to add the necessary XML tags to
* the SOAP client requests in order to authenticate on behalf of a given
* user with a given password.
*
@Turin86
Turin86 / mbox_send.py
Last active October 3, 2016 23:47 — forked from wojdyr/mbox_send.py
A Python script that (re-)sends all messages in mbox files with From/To/Cc/Bcc as specified in the messages headers
#!/usr/bin/env python
"""\
A command-line utility that can (re)send all messages in an mbox file
to a specific email address, with options for controlling the rate at
which they are sent, etc.
"""
# I got this script from Robin Dunn a few years ago, see
# https://github.com/wojdyr/fityk/wiki/MigrationToGoogleGroups