Skip to content

Instantly share code, notes, and snippets.

@kanzure
kanzure / coercion.py
Created March 13, 2014 21:26
sqlalchemy type coercion
"""
Type coercion for sqlalchemy prior to committing to some database.
http://stackoverflow.com/questions/8980735/how-can-i-verify-column-data-types-in-the-sqlalchemy-orm
"""
from sqlalchemy import (
Column,
Integer,
String,
@kanzure
kanzure / pip.error.log
Created March 4, 2014 22:35
stormpath-sdk is doing weird things?
Downloading/unpacking unittest2py3k (from stormpath-sdk->-r ./requirements/requirements.txt (line 40))
Running setup.py egg_info for package unittest2py3k
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip_build_root/unittest2py3k/setup.py", line 12, in <module>
from unittest2 import __version__ as VERSION
File "unittest2/__init__.py", line 61, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "unittest2/case.py", line 539
def assertAlmostEqual(self, first, second, *, places=None, msg=None,
@kanzure
kanzure / checksizes.py
Created December 8, 2013 06:34
HTTP file size checking in python
import requests
urls = open("vidurls.txt", "r").read().split()
results = {}
for url in urls:
print "processing: ", url
try:
@kanzure
kanzure / record.sh
Created December 1, 2013 00:34
recording vba emulation to video on linux
#!/bin/sh
# VBA and other emulators can save videos on their own, but this captures other windows too.
INFO=$(xwininfo -frame)
WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' |\
grep -oEe '[0-9]+x[0-9]+')
WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' |\
grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/+/,/' )
@kanzure
kanzure / battle.py
Created October 20, 2013 22:29
Attempt at doing battles in pokecrystal with python
"""
Code that attempts to model a battle.
"""
from pokemontools.vba.vba import crystal as emulator
class BattleException(Exception):
"""
Something went terribly wrong in a battle.
"""
class Test(object):
@staticmethod
def bark(message):
print "foo"
return message
T = bark.__func__("hello cruel world")
@kanzure
kanzure / errordump.txt
Created September 22, 2013 16:46
pokecrystal vba automation test
======================================================================
ERROR: test_keyboard_typing_cap_name (test_vba.VbaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kanzure/code/pokemon-reverse-engineering-tools/tests/test_vba.py", line 260, in test_keyboard_typing_cap_name
self.assertEqual(name, self.cry.get_player_name())
File "/home/kanzure/code/pokemon-reverse-engineering-tools/pokemontools/vba/vba.py", line 367, in get_player_name
name = translate_chars(bytez)
File "/home/kanzure/code/pokemon-reverse-engineering-tools/pokemontools/vba/vba.py", line 34, in translate_chars
result += chars[each]
@kanzure
kanzure / justdicebridged.py
Created September 16, 2013 14:27
python/javascript bridge using webkit and javascriptcore
#!/usr/bin/env python
import datetime
import json
import gtk
import gobject
# TODO: fix gi.repository.WebKit to have a working webview.get_dom_document
import webkit
@kanzure
kanzure / output.txt
Created September 14, 2013 19:25
python gtk3 libwebkit libjavascriptcore gi.repository gobject introspection JSGlobalContextRef
In [12]: frame = browser.webview.get_main_frame()
In [13]: frame.get_global_context()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-28813e0f64ff> in <module>()
----> 1 frame.get_global_context()
/usr/lib/python2.7/dist-packages/gi/types.py in function(*args, **kwargs)
111 @wraps_callable_info(info)
@kanzure
kanzure / shellcoderunner.py
Created September 12, 2013 15:44
pyinstaller win32 shellcode runner
#!/usr/bin/python
##############################################################
# PyInstaller Win32 shellcode runner - by @mihi42
#
# Needed software:
# * Python 2.7.2 from
# <http://www.python.org/download/releases/>
# * PyWin32 build 217 for Python 2.7 from
# <http://sourceforge.net/projects/pywin32/files/pywin32/>