Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
print "While:",
n = range(3)
while n:
print n.pop(),
else:
print "else!",
print
@dsc
dsc / count_seqs.sh
Last active December 11, 2015 16:38 — forked from ottomata/count_seqs.sh
# udp2log:
# separate hosts
cd /a/otto/mobile-sleuth.2/udp2log.orig
for host in cp104{1,2,3,4}; do
grep -P "^$host" mobile.2013-01-13_11.45.00-13.15.00.log | awk '{print $2 " " $3}' | sort -n > ../$host.udp2log.seq
done
# hdfs:
# separate hosts
#!/bin/bash
for host in cp104{1,2,3,4}; do
first_seq=$(head -n 1 $host.udp2log.seq | awk '{print $1}') # && echo $first_seq
last_seq=$(tail -n 1 $host.hdfs.seq | awk '{print $1}') # && echo $last_seq
should_be=$(echo "$last_seq - $first_seq + 1" | bc) #&& echo $should_be
# count lines in blog.hdfs.seq file between $first_seq and $last_seq
hdfs_count=$(sed -n -e "/^$first_seq/,/^$last_seq/p" $host.udp2log.seq | wc -l) #&& echo $hdfs_count
@dsc
dsc / blah.co
Created October 23, 2012 16:42
async comparison
fs = require 'fs'
files1 = files2 = null
unless process.argv[2]
err, files1 <- fs.readdir '/Users'
err, files2 <- fs.readdir '/usr'
console.log err, files1, files2
@dsc
dsc / teegram.js
Created October 12, 2012 21:03
Listens for UDP packets, sending the stream to stdout and also teeing it to another port on the local machine.
#!/usr/bin/env node
// Listens for UDP packets, sending the stream to stdout and
// also teeing it to another port on the local machine.
//
// Usage: teegram.js LISTEN_PORT TEE_PORT
var dgram = require('dgram');
@dsc
dsc / gist:3855240
Created October 8, 2012 21:52
Python argparse Cheatsheet
Arg Name or Optional Flags:
positional : str = "foo"
options : str = "-f", "--foo"
Standard:
action : str = [store], append, store_true, store_false, store_const, append_const, version
default : * = [None]
type : callable = [str], argparse.FileType(mode='wb', bufsize=0)
Exotic:
@dsc
dsc / img.py
Created October 8, 2012 21:42
Base class for Python CLI scripts, with example using PIL to display image dimensions on the shell.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Prints image dimensions.
"""
__author__ = 'David Schoonover <dsc@less.ly>'
import sys, re, argparse
from subprocess import Popen, PIPE, STDOUT, check_output
from path import path
from bunch import *
@dsc
dsc / chart.css
Created September 21, 2012 04:10
d3.js: A Sine Graph
svg {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
@dsc
dsc / fix_block_indentation.py
Created September 19, 2012 19:35
Fix Block Indentation TextMate Command
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# TextMate command to correct block indentation for languages with
# semantic whitespace (like Python or CoffeeScript).
#
# Command settings:
# input: Selected Text or Document
# output: Replace Selected Text
# activation: cmd+shift+R
@dsc
dsc / events.coffee
Created September 17, 2012 19:28
events.co
# Technically, this is Coco, not CoffeeScript, but close enough.
{ toString:objToString } = Object::
isArray = Array.isArray or (o) -> objToString.call(o) is '[object Array]'
slice = [].slice
class exports.EventEmitter