Skip to content

Instantly share code, notes, and snippets.

View goerz's full-sized avatar

Michael Goerz goerz

View GitHub Profile
@goerz
goerz / rename_amtrak.py
Created February 19, 2016 21:21
Rename Amtrak Tickets
#!/usr/bin/env python
"""command line script that renames a bunch of Amtrak ticket PDF to a more
useful name. Relies on `pdftotext`."""
import os
import re
import logging
from collections import namedtuple
from dateutil.parser import parse as parse_date
from glob import glob
@goerz
goerz / test_class_behavior.py
Created December 10, 2015 23:14
Example code that illustrates the (possibly surprising) behavior of Python instance and class attributes
class MyNewClass(object):
a = 1 # class attribute
def __init__(self):
self.b = 1 # instance attribute
def get_a_via_instance(self):
return self.a
def get_a_via_class(self):
return self.__class__.a # = MyNewClass.a
class MyOldClass():
@goerz
goerz / find_encoding.py
Created October 30, 2015 18:08
Determine charset encoding from byte sequence and known unicode codepoint
#!/usr/bin/env python
import click
codepoint_hex = click.prompt("Enter a unicode codepoint (hex) for a known character")
encoded_bytes = click.prompt("Enter the bytes corresponding to the same character in an unknown encoding, in hex")
encoded_bytes = bytearray.fromhex(encoded_bytes)
codepoint_dec = int(codepoint_hex, 16)
unicode_char = chr(codepoint_dec)
click.echo("The unicode characters is: %s" % unicode_char)
@goerz
goerz / 00_GPG_and_SSH_README.md
Last active December 28, 2018 19:43
Public SSH/GPG keys

Public SSH/GPG Keys

If you would like to give me SSH access to a machine, please append the content of goerz.pub to the ~/.ssh/authorized_keys file.

To send me encrypted files (attachments) by email, use the GPG Key 57a6caa6.asc.

You can verify the GPG keys at https://keybase.io/goerz

@goerz
goerz / imshow_transparency.ipynb
Last active October 11, 2015 14:54
Transparency in imshow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@goerz
goerz / rabicycling.ipynb
Last active January 28, 2020 23:41
The Analytical Solution of Rabi Cycling in the Two-Level-System
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@goerz
goerz / doc2markdown.py
Created July 24, 2015 14:44
Convert a word (doc/docx) file to markdown
#!/usr/bin/env python
"""Convert a word (doc/docx) file to markdown"""
import sys
import os
import subprocess
SOFFICE = r'/Applications/LibreOffice.app/Contents/MacOS/soffice'
PANDOC = r'pandoc'
@goerz
goerz / creating-an-iso-image-on-macos-x.markdown
Last active August 29, 2015 14:01
Creating an ISO image on MacOS X

Creating an ISO image on MacOS X

Author: Michael Goerz [email protected]
Date: July 6, 2009

  1. Insert your CD/DVD. Check that MacOS has mounted it in as a Volume (It will appear on the Desktop).

  2. Identify which device the CD/DVD is.

This is the trickiest part of the whole procedure. First, use drutil to get some comprehensive information about your CD/DVD

@goerz
goerz / fortran_strings.markdown
Last active August 29, 2015 14:01
Some Fortran String Gotchas

Some Fortran String Gotchas

Author: Michael Goerz [email protected]
Date: Oct 20, 2008

I ran into some problems the other day from a misunderstanding about how passing strings works in fortran.

Consider the following program:

implicit none

@goerz
goerz / assumptions.nb
Created May 25, 2014 03:46
How to tell Mathematica that a variable represents a real number, is greater than zero, or similar conditions
(************** Content-type: application/mathematica **************
CreatedBy='Mathematica 5.1'
Mathematica-Compatible Notebook
This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.
To get the notebook into a Mathematica-compatible application, do