Skip to content

Instantly share code, notes, and snippets.

View kstrauser's full-sized avatar

Kirk Strauser kstrauser

View GitHub Profile
@kstrauser
kstrauser / ghost2wp.py
Last active August 2, 2018 07:20 — forked from tzangms/ghost2wp.py
Migrate Ghost to Wordpress
"""
Requirements:
* A Wordpress Blog
* Ghost export file (json).
* Python Packages: python-wordpress-xmlrpc
>>> pip install python-wordpress-xmlrpc
WARNING:
@kstrauser
kstrauser / mocked.py
Last active March 25, 2017 01:31
Use assert functions instead of methods to avoid insidious test problems
>>> import mock
>>> m = mock.Mock()
>>> m.assert_called_once() # Old version of Mock? This may not be what you expect.
<Mock name='mock.assert_called_once()' id='4558624144'>
>>> assert_called_once = mock.Mock.assert_called_once # Doesn't exist. Now you know!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Mock' has no attribute 'assert_called_once'
from itertools import count
def fizz():
for i in count(1):
yield '' if i % 3 else 'fizz'
def buzz():
for i in count(1):
yield '' if i % 5 else 'buzz'

Keybase proof

I hereby claim:

  • I am kstrauser on github.
  • I am ks (https://keybase.io/ks) on keybase.
  • I have a public key whose fingerprint is 19CF F48E 5C06 16B4 4A15 1E80 54D9 906A 294B 7FF3

To claim this, I am signing this object:

@kstrauser
kstrauser / freezewheels.py
Created August 29, 2013 17:45
This works like a hypothetical "pip freezewheels" that makes wheels of all installed packages.
#!/usr/bin/env python
"""
Build wheels of all currently installed packages (as listed by "pip freeze")
"""
import glob
import importlib
from subprocess import call
@kstrauser
kstrauser / gist:1300151
Created October 20, 2011 01:11
Python unittest for a named object's existence

I use this decorator in unittest modules to verify that a particularly-named object exists:

def existsin(namespace):
    """Given a namespace, this decorator asserts that an object with
    the same name as the function it's wrapping (minus ) exists in that
    namespace"""
    def wrapper(namedunittest):
        assert namedunittest.__name__.startswith('test_'), \
            "The wrapped '%s' function doesn't look like a unit test" % namedunittest.__name__
@kstrauser
kstrauser / substrcomparatormaker.py
Created October 4, 2011 22:35
Decorator to help with legacy database that aren't 1NF
def substrcomparatormaker(column, i, j=None):
"""Return a comparator that tests for the substring of 'column'
from 'i' to 'j', as specified with Python slice values. This
means setting the start column to i + 1 because Python is 0-based
and SQL is 1-based, and setting the length to j - i.
Please don't create new tables that use this! It's only for legacy,
unnormalized data where multiple values are lumped together in a single
column.