Skip to content

Instantly share code, notes, and snippets.

View x's full-sized avatar
🐦

Devon Peticolas x

🐦
View GitHub Profile
@x
x / gist:4ccbf329d70cf74ecec8
Created July 7, 2014 15:52
find port of process
ps aux # get the pid
netstat -tulpn | grep PID
@x
x / gist:21fd81938df43d3ef742
Created July 29, 2014 17:38
top processes by memory
ps aux --sort -pmem | head
@x
x / gist:93793c12003b1312ffda
Created July 30, 2014 11:56
get s3 files by grep
s3cmd ls s3://S3_BUCKET | grep PATTERN | tr -s ' ' | cut -d' ' -f4- | xargs s3cmd get
@x
x / gist:86892f50894cc2e46602
Created July 30, 2014 18:29
Named Tuple vs Dict Vs Tuple
$ python -m timeit -s 'from collections import namedtuple; NT = namedtuple("NT", "a"); nt = NT(1)' 'nt.a'
10000000 loops, best of 3: 0.138 usec per loop
/U/d/chartbeat(dev)(master)$ python -m timeit -s 'd = (1, )' 'd[0]'
10000000 loops, best of 3: 0.0409 usec per loop
/U/d/chartbeat(dev)(master)$ python -m timeit -s 'd = {"a": 1}' 'd["a"]'
10000000 loops, best of 3: 0.0358 usec per loop
@x
x / gist:ae168992c33024d9d4c9
Created August 6, 2014 21:57
kill by grep
ps aux | grep FOOBARBAZ | tr -s ' ' | cut -d' ' -f2 | xargs kill -9
@x
x / gist:07b6c260b666e1c5cc5f
Created October 16, 2014 21:14
get collections with unique indexes
db.getCollectionNames().filter(function(col){return db[col].getIndexes().filter(function(idx){return idx.unique}).length})
@x
x / gist:b89172e7304e40bb4484
Last active August 29, 2015 14:09
clojure kafka consumer
(ns test-kafka.core
(:gen-class)
(:require [clj-kafka.consumer.zk :refer :all]
[clj-kafka.core :refer :all]
[msgpack.core :refer :all]))
(def config {"zookeeper.connect" "zk04/cb/kafka/pingqueue"
"group.id" "clj-kafka.consumer"
"auto.offset.reset" "smallest"
"auto.commit.enable" "false"})
@x
x / gist:dc57b27677c85d20becb
Last active August 29, 2015 14:11
Catch exceptions with context managers
class ExceptionCatcher():
def __enter__(self):
self.msg = None
def __exit__(self, type, value, traceback):
if type is Exception:
self.msg = value
return True # if you return a truthy value then the exception isn't raised
@x
x / gist:e9ffa40c97279ff8c1f0
Created January 14, 2015 20:53
tail python logstash files
jq -c '[.["@timestamp"], .levelname, .path, .message]'
@x
x / gist:7b2866ef4c7978dd84bc
Created February 4, 2015 18:02
Run clojure tests from repl
(require '[clojure.test :refer [run-tests]])
(do (require 'cb-riak.cb-riak-test :reload-all) (run-tests 'cb-riak.cb-riak-test))