Skip to content

Instantly share code, notes, and snippets.

View antiface's full-sized avatar

A.G. antiface

View GitHub Profile
from functools import partial
def _composed(f, g, *args, **kwargs):
return f(g(*args, **kwargs))
def compose(*a):
try:
return partial(_composed, a[0], compose(*a[1:]))
except:
return a[0]
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #000;
}
</style>
<body>
<html>
<head>
<title>Minimal River Reader</title>
<script src="http://fargo.io/code/jquery-1.9.1.min.js"></script>
</head>
<body>
<script>
var theRiver;
function onGetRiverStream (updatedFeeds) {
theRiver = updatedFeeds;
function fbUpdatePost (idPost, thePostText) {
FB.api (idPost, "post", {message: thePostText}, function (response) {
console.log ("fbUpdatePost: response == " + JSON.stringify (response, undefined, 4));
});
}
{
"created_at": "Fri Sep 19 12:20:23 +0000 2014",
"id": 512939257850511360,
"id_str": "512939257850511360",
"text": "\"I never used the Blackberry again.\" https://t.co/CYsbbBDtOh",
"source": "<a href=\"http://radio3.io/\" rel=\"nofollow\">radio3.io</a>",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
@antiface
antiface / pets.py
Last active August 29, 2015 14:06 — forked from jhamrick/pets.py
class Pet(object):
def __init__(self, name, species):
self.name = name
self.species = species
def getName(self):
return self.name
def getSpecies(self):
from PIL import Image
backgroundColor = (0,)*3
pixelSize = 9
image = Image.open('input.png')
image = image.resize((image.size[0]/pixelSize, image.size[1]/pixelSize), Image.NEAREST)
image = image.resize((image.size[0]*pixelSize, image.size[1]*pixelSize), Image.NEAREST)
pixel = image.load()

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
#!/usr/bin/env python
# wagnerfischer.py: Dynamic programming Levensthein distance function
# Kyle Gorman <gormanky@ohsu.edu>
#
# Based on:
#
# Robert A. Wagner and Michael J. Fischer (1974). The string-to-string
# correction problem. Journal of the ACM 21(1):168-173.
#
# The thresholding function was inspired by BSD-licensed code from
#!/usr/bin/env python
#
# Copyright (c) 2013-2014 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to