Skip to content

Instantly share code, notes, and snippets.

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
@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
### 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 / 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");
@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.
#
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 / Timer.py
Last active August 25, 2017 16:48
import time
# Simple Timer
class Timer:
def __init__(self):
self.reset()
def reset(self):
self._start = time.time()
def elapsed(self): # elapsed time in seconds (float)
# Helper class for statistics
# see: http://www.johndcook.com/blog/standard_deviation/
class Stats:
""" Uses Welford's method to calculate stats.
Assumes positive values.
It's not thread safe
stats = Stats("ConnectionTimeStats")
stats.add(0.223)
stats.add(1.343)
From: https://www.youtube.com/watch?v=BHhA_ZKjyxo
# session management
tmux ls (or tmux list-sessions)
tmux new -s session-name
Ctrl-b d Detach from session
tmux attach -t [session name]
tmux kill-session -t session-name
#include <sys/klog.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
int logsize = klogctl(10 /* SYSLOG_ACTION_SIZE_BUFFER */, 0, 0);
char *bufp = malloc(logsize);
klogctl(3 /* SYSLOG_ACTION_READ_ALL */, bufp, logsize);
write(1, bufp, logsize);