Skip to content

Instantly share code, notes, and snippets.

@pckujawa
pckujawa / gist:2232604
Created March 29, 2012 02:30
telling python how to create a dict out of your object (via interpreter on KEGG web API data)
>>> from SOAPpy import WSDL
>>> wsdl = 'http://soap.genome.jp/KEGG.wsdl'
>>> serv = WSDL.Proxy(wsdl)
>>> pathways = serv.list_pathways('map')
>>> ps=pathways
>>> ps[0]
<SOAPpy.Types.structType item at 37525944>: {'definition': 'Glycolysis / Gluconeogenesis - Reference pathway', 'entry_id': 'path:map00010'}
>>> ps[0].__dict__
{'_attrs': {},
'_cache': None,
@pckujawa
pckujawa / webapp.py
Created March 29, 2012 02:39 — forked from alex/webapp.py
turn any python object into a web app
import traceback
class WebApp(object):
def __init__(self, obj):
self.obj = obj
def __call__(self, environ, start_response):
try:
path = filter(bool, environ["PATH_INFO"].split("/"))
@pckujawa
pckujawa / gist:2246059
Created March 30, 2012 02:54
methods of unit testing in python
# Taken from http://artifex.org/~hblanks/talks/2011/pep20_by_example.html
################################### 7 ##################################
""" Write out the tests for a factorial function. """
#-----------------------------------------------------------------------
def factorial(n):
"""
Return the factorial of n, an exact integer >= 0.
@pckujawa
pckujawa / gist:2246101
Created March 30, 2012 03:01
xml parsing using different libraries
################################## 15 ##################################
def hard():
# Example 1
try:
import twisted
help(twisted) # (this may not be as hard as I think, though)
except:
pass
@pckujawa
pckujawa / gist:2246120
Created March 30, 2012 03:06
parsing inputs from commandline and creating a latex file from python
from optparse import OptionParser
import os
import re
import subprocess
import sys
parser = OptionParser(usage=__doc__.strip())
parser.add_option('-v', dest='verbose', action='store_true',
help='Verbose output')
@pckujawa
pckujawa / gist:2246183
Created March 30, 2012 03:21
android coverflow widget
/*
* Copyright (C) 2010 Neil Davies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@pckujawa
pckujawa / gist:2246185
Created March 30, 2012 03:22
android coverflow widget example
/*
* Copyright (C) 2010 Neil Davies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@pckujawa
pckujawa / gist:2396287
Created April 16, 2012 04:00
Escape the shoebox on android legacy apps
<supports-screens android:largeScreens="true" android:anyDensity="true" />
@pckujawa
pckujawa / gist:2631963
Created May 8, 2012 01:59
Including the name of the script dynamically, e.g. for a USAGE prompt
USAGE = """
Usage: %s <action> [<action parameters>]
""" % os.path.basename(sys.argv[0])
@pckujawa
pckujawa / gist:2789170
Created May 25, 2012 16:53
msbuild target for printing reserved properties
<Project DefaultTargets="PrintReservedProperties" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrintReservedProperties">
<Message Text="MSBuildProjectDirectory $(MSBuildProjectDirectory)" />
<Message Text="MSBuildProjectFile $(MSBuildProjectFile)" />
<Message Text="MSBuildProjectExtension $(MSBuildProjectExtension)" />
<Message Text="MSBuildProjectFullPath $(MSBuildProjectFullPath)" />
<Message Text="MSBuildProjectName $(MSBuildProjectName)" />
<Message Text="MSBuildBinPath $(MSBuildBinPath)" />
<Message Text="MSBuildProjectDefaultTargets $(MSBuildProjectDefaultTargets)" />
<Message Text="MSBuildExtensionsPath $(MSBuildExtensionsPath)" />