Skip to content

Instantly share code, notes, and snippets.

View urschrei's full-sized avatar

Stephan Hügel urschrei

View GitHub Profile
@urschrei
urschrei / datediff.py
Last active December 11, 2015 23:29
Number of days and number of months between two dates
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Return the number of days between today, and the input date
Also calculate how many times the month rolls over
The expected format is dd/mm/yyyy
There's no input or bounds checking hahahahahahahaha
"""
import datetime
@urschrei
urschrei / biblatex_mla_setup.tex
Created July 17, 2012 10:59
Sample Biblatex-MLA setup
% Biblatex-MLA setup for Biblatex-MLA 0.9.5
\usepackage[
style=mla,
autocite=footnote,
backref=true,
hyperref=true,
backend=biber]{biblatex}
% Compatibility fixes for Biblatex 2.0 and Biblatex-MLA
\DeclareAutoCiteCommand{footnote}[f]{\footcite}{\footcites}
\providecommand\biburldatelong{}
@urschrei
urschrei / hiring.py
Last active October 6, 2015 02:28
How many women has GitHub hired since May 2011?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import requests
gh_url = "https://github.com/blog/%s"
titles = []
# all posts since the 19th of May 2011
for r in xrange(858, 1395):
@urschrei
urschrei / gist:2917499
Created June 12, 2012 13:26
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@urschrei
urschrei / mkflask.sh
Created May 12, 2012 14:46
Bootstrap a Flask project
#!/bin/bash -e
# opinionated Flask bootstrap script
# assumes you'll be using MySQL/PG, Fabric, Webassets, WTForms and Blueprints
# creates a virtualenv and an Alembic migrations system
# The script will halt on any error, and remove the project dir, if it created one
# accepts a single argument: a new directory name under which to create the project
# check that Python is installed
type python >/dev/null 2>&1 || { echo >&2 "Python doesn't appear to be installed. Aborting."; exit 1; }
@urschrei
urschrei / gist:1193001
Created September 4, 2011 15:16
wrap() isn't unpacking the list
#!/usr/bin/env python
def wrap(f):
def enc(*args):
for item in args:
f(item)
return enc
@wrap
@urschrei
urschrei / gist:1191297
Created September 3, 2011 14:55
Output of retrieved bib-formatted item entries from the Zotero Read API
[u'<div class="csl-entry">Sontag, S. \u201cGodot Comes to Sarajevo.\u201d <i>The New York Review of Books</i> 21 (1993) : 53\u201359. Print.</div>',
u'<div class="csl-entry">McIntyre, T. J. \u201cCopyright in Custom Code: Who Owns Commissioned Software?\u201d <i>Journal of Intellectual Property Law &amp; Practice</i> (2007) : n. pag. Print.</div>',
u'<div class="csl-entry">Badiou, A. \u201c\u2018We Need a Popular Discipline\u2019: Contemporary Politics and the Crisis of the Negative.\u201d <i>Critical Inquiry</i> 34.4 (2008) : n. pag. Print.</div>']
@urschrei
urschrei / doctor.txt
Created July 30, 2011 17:14
Output of brew install -v
If you have installed MacGPG2 via the package installer, several other
checks in this script will turn up problems, such as stray .dylibs in
/usr/local and permissions issues with share and man in /usr/local/.
Some "config" scripts were found in your path, but not in system or Homebrew folders.
`./configure` scripts often look for *-config scripts to determine if software packages
are installed, and what additional flags to use when compiling and linking.
Having additional scripts in your path can confuse software installed via Homebrew if
@urschrei
urschrei / commission.py
Created July 26, 2011 22:09
Basic commission payment thing
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Assume a target number and an actual number
Assume a range of commission payments based upon the percentage achieved
What is the amount of commission due?
"""
from decimal import Decimal
#!/usr/bin/env python
def fibo():
"""
yield the Fibonacci sequence
"""
a, b = 0, 1
while True:
yield a
a, b = b, a + b