Skip to content

Instantly share code, notes, and snippets.

@embray
embray / setup.cfg
Created September 2, 2011 19:29
A d2to1 example of setup_hooks and pre/post command hooks
$ ./setup.py build
Setting up testproj
running build
running pre_hook testproj.pre_build_hook for command build
Someone is building my project!
running build_py
running post_hook testproj.post_build_hook for command build
Someone built my project!
@embray
embray / long_comment.ipynb
Created December 7, 2012 18:12
update_card_with_long_comment() PyFITS example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@embray
embray / suggest_backports.py
Last active July 26, 2019 11:41
List pull requests merged since the last tag on the given release branch which have not yet been merged into the release branch.
#!/usr/bin/env python
# I wasn't happy with any of the GitHub libraries for Python that I tried so I
# just used the GitHub API directly. If someone would like to rewrite this
# using a library please be my guest
from __future__ import unicode_literals
import argparse
import base64
@embray
embray / classes.ipynb
Created May 9, 2013 19:21
Notebook for my PyLunch talk on classes. This contains some content that we didn't get to yet in PyLunch, as well as some new content that was added after this was first presented.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@embray
embray / win_register_python.py
Created July 19, 2013 22:25
A script to register Python under HKEY_CURRENT_USER in addition to HKEY_LOCAL_MACHINE
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html
@embray
embray / win32_is_append_mode.py
Last active December 22, 2015 08:19
A function written with ctypes called is_append_mode_win32 which, given a file object, can determine, on Windows, if it was opened in append mode (regardless of what its mode string says). In UNIX this would be equivalent to fcntl(fd, F_GETFL) & O_APPEND. These are the hoops we have to go through to get the same functionality on Windows.
from ctypes import (cdll, c_size_t, c_void_p, c_int, c_char, Structure,
POINTER, cast)
from ctypes.util import find_msvcrt
msvcrt = cdll.LoadLibrary(find_msvcrt())
# Constants
IOINFO_L2E = 5
@embray
embray / capture_block.py
Last active June 22, 2020 08:07
Capture the contents of a with statement code block without executing the block
import contextlib
import dis
import inspect
import linecache
import struct
import sys
class SkipBlock(Exception):
pass
@embray
embray / 01-numpy.py
Created August 12, 2014 14:27
IPython notebook from https://github.com/swcarpentry/bc/blob/master/novice/python/01-numpy.ipynb converted to Python module with nbconvert
# coding: utf-8
### Analyzing Patient Data
# We are studying inflammation in patients who have been given a new treatment for arthritis,
# and need to analyze the first dozen data sets.
# The data sets are stored in [comma-separated values](../../gloss.html#comma-separeted-values) (CSV) format:
# each row holds information for a single patient,
# and the columns represent successive days.
# The first few rows of our first file look like this:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.