Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
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 |
#!/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 |
> ~/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 |
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. |