Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
import subprocess | |
import select | |
from logging import DEBUG, ERROR | |
def call(popenargs, logger, stdout_log_level=DEBUG, stderr_log_level=ERROR, **kwargs): | |
""" | |
Variant of subprocess.call that accepts a logger instead of stdout/stderr, | |
and logs stdout messages via logger.debug and stderr messages via | |
logger.error. |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
> ~/tcp_redis_monitor.py 6379 | |
Timestamp Nb TX bytes RX bytes TX RMA RX RMA | |
1333983822.943 1 0 0 0.000 0.000 | |
1333983823.193 1 0 0 0.000 0.000 | |
1333983824.194 1 0 0 0.000 0.000 | |
1333983825.195 1 0 0 0.000 0.000 | |
1333983826.196 1 0 0 0.000 0.000 |
#!/bin/bash | |
# Script for installing tmux on systems where you don't have root access. | |
# tmux will be installed in $HOME/local/bin. | |
# It's assumed that wget and a C/C++ compiler are installed. | |
# exit on error | |
set -e | |
TMUX_VERSION=1.8 |
val ranges = List((2,3), (1,2), (5,11), (4,10), (3,3), (6,7), (15,16)) | |
ranges.sorted.foldLeft(List[(Int, Int)]()) { (acc, t) => | |
acc match { | |
case x :: xs if x._2 >= t._1 => (x._1, math.max(x._2, t._2)) :: xs | |
case x :: xs => t +: acc | |
case _ => List(t) | |
} | |
}.reverse |
<!doctype HTML> | |
<title>D3 Test</title> | |
<script src="d3.v3.min.js" charset="utf-8"></script> | |
<style type="text/css"> | |
body { | |
margin:0 auto; | |
position:relative; | |
width:958px; | |
} | |
.chart rect { |
// Just before switching jobs: | |
// Add one of these. | |
// Preferably into the same commit where you do a large merge. | |
// | |
// This started as a tweet with a joke of "C++ pro-tip: #define private public", | |
// and then it quickly escalated into more and more evil suggestions. | |
// I've tried to capture interesting suggestions here. | |
// | |
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_, | |
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant, |
select.form-control + .chosen-container.chosen-container-single .chosen-single { | |
display: block; | |
width: 100%; | |
height: 34px; | |
padding: 6px 12px; | |
font-size: 14px; | |
line-height: 1.428571429; | |
color: #555; | |
vertical-align: middle; | |
background-color: #fff; |
from os import chdir, getcwd | |
from os.path import realpath | |
class PushdContext: | |
cwd = None | |
original_dir = None | |
def __init__(self, dirname): | |
self.cwd = realpath(dirname) |