Skip to content

Instantly share code, notes, and snippets.

View durden's full-sized avatar

Luke Lee durden

View GitHub Profile
@durden
durden / docx_reader.py
Created December 2, 2013 23:22
Function to grab test from docx file (copied from http://etienned.github.io/posts/extract-text-from-word-docx-simply/)
# Copied from http://etienned.github.io/posts/extract-text-from-word-docx-simply/
try:
from xml.etree.cElementTree import XML
except ImportError:
from xml.etree.ElementTree import XML
import zipfile
"""
@durden
durden / gist:6369273
Last active December 21, 2015 21:39
Ipython notebook exploring nikeplus data
{
"metadata": {
"name": "NikePlus data exploration"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@durden
durden / deduplicating_data_ipython.md
Last active December 21, 2015 05:29
Notes from Pytexas 2013

Filtering and Deduplicating Data in IPython Notebook

  • Nice shortcut to create a list of strings
fields = '''\
test1,
test2,
test3,
test4'''.split()
@durden
durden / defensive_coding_references.md
Last active December 20, 2015 22:48
References for Defensive Coding talk

Bugs

Can't code without them, so code against them!

Presentation

@durden
durden / dynamic_imports.py
Last active October 1, 2020 23:42
Diff removing dynamic imports from pyqtgraph/__init__.py
# This is a raw listing of the imports that take place dynamically by calling
# the pyqtgraph/__init__.py:importAll() in the following scenarios:
#importAll('graphicsItems', globals(), locals())
#importAll('widgets', globals(), locals(), excludes=['MatplotlibWidget', 'RemoteGraphicsView'])
from .graphicsItems.ArrowItem import ArrowItem
from .graphicsItems.GraphicsWidgetAnchor import GraphicsWidgetAnchor
from .graphicsItems.GraphicsWidgetAnchor import Point
from .graphicsItems.GraphicsWidgetAnchor import QtCore
Development Status :: 1 - Planning
Development Status :: 2 - Pre-Alpha
Development Status :: 3 - Alpha
Development Status :: 4 - Beta
Development Status :: 5 - Production/Stable
Development Status :: 6 - Mature
Development Status :: 7 - Inactive
Environment :: Console
Environment :: Console :: Curses
Environment :: Console :: Framebuffer
@durden
durden / terminal_size.py
Created June 14, 2013 18:46
Get width/height of current terminal in python
# Snippet taken from: https://github.com/JakeWharton/pidcat/blob/master/pidcat.py
# unpack the current terminal width/height
data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
HEIGHT, WIDTH = struct.unpack('hh',data)
@durden
durden / python_versioning.md
Last active December 17, 2015 23:39
Article I've posted on my codrspace blog at http://codrspace.com/durden/python-versioning trying to figure out if my Python interpreter has a bug fix or not.

Python versioning

Motivation

I recently spent a little time reviewing a Python bug report and determining if I was running with a fixed version of the Python interpreter. I think this is a useful exercise for someone who is overly curious and not a core developer of the language.

This post is a rundown of my thought process while trying to figure this out.

@durden
durden / context_test.py
Created May 16, 2013 19:49
Context managers are smart..er than you think...
class mycontext(object):
def __enter__(self, *args, **kwargs):
print 'enter'
def __exit__(self, *args, **kwargs):
print 'exit'
def myfunc():
with mycontext():
# Gee what will happen here?
@durden
durden / qtevents.txt
Created May 13, 2013 15:20
Listing of Qt event defines sorted in numerical order.
# Taken from: http://qt-project.org/doc/qt-4.8/qevent.html#type
# Reformatted with: cat /tmp/events.txt | sort -t$'\t' -k2 -n | column -t -s $'\t'
QEvent::None 0 Not an event.
QEvent::Timer 1 Regular timer events (QTimerEvent).
QEvent::MouseButtonPress 2 Mouse press (QMouseEvent).
QEvent::MouseButtonRelease 3 Mouse release (QMouseEvent).
QEvent::MouseButtonDblClick 4 Mouse press again (QMouseEvent).
QEvent::MouseMove 5 Mouse move (QMouseEvent).
QEvent::KeyPress 6 Key press (QKeyEvent).