Skip to content

Instantly share code, notes, and snippets.

View hpiwowar's full-sized avatar

Heather Piwowar hpiwowar

View GitHub Profile
@jalperin
jalperin / mendeley_oauth2_example.py
Last active November 6, 2022 10:44
Example of how to access the Mendeley OAuth2 API
# -*- coding: utf-8 -*-
#!/usr/bin/env python
### Example code to access the Mendeley OAuth2 API
### Author: Juan Pablo Alperin
import requests
import requests.auth
import urllib
CLIENT_ID = ''
CLIENT_SECRET = ''
@jdunck
jdunck / redis_leaky_bucket.py
Created November 17, 2012 08:16
leaky bucket queue - redis 2.6 + lua + python
#cribbed from http://vimeo.com/52569901 (Twilio carrier call origination moderation)
# The idea is that many fan-in queues can enqueue at any rate, but
# dequeue needs to happen in a rate-controlled manner without allowing
# any individual input queue to starve other queues.
# http://en.wikipedia.org/wiki/Leaky_bucket (second sense, "This version is referred to here as the leaky bucket as a queue.")
#
# requires:
# redis 2.6+
# redis-py>=2.7.0
# anyjson
@dbarnett
dbarnett / jsonalchemy.py
Created February 3, 2012 15:10
JSONAlchemy: Proper JSON marshalling and mutation tracking in SQLAlchemy
import simplejson
import sqlalchemy
from sqlalchemy import String
from sqlalchemy.ext.mutable import Mutable
class JSONEncodedObj(sqlalchemy.types.TypeDecorator):
"""Represents an immutable structure as a json-encoded string."""
impl = String
@href
href / dict_namedtuple.py
Created October 27, 2011 12:00
Convert any dictionary to a named tuple
from collections import namedtuple
def convert(dictionary):
return namedtuple('GenericDict', dictionary.keys())(**dictionary)
"""
>>> d = dictionary(a=1, b='b', c=[3])
>>> named = convert(d)
>>> named.a == d.a
True
>>> named.b == d.b
@hpiwowar
hpiwowar / ASIST2011_stats.R
Created May 30, 2011 15:15
Stats for the analysis and graphics in Piwowar ASIS&T 2011 submission "Finding the hold-outs"
### Heather Piwowar
### MIT open license.
### blog post about interm results:
library(rms)
# if true, draw figures on screen instead of in a file
SCREEN=TRUE
# set to ".eps" or ".png"
@hpiwowar
hpiwowar / plot.summary.formula.response.CIs.R
Created May 30, 2011 15:10
Plots Hmisc summary formula responses with confidence intervals
### Heather Piwowar
# Modifications to add confidence intervals added by Heather Piwowar
# Based on dotchart2{Hmisc}
dotchart2.CIs =
function (data, labels, groups = NULL, gdata = NA, horizontal = TRUE,
pch = 16, xlab = "", ylab = "", auxdata, auxgdata = NULL,
auxtitle, lty = if (.R.) 1 else 2, lines = TRUE, dotsize = 0.8,
cex = par("cex"), cex.labels = cex, cex.group.labels = cex.labels *
1.25, sort. = TRUE, add = FALSE, dotfont = par("font"),
@brantfaircloth
brantfaircloth / gist:764363
Created January 4, 2011 03:49
dynamic tests generation that works in unittest and nose
# modified from http://bit.ly/dEyw03
import unittest
class TestMyGoods(unittest.TestCase):
pass
def create_dynamic_method(pair):
"""just don't include `test` in the function name here, nose will try to
run it"""