Skip to content

Instantly share code, notes, and snippets.

@robla
robla / roadmap-publisher.py
Last active December 16, 2015 09:59
Work-in-progress for publishing the WMF Roadmap back to mediawiki.org
#!/usr/bin/env python
#
# Copyright (c) 2013 Rob Lanphier, Wikimedia Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@robla
robla / striptrackers.py
Created January 24, 2016 05:33
Sanitize URLs of tracking cruft from HTML exported from GDocs.
#!/usr/bin/env python
#
# Copyright 2016 Rob Lanphier
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@robla
robla / sftpurl.py
Created July 18, 2016 00:18
print the sftp URL of a file from shell
#!/usr/bin/python
import os
import socket
import sys
import urllib
def sftppath(file):
fqdn=socket.getfqdn()
fullpath=os.path.realpath(os.path.expanduser(file))
return "sftp://" + fqdn + urllib.quote(fullpath)
@robla
robla / gist:371ea556af34d20341808610068fb0e1
Created February 21, 2017 04:22
Blockstack ID: roblan.id
Verifying that "roblan.id" is my Blockstack ID. https://onename.com/roblan
@robla
robla / keybase.md
Created November 21, 2017 02:31
keybase.md

Keybase proof

I hereby claim:

  • I am robla on github.
  • I am robla (https://keybase.io/robla) on keybase.
  • I have a public key ASCNQx8NKhpIwCSsDw5BeXa9ojdNLNBkYrdpMcZKOa9ZLAo

To claim this, I am signing this object:

@robla
robla / sqlite3-csv.sh
Created November 25, 2017 01:27
sqlite3-csv.sh: dump an table from sqlite db as csv
#!/bin/bash
# sqlite3-csv: dump an table from sqlite db as csv
summary="$0: dump an sqlite db as csv"
usageline=" usage: $0 thisdb [thistable]"
usage="${summary}\n\n${usageline}\n\n"
if [ -z "$1" ]; then
printf "$usage"
exit;
@robla
robla / sfballotparse.py
Created June 17, 2018 21:00
sfballotparse.py - parse sfelections.sfgov.org/results ballot image files
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2018 Rob Lanphier
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@robla
robla / sf2018mayorballots-urlencoded-tallysorted.txt
Last active June 17, 2018 21:21
Ballots for sf2018mayoral race (report 14), urlencoded with robla/sfballotparse.py and piped through sort + uniq -c
47 AMY+FARAH+WEISS=1
4 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2
38 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&ELLEN+LEE+ZHOU=3
31 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&JANE+KIM=3
29 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&LONDON+BREED=3
27 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&MARK+LENO=3
20 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&MICHELLE+BRAVO=3
8 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&None=3
15 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=2&RICHIE+GREENBERG=3
1 AMY+FARAH+WEISS=1&ANGELA+ALIOTO=3
@robla
robla / grepcount-cand-files.sh
Last active June 18, 2018 05:32
Very crude tool to tally the output of sfballotparse.py for 2018 in particular (with hardcoded last names for the top 3 candidates this past election)
#!/bin/bash
# Very crude tool to tally the output of sfballotparse.py for 2018 in particular
# (with hardcoded last names for the top 3 candidates this past election)
votefile=${1}
if [ ! -f "${votefile}" ]; then
echo "${votefile} not found"
exit
fi
@robla
robla / reverse_cumulative_table.py
Created February 16, 2019 00:54
Reverse-engineering a ballot set from a specific table of pairwise voting results listed in a 2019 reddit post
#!/usr/bin/python3
# Script for generating an answer to this:
# <https://www.reddit.com/r/Voting/comments/aqsxft/condorcet_winner_from_counts_of_ranks_possible/>
import json
import itertools
from collections import Counter
innerperm = [x for x in itertools.permutations(['P1', 'P2', 'P3'], 3)]