Skip to content

Instantly share code, notes, and snippets.

View breyten's full-sized avatar

Breyten Ernsting breyten

View GitHub Profile
@breyten
breyten / hg-close-inactive-branches.sh
Last active February 22, 2019 11:17
Automatically close inactive mercurial branches (use with care!)
for i in `hg branches |grep -v 'default' |grep -v 'production' |grep inactive |awk '{print $1}'`; do hg update $i && hg commit -m "close branch" --close-branch; done
@breyten
breyten / authentication.py
Created December 9, 2013 16:08
Middleware for Django to authenticate a user with an OAuth token
from pprint import pprint
import re
from django.conf import settings
from django.contrib.auth.models import User, check_password
from django.contrib.auth import authenticate, login
from apps.api.authentication import verify_access_token, OAuthError
class OAuth2Middleware( object ):
@breyten
breyten / get_climates.py
Created August 9, 2016 09:37
Gets climate data from wikipedia country pages
#!/usr/bin/env python
import os
import sys
import re
from pprint import pprint
import json
from time import sleep
import requests
from BeautifulSoup import BeautifulSoup
@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''
@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 / 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 / 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 / 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 / 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 / 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==