Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python2.5
# -*- coding: utf-8 -*-
# Copyright © 2010 Andrew D. Yates
# All Rights Reserved
"""Assorted Google App Engine Python Utilities.
ID: random string for IDs
KeyPath: human readable path of an app engine datastore key
Cookie: generate HTTP cookie header formatted string
"""
<samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="{{ response_id }}" IssueInstant="{{ issue_instant }}" Version="2.0"><samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"></samlp:StatusCode></samlp:Status><saml:Assertion ID="{{ assertion_id }}" IssueInstant="{{ issue_instant }}" Version="2.0"><saml:Issuer>{{ issuer }}</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">{{ username }}</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData {% if request_id %}InResponseTo="{{ request_id }}" {% endif %}NotOnOrAfter="{{ not_on_or_after }}" Recipient="{{ acs_url }}"></saml:SubjectConfirmationData></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="{{ not_before }}" NotOnOrAfter="{{ not_on_or_after }}"><saml:AudienceRestriction><saml:Audience>{{ acs_url }}</saml:Audience></saml:AudienceR
@andrewdyates
andrewdyates / app.yaml
Created October 29, 2010 00:09
OpenID federated login / logout sketch test for Google App Engine
application: myapplication
version: 1
runtime: python
api_version: 1
handlers:
- url: /_ah/login_required
script: do_openid_login.py
@andrewdyates
andrewdyates / open_with_zip.py
Created April 24, 2012 17:21
Open a file that may be compressed in python.
import gzip
import zipfile
def open_with_zip(filepath):
"""Open a file with .gzip, .zip, or no compression.
Returns:
[*str] read filepointer of uncompressed file stream
"""
ext = filepath.lower().rpartition('.')[-1]
@andrewdyates
andrewdyates / try_distance_corr.py
Created June 22, 2012 14:37 — forked from josef-pkt/try_distance_corr.py
distance covariance and correlation
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 15 14:00:29 2012
Author: Josef Perktold
License: MIT, BSD-3 (for statsmodels)
http://en.wikipedia.org/wiki/Distance_correlation
Yaroslav and Satrajit on sklearn mailing list
@andrewdyates
andrewdyates / dcor.pyx
Created June 22, 2012 15:01 — forked from ffinkernagel/dcor.pyx
Distance correlation - not quadratic in space
# Copyright (c) 2012, Florian Finkernagel. All right reserved.
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are
## met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above
## copyright notice, this list of conditions and the following
@andrewdyates
andrewdyates / tab_to_npy.py
Created June 25, 2012 23:52
Load tab data into masked numpy matrix
#!/usr/bin/python
import numpy as np
import os
TEST_FILE=os.path.expanduser("~/Dropbox/biostat/eqtl_data/GSE25935/GSE25935.GPL4133.eQTL.nooutliers.tab")
# this does not (yet) work
# http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html#numpy.genfromtxt
# http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html#numpy.loadtxt
"""
=====================================================
Distance computations for masked arrays (:mod:`scipy.spatial.mdistance`)
=====================================================
.. sectionauthor:: Damian Eads, Jason Merkin
Function Reference
------------------
@andrewdyates
andrewdyates / get_current_username.py
Created June 27, 2012 04:43
get current username in Python
# http://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python
import os, pwd
username = pwd.getpwuid(os.getuid()).pw_name
@andrewdyates
andrewdyates / make_dir.py
Created October 2, 2012 22:57
A simple make directory function in Python that I must have copy-pasted 100 times.
#!/usr/bin/python
import os, errno
def make_dir(outdir):
try:
os.makedirs(outdir)
except OSError, e:
if e.errno != errno.EEXIST: raise
return outdir