Having a bit of fun at 3 in the morning.
The Python version of the C-style switch statement is either a bunch of if/else's or a dictionary. Going the dictionary route can be ugly looking (not to mention confusing, pulling a value out of a mapping and calling it). This just encapsulates the whole thing and adds some support for a pseudo-default case.
The structure is a bit weird, nowhere near as nice as regular syntax, but if you absolutely have to do this, it makes it easier to read.
Friday, April 08, 2011
Wednesday, April 06, 2011
And now I can't remember what got me on this line of thought...
So here I am, hacking away in Python for oh, a few years now, and I just remembered what got me into Python in the first place.
See, I was using Python's implicit line wrapping with a tuple, and remembered back to when I read an article explaining that Python did that. Before that, all my longer lists weren't wrapped, or wrapped with '\'.
That made me recall the impetus that had me looking for such information in the first place: a Wiimote driver for Linux called CWiid.
Which, coincidently, was the first time I had seriously taken a look at Python.
I was using it to add motion control to Descent 3, which I had just purchased from GoG.com, which was... September 23rd, 2008.
I got something rudimentary going, noted that it would take a lot of hacking to make it better, and I needed to be better at the extension language it used to do it myself. So I waded into that language, which turned out to be Python.
Huh. I never did get back to motion control in Descent 3...
See, I was using Python's implicit line wrapping with a tuple, and remembered back to when I read an article explaining that Python did that. Before that, all my longer lists weren't wrapped, or wrapped with '\'.
That made me recall the impetus that had me looking for such information in the first place: a Wiimote driver for Linux called CWiid.
Which, coincidently, was the first time I had seriously taken a look at Python.
I was using it to add motion control to Descent 3, which I had just purchased from GoG.com, which was... September 23rd, 2008.
I got something rudimentary going, noted that it would take a lot of hacking to make it better, and I needed to be better at the extension language it used to do it myself. So I waded into that language, which turned out to be Python.
Huh. I never did get back to motion control in Descent 3...
Wednesday, June 09, 2010
Quantum Electrodynamic Threshold
Wikipedia: Quantum Electrodynamic Threshold
Whether this is real or not is immaterial to my purposes. What I really want to know is, if one were to be fixed in place about a meter from the edge of one of these things--unaffected by the massive magnetic field--then 1) what would the region look like, and 2) what would happen to matter entering the region assuming the magnetics don't immediately pull it to the center. Also, what does it look like from the inside--looking deeper in, to the side, and out.
Tuesday, November 24, 2009
Ninja Planet
16:55:24
You're standing in the wasteland of the planet Ninja.
The desolate land that stretches out before you is scattered with knobbly trees, swaying lightly in the breeze. Twisted mountain peaks occlude the horizon, silhouetted by the setting sun behind them, and casting shadows that claw their way towards you. The whole landscape radiates a level malovence that should be impossible for mere nature.
You knew the moment you entered the atmosphere in you exploration lander than even coming near this planet was a horrible mistake, but here you are, 3 feet from the ladder back into the craft, standing, frozen in place, and attempting to plan out your escape.
The breeze picks up slightly, pushing a light cloud of dirt off the vacant landscape and into the air. Your eyes catch on the swirls in the ominously blood-red dust. Are they simple vortexes, or perhaps, something else..? A small twig or rock bounces lightly off your right thigh. You don't dare move to see which.
Timing drifts through your head. Approximately five seconds to get to the airlock, two to key it open and another to step through and hit the 30 second cycle sequence. One long minute to run through the abbreviated emergency checklist. 8 minutes to orbit.
Nine minutes and thirty eight seconds. Five hundred and seventy eight ways to die.
This is planet Ninja. In front of you? Well over a thousand ninjas... probably. You imagine them watching; Waiting for weakness. You hope it's your imagination.
16:55:25
You discover your legs won't move. One second of thought, one more way to die, though this one more unanticipated than the rest. Your hand brushes over a small pin stuck to your right thigh.
Inaction has consequences too.
You're standing in the wasteland of the planet Ninja.
The desolate land that stretches out before you is scattered with knobbly trees, swaying lightly in the breeze. Twisted mountain peaks occlude the horizon, silhouetted by the setting sun behind them, and casting shadows that claw their way towards you. The whole landscape radiates a level malovence that should be impossible for mere nature.
You knew the moment you entered the atmosphere in you exploration lander than even coming near this planet was a horrible mistake, but here you are, 3 feet from the ladder back into the craft, standing, frozen in place, and attempting to plan out your escape.
The breeze picks up slightly, pushing a light cloud of dirt off the vacant landscape and into the air. Your eyes catch on the swirls in the ominously blood-red dust. Are they simple vortexes, or perhaps, something else..? A small twig or rock bounces lightly off your right thigh. You don't dare move to see which.
Timing drifts through your head. Approximately five seconds to get to the airlock, two to key it open and another to step through and hit the 30 second cycle sequence. One long minute to run through the abbreviated emergency checklist. 8 minutes to orbit.
Nine minutes and thirty eight seconds. Five hundred and seventy eight ways to die.
This is planet Ninja. In front of you? Well over a thousand ninjas... probably. You imagine them watching; Waiting for weakness. You hope it's your imagination.
16:55:25
You discover your legs won't move. One second of thought, one more way to die, though this one more unanticipated than the rest. Your hand brushes over a small pin stuck to your right thigh.
Inaction has consequences too.
Tuesday, November 03, 2009
Mapping Shipment Tracking
You know when you buy something online and the retailer gives you a number that lets you check on it's progress as it makes it's way to the destination? They generally give you a list events--checked in, checked out, in transit, out for delivery, etc.--along with times.
Sometimes, when I have nothing better to do, I take the locations its been and string them together in Google Maps (guessing because the locations don't usually have addresses, but I can guess pretty well with satellite view.)
But the shipper knows exactly where those locations are, and moreover, the route the truck is actually scheduled to take, though this matters more for delivery than shipment. So here's what you do:
Now your customers can not only read where it is, but can look on a map and see how far away it is.
Better, Google already detects tracking numbers people search for and forwards them to the appropriate page. Leave the mapping data open and get Google to add to the "Forward to Tracking" page a "View tracking in Google Maps" link.
Sometimes, when I have nothing better to do, I take the locations its been and string them together in Google Maps (guessing because the locations don't usually have addresses, but I can guess pretty well with satellite view.)
But the shipper knows exactly where those locations are, and moreover, the route the truck is actually scheduled to take, though this matters more for delivery than shipment. So here's what you do:
- Plot the anticipated route on Google Maps. I know you can, you don't run a shipment company for years without some way to predict the likely path any given package will take.
- Plot the actual route as updates come in. Revise the anticipated route if needed.
- Plot events as pins. Stack multiple events in one pin with timestamps, no need for pin forests at an overnight stay at a warehouse.
- If you have a way to determine the location of the truck, consider plotting that on the map. Perhaps in real time.
Now your customers can not only read where it is, but can look on a map and see how far away it is.
Better, Google already detects tracking numbers people search for and forwards them to the appropriate page. Leave the mapping data open and get Google to add to the "Forward to Tracking" page a "View tracking in Google Maps" link.
Subscribe to:
Posts (Atom)