Skip to content

Instantly share code, notes, and snippets.

import time
from collections import deque
from Queue import Queue
# Adding some control to Queue class
class ProcessQueue(Queue):
""" Extends Queue to add some control methods
Assumes only blocking put and get will be used
There's 2 common patterns to consume items from Queue
that are noisy and/or error prone:
@lucindo
lucindo / BackoffSession.py
Created September 11, 2016 00:20
Backoff for requests.Session
## Backoff for resquests.Session
#
# A common pattern for me when using the requests library is
# to make several HTTP requests to an endpoint using a Session
# in order to mantain an open connection to the server.
#
# Many times I had to set requests.adapters.DEFAULT_RETRIES to
# some value in order to avoid transient errors that a simple
# retry would take care of.
#
@lucindo
lucindo / log4j.java
Created October 18, 2016 19:26
Quick&Dirty Log4J conf (inline)
import java.util.Properties;
import org.apache.log4j.PropertyConfigurator;
class MyDummyApp {
public static void main(String []args) {
Properties properties=new Properties();
properties.setProperty("log4j.rootLogger","DEBUG,stdout");
properties.setProperty("log4j.rootCategory","DEBUG");
properties.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
### Keybase proof
I hereby claim:
* I am lucindo on github.
* I am lucindo (https://keybase.io/lucindo) on keybase.
* I have a public key ASBTuwODc0m6t_FcXwRVlIQKzAkgfuWI6ZNIz3TS_ZxP9Ao
To claim this, I am signing this object:
@lucindo
lucindo / csvsplitter.py
Created July 11, 2017 15:57
Splits CSV files by line
import csv
import sys
if __name__ == '__main__':
if len(sys.argv) != 3:
sys.exit("%s <csv-file> <lines>" % sys.argv[0])
infile, total = sys.argv[1], int(sys.argv[2])
basename = infile.split('.csv')[0]
output_count = 0
output_handler, file_handler = None, None
2017-1-2 59589
2017-1-3 61814
2017-1-4 61589
2017-1-5 62071
2017-1-6 61665
2017-1-9 61700
2017-1-10 62132
2017-1-11 62446
2017-1-12 63954
2017-1-13 63652