notes.husk.org. scribblings by Paul Mison.

2013-03-11

Converting a naïve Python datetime object from one timezone to another

text 18:14:00

tominsam:

Suppose you have a naïve datetime object (one without associated timezone information) that you know is in, say, Austin localtime, and you want the equivalent in another timezone, say, UTC.

print my_dt

import pytz
austin = pytz.timezone("America/Chicago")
utc_dt = austin.localize(my_dt).astimezone(pytz.utc).replace(tzinfo=None)

print utc_dt

localize is important. my_dt.replace(tzinfo=austin) is not correct during summer time, for instance.

I can tell this is going to be one of those little bits of code I’ll need to refer to.

(Source: tominsam)

2012-12-10

post/37663261996

photo 22:09:02
An image of Asteroids, showing the normally invisible vector lines that join lettering and the centres of the asteroids and spaceships themselves, taken from a 2008 c’t magazine programming contest to program a player for the game.

An image of Asteroids, showing the normally invisible vector lines that join lettering and the centres of the asteroids and spaceships themselves, taken from a 2008 c’t magazine programming contest to program a player for the game.

2012-10-15

post/33656277591

photo 20:50:33
yoz:

From the manual for the Sinclair ZX81 (via Vicki Brasseur)

“Don’t panic.”

yoz:

From the manual for the Sinclair ZX81 (via Vicki Brasseur)

“Don’t panic.”

2012-07-05

post/26581547183

photo 22:27:54
Perhaps unsurprisingly, given their evidently shaky grasp of social media, the Shard’s inauguration website turns out to have difficulty grasping the concept of timezones.

Perhaps unsurprisingly, given their evidently shaky grasp of social media, the Shard’s inauguration website turns out to have difficulty grasping the concept of timezones.

2012-01-10

post/15603992043

quote 04:00:04
“ The Web is teeming with code because code is text and text is cheap, portable and searchable. Copying is encouraged, not frowned upon. The neophyte programmer never has to learn alone. ”

2010-12-24

Flickr API Corners: ID to URL

text 09:57:07

If you have the URL of a Flickr photo, and want the URL of the page containing that photo, here are two ways, one on the website, and one using the API.

(Why would you want to do this? Well, people seem to be good at breaking the terms of service and not linking back to Flickr with a photo. Perhaps it’s been through ffffound or tumblr, or it’s been used on a blog. If that happens, but you want to find out who posted it, carry on.)

Firstly, using the website. Say your URL is http://farm5.static.flickr.com/4031/4497550401_11d8d708a7_z.jpg. Select up to the number behind the final slash and replace the text with http://flickr.com/photo.gne?id=. You’ll be redirected to a page containing the photo. (It’s possible that the photo will be private, but you’ll still be told who the uploader was.) Note you don’t need to trim things from the end of the URL; Flickr’s smart enough to do that for you.

Secondly, through the API. Open up the API explorer and look at flickr.photos.getInfo. Again, look after the last slash, and copy the number there (in this case, 4497550401) into the “ID” field. Once you call the method, you’ll see a variety of information about the photo, including (at the bottom of the XML) a URL.

It’s possible, if you don’t sign the call, or if the photo’s private, that you’ll need the second (hex) string, in this case 11d8d708a7, in the “secret” field. Providing this grants a little more access to a photo than the ID alone, but you may still find that the photo is private.

There you have it: two ways to get from a Flickr photo ID to the URL of the page containing it.

2010-10-21

post/1368408469

quote 22:06:49
“ More people need to do stupid shit. I mean that from the bottom of my heart. Don’t do it to make money. Don’t even do it to learn hip new technology X. Do it for the sake of doing something stupid. ”
Zack Holmen, author of Facelette: On TechCrunch in Three Hours and $0. Or, as I’d put it: In Praise Of Hobby Programming.

2009-12-31

Crowdsourcing for the Conservatives

text 20:51:55

iamdanw:

The Wisdom of Cameron: Crowdsourcing for the Conservatives

The Conservative Party offered to pay £1m to produce something that can “harness the wisdom” of voters6 hours later Tom Scott launches one. He’s rather fast.

I suspect the Tories were hoping for a bit more than a yes or no voting app. Still, I applaud Tom Scott’s work: either it’ll win the money, in which case the prize has been proven to be a bit of a joke, or it won’t, and it’ll force the party to explain a bit more carefully exactly what it is that they do want. After all, a £1m project usually has a better scope document than a BBC News page.

2009-11-15

post/244683399

quote 11:01:45
“ I did have another job at one point, as a computer programmer, but I kept up with my other work because it was so much more enjoyable. I did the two — computer programmer by day, prostitute by night — for three or four months. ”
Belle de Jour, in the Times Online in a long interview where she reveals her identity.

2009-08-11

post/160430634

quote 10:44:10
“ 200 times as many COBOL transactions take place each day than Google searches – a figure which puts the influence of Web 2.0 into stark perspective. ”

what

more

pages