Skip to content

Instantly share code, notes, and snippets.

@bgreenlee
bgreenlee / gist:5305273
Last active December 15, 2015 18:39
Coalesce a list of overlapping start/end tuples
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
@ryin
ryin / tmux_local_install.sh
Last active April 23, 2024 01:06
bash script for installing tmux without root access
#!/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
@dspezia
dspezia / Example log
Created April 9, 2012 15:17
Assessing pending activity of a Redis server
> ~/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
@hrldcpr
hrldcpr / tree.md
Last active June 8, 2024 18:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@bgreenlee
bgreenlee / logging_subprocess.py
Created November 29, 2011 00:58
Variant of subprocess.call that accepts a logger instead of stdout/stderr #python
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.
@snb
snb / virtualbox_ports.png
Created January 24, 2010 01:46
virtualbox serial console
virtualbox_ports.png