Skip to content

Instantly share code, notes, and snippets.

class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
self.nodes.add(value)
def add_edge(self, from_node, to_node, distance):
@miku
miku / .gitignore
Last active August 29, 2015 13:59
Command line converter: RDFXML from an URL to JSON-LD
*pyc
*rdftojld.build
@miku
miku / zippy.py
Created April 26, 2014 14:53
Iterate over subsequent pairs with zip.
>>> l = [1, 2, 3, 4, 5]
>>> zip(l[:-1], l[1:])
[(1, 2), (2, 3), (3, 4), (4, 5)]
@miku
miku / ftpmirror-example.py
Created April 30, 2014 12:48
Self contained FTPMirror example.
#!/usr/bin/env
# coding: utf-8
"""
Example FTPMirror task. On the command line:
$ python ftpmirror-example.py MirrorTask --local-scheduler
Example output:
from twisted.internet import defer, reactor
def stopping(result):
print('got', result)
# raise RuntimeError('fail')
reactor.stop()
return result
def raiseException(_):
raise Exception()
@miku
miku / README.md
Last active August 29, 2015 14:01
Example broken MARC XML
@miku
miku / escat.sh
Last active August 29, 2015 14:01
Elasticsearch wrapper (cat and top)
function escat() {
INDEXCAT="curl -sL localhost:9200/_cat/indices"
if [ $# -eq 0 ]; then
$INDEXCAT|sort -k2
else
case $1 in
-s) $INDEXCAT|sort -nrk 5; shift 1;;
-S) $INDEXCAT|sort -nrk 5; shift 1;;
-n) $INDEXCAT|sort -k 2; shift 1;;
-t) $INDEXCAT|sort -k 1; shift 1;;
@miku
miku / closest_example.py
Last active August 29, 2015 14:01
Example for BaseTask and ClosestDateParameter example
#!/usr/bin/env python
# coding: utf-8
"""
1) SimpleTask will "know" its output `path`.
2) ClosestDateParameter helps to map multiple dates to a single date,
e.g. I want to be able to call the task every day, but the output
from the most recent Monday will be enough.
"""
@miku
miku / pre-commit
Last active August 29, 2015 14:01
Git pre-commit hook, taking a screenshot of a single webpage
#!/usr/bin/env bash
HOMEPAGE=http://localhost:5000
SCREENIE_DIR=$(pwd)/screenshots
HEAD=$(git rev-parse HEAD)
if [[ "$OSTYPE" == "darwin"* ]]; then
RESPONSE=$(curl --write-out %{http_code} --silent --output /dev/null "$HOMEPAGE")
if [[ "$RESPONSE" == 200 ]]; then
mkdir -p "$SCREENIE_DIR"
@miku
miku / 100.a.uniq.tsv
Last active August 29, 2015 14:01
Uniq authors
Aas, Tore NA
Abaji NA
Abe, Komei 1911-2006
Abel, Carl Friedrich 1723-1787
Abel, Mark NA
Aberg, Hanna NA
Abert, Johann Joseph 1832-1915
Ablinger, Peter * 1959
Abou-Khalil, Rabih * 1957
Abraham, Paul 1892-1960