Skip to content

Instantly share code, notes, and snippets.

View breyten's full-sized avatar

Breyten Ernsting breyten

View GitHub Profile
@breyten
breyten / get_dutch_politicians.py
Created August 28, 2015 12:53
Get dutch politicians (mps and executives)
#!/usr/bin/env python
import requests
from BeautifulSoup import BeautifulSoup
def get_politicians(session):
url = u'http://www.tweedekamer.nl/kamerleden/alle_kamerleden'
resp = session.get(url)
if resp.status_code != 200:
return None
@breyten
breyten / query_npo_backstage.py
Last active August 28, 2015 13:07
Query NPO backstage API for the name of a person.
#!/usr/bin/env python
import requests
from BeautifulSoup import BeautifulSoup
NPO_BACKSTAGE_BASE_URL = 'http://backstage-api.npo.nl'
NPO_BACKSTAGE_ENDPOINT_SEARCH = '/v0/search'
def get_politician_count(politician, session):
SEARCH_DATA = {
@breyten
breyten / combine_results.py
Created August 28, 2015 14:28
combine_results.py
party_counts = sorted([
{'party': p, 'count': get_party_count(p, session)} for p in parties],
key=lambda x: x['count'])
pprint(party_counts)
all_people = politicians + executives
politician_counts = sorted([
{'politician': p, 'count': get_politician_count(p, session)} for p in all_people],
key=lambda x: x['count'])
@breyten
breyten / GithubNewIssueDefaults.js
Last active August 29, 2015 13:56
Make a new issue have sane defaults by setting a default milestone & assignee
// ==UserScript==
// @name GithubNewIssueDefaults
// @namespace http://yerb.net/
// @version 0.1
// @description Make a new issue have sane defaults -- milestone & assignee
// @match https://github.com/*/*/issues/new
// @copyright 2013, Breyten Ernsting
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
@breyten
breyten / git-branches-by-commit-date.sh
Last active December 12, 2015 03:28 — forked from jasonrudolph/git-branches-by-commit-date.sh
List unmerged branches with the latest commit message for each branch
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch --no-merged`;do echo -e `git show --abbrev-commit --format="%ci %d %s" $branch | head -n 1`; done | sort -r
@breyten
breyten / list_tsv_column.sh
Created April 1, 2013 10:57
List a specific field of a tab separated file using AWK
#!/bin/sh
/usr/bin/awk '
BEGIN {
FS="\t";
FIELD_NAME="'$1'";
print FIELD_NAME;
}
NR == 1 {
@breyten
breyten / middleware.py
Created December 11, 2013 11:49
Modify the locale middleware in python to not look at the HTTP_ACCEPT_LANGUAGE header (and just use the language specified in the settings or the user's preferences)
import os
import sys
import re
from django.utils import translation
from django.middleware.locale import LocaleMiddleware
class LocaleNoHTTPAcceptMiddleware(LocaleMiddleware):
def process_request(self, request):
request.LANGUAGE_CODE = translation.get_language()
@breyten
breyten / bitcoin_hider.js
Last active December 31, 2015 20:09
Hide Bitcoin articlens on HN with TamperMonkey
// ==UserScript==
// @name HNBitcoinHider
// @namespace http://yerb.net/
// @version 0.1
// @description Hide bitcoin news items on Hacker News
// @match https://news.ycombinator.com*
// @copyright 2013, Breyten Ernsting
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
@breyten
breyten / get_amsterdam_datapunt.sh
Created March 15, 2016 13:54
Get amsterdam datapoints
#!/bin/bash
for SET in `wget -q -O - 'https://api.datapunt.amsterdam.nl/gebieden/' |jq '.[]' |sed -e 's/"//g;'`; do
echo $SET
for PART in `wget -q -O - $SET |jq '.results[] |._links.self.href' |sed -e 's/"//g;'`; do
echo "* $PART"
wget -q -x $PART
done
done
@breyten
breyten / parse_big_xml.py
Last active June 8, 2016 11:36
Parsing big pretty printed XML files
import sys
import os
import re
import codecs
from lxml import etree
def parse_big_xml(filename, item_tag=u'item'):
with codecs.open(filename, 'r', 'utf-8') as in_file:
output = u''