Skip to content

Instantly share code, notes, and snippets.

View antiface's full-sized avatar

A.G. antiface

View GitHub Profile
#!/usr/bin/env python
#
# Copyright (C) 2011 by Ben Noordhuis <info@bnoordhuis.nl>
#
# 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 the following conditions:
from Population import Population
from Individual import Individual
from random import random, randint
class Algorithm():
#Constants
Uniform_rate = 0.5
Mutation_rate = 0.015
Tournament_size = 5
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]: