Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
for repo in $(cat repos.txt); do
repodir=$(perl -pe 's!/!-!g;' -e 's/^analytics-//' <<< "$repo")
echo git clone --mirror ssh://gerrit.wikimedia.org/$repo.git $repodir
if git clone --mirror ssh://gerrit.wikimedia.org/$repo.git $repodir; then
echo
else
break
fi
done
@dsc
dsc / jconsole-proxy.sh
Created August 7, 2012 01:15
jconsole via ssh proxy
#!/bin/bash
#/ jc -- jconsole via ssh proxy
#/
#/ Usage: jc [options] HOST JMX_PORT [PROXY_PORT=JMX_PORT] [JMX_HOST=HOST]
#/
#/ Starts a SOCKS proxy via ssh to connect to a
#/ JVM running on a remote and protected machine.
#/
#/ Arguments:
@dsc
dsc / modelhaiku.py
Created June 22, 2012 20:31
modelhaiku.py
from sqlalchemy import *
class Haiku(Model):
id = Column(Integer, primary_key=True)
ctime = Column(DateTime, default=func.now())
line1 = Column(Text())
line2 = Column(Text())
line3 = Column(Text())
query = (Session.query(Haiku)
@dsc
dsc / README.md
Created June 22, 2012 05:16
Performance of JS Hash Implementations
@dsc
dsc / git-fat-pack.sh
Created June 13, 2012 17:53
Permanently remove crap from a git repo.
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
@dsc
dsc / dsync.sh
Created May 23, 2012 17:54
dsync -- Copy files to many hosts in parallel
#!/bin/bash
#/ dsync -- Copy files to many hosts in parallel.
#/
#/ Usage: dsync [options] -- [RSYNC_OPTIONS] SRC[...] DEST
#/
#/ `dsync` copies files (using `rsync`) to many hosts in parallel.
#/
#/ Where possible, `dsync` follows semantics of `dsh` and `rsync` -- it
#/ understands `~/.dsh/groups`, and uses `dsh`-like flags for specifying
@dsc
dsc / combi.py
Created April 27, 2012 17:56
testcomb.py
# when you asked the question, this is what popped in my head;
# a solution to abstracting the requested problem into indexes
def combi(n, k):
r = []
for i in range(n - k + 1):
for j in range(i + 1, n - k + 2):
s = [i]
for m in range(k - 1):
s.append(j + m)
@dsc
dsc / comb.py
Last active October 3, 2015 06:18
kcomb
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Write me a function that takes a collection S and an integer k, and returns a
collection of all collections such that each is a sub-collection of S with size k.
- S is a set-like structure that guarantees these collections contain totally
ordered and unique values; importantly, [1,2] is the same as [2,1].
- You can make sets as needed.
- They support indexing and slicing, as well as iteration.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from IPython.core import ipapi
ip = ipapi.get()
### Auto-Activate VirtualEnv
import os, sys
@dsc
dsc / ordered_json.py
Created December 22, 2011 22:05
Python JSON decoder that uses OrderedDict for JSON Objects.
import json
from collections import OrderedDict
ordered_decoder = json.JSONDecoder(object_pairs_hook=OrderedDict)
class OrderedJSONDecoder(json.JSONDecoder):
""" As `JSONDecoder`, but passing `collections.OrderedDict`
for `object_pairs_hook` by default.
"""