Saturday, February 25, 2012

Scumbag News


Tutorial: Make your desktop picture match the current weather

It changes with the weather!
I've had a problem recently.  I go to campus at 8am and sometimes don't leave until late afternoon or night.  And there are no windows.  Going in when it's sunny and coming out to find snow somehow makes life a little more depressing than it has to be, not because I don't like snow, but because I don't like the idea of being 100% cut off from the world.

Solution: By throwing together a little Unix code, AppleScript, and a free program called GeekTool, I make my desktop picture change to reflect the weather outside.  I use GeekTool to automate running the script at hourly intervals.  You could do this a lot of different ways with plists or other programs, but since I use GeekTool anyway it was the easiest.

What happens is that once an hour, GeekTool executes a Unix shell command that opens an AppleScript script.  The script (using a shell command) gets your current weather from an NOAA website, and sets a JPEG on your computer with a name that matches the weather as the desktop.

End result: your desktop picture matches the weather outside.

The How-To Part:

1. Make a folder in your Pictures folder called "Weather"

2. Open the "AppleScript Editor" application, make a new script, and copy and paste the code below into it:


--
--  DesktopWeatherman.scpt
--  2011.2.25
--  Mark Sawyer
--  bioquizzical.blogspot.com
--

#Find your weather region by going to www.weather.gov and clicking where you live.  The 3 letter code at the end of the new URL should be your region (ex: FOO)
#Change all instances of "CLE" to the weather region you're in (ex: /data/FOO/RWRFOO)
#Change "HOPKINS" to the city you're in (look at www.srh.noaa.gov/data/FOO/RWRFOO to find out what it calls your city)
#For example, if your region is FOO and you live in YUBA, the URL in the code should say "http://www.srh.noaa.gov/data/CLE/RWRCLE | grep YUBA"

#NOTE! Your region might not have a RWR file.  If so... good luck!
# Also, your region might use slightly different weather codes. Look at www.srh.noaa.gov/data/FOO/RWRFOO to find out what codes it uses. 


set current_weather to do shell script "curl -s http://www.srh.noaa.gov/data/CLE/RWRCLE | grep HOPKINS | awk '{ print $2 }'"

if current_weather is equal to "LGT" then set current_weather to do shell script "curl -s http://www.srh.noaa.gov/data/CLE/RWRCLE | grep HOPKINS | awk '{ print $2,$3 }'"

set localFile to "~/Pictures/Weather/" & current_weather & ".jpg"

tell application "System Events"
tell desktop 1
set picture rotation to 1
set picture rotation to "never"
set picture to POSIX file localFile
end tell
end tell
It should look like this by the end.

3. Save the script in your "Weather" folder as "DesktopWeatherman.scpt".  You'll need to edit it to match your region and city.  Everything in the code immediately after a "#" is a comment. Follow the instructions in the comments.

4. Download and install GeekTool.  Make sure to click the "Enable" box when you install it!

5. Make a new Geeklet by dragging the "Shell" icon onto your desktop.  It doesn't matter where you put it.

6. In the "Properties" window in GeekTool, in the "Command" box type
osascript ~/Pictures/Weather/DesktopWeatherman.scpt
7. Still in the "Properties" window, in the "Refresh every" box, type 1800 (the weather site only updates every hour, so checking more frequently doesn't really make a difference).



8. Fill your Weather folder with pictures to match each possible weather status.  The name of each picture should be the weather status followed by ".jpg".  The status names might vary by region.  Follow the comments in the code to see what your region uses.  In most regions, the possible weather codes (I've seen) are:
SUNNY, FAIR, MOSUNNY, PTSUNNY, MOCLDY, PTCLDY, CLEAR, DRIZZLE, LGT RAIN, RAIN, FLURRIES, LGT SNOW, SNOW, FOG, MIX PCPN.
I'm not clear on exactly what some of these mean either, but this might help.

The directory should now look something like this:

I don't have files for every weather condition quite yet...

If it loads some default Mac picture instead of one of your weather pictures, it means you don't have a picture to match the current weather status.

9. To make it show the weather status in words on your desktop, make another Shell geeklet and in the "Command" box type:
curl -s http://www.srh.noaa.gov/data/CLE/RWRCLE | grep HOPKINS | awk '{ print $2 }'
Of course, you need to change "CLE" and "HOPKINS" just like you did in the AppleScript.  The font I use is called "Trade Winds" and from Google Webfonts.

And that's it!  For obvious reasons this will only work in the USA, and you might have to tweak things to get it to work in your weather region. I guess outside of the USA you could still have it match the weather for a US city, I just have no idea who you would do that.

Anyway, enjoy your window to the world!

Attribution: The picture I used for my backgroup in the title was on so many scores of websites that I could not find the original owner.  Please let me know if you can!

Sunday, February 19, 2012

Watson

(Note: when I drew this about a year ago, it wasn't intended to be specific to one party or another)

Thursday, February 9, 2012

Averages, Probability, and the Indivisible: Why you're morphine free in 1 week (probably)

Math makes everything less fun, right?


This morning I sat through a lecture discussing half-lives of drugs, and the lecturer declared that "If a drug follows first-order kinetics [meaning its concentration is cut in half every few hours] it will never be entirely eliminated from your body.  So, you still have some of the formula you drank as a baby!" Okay, so Aristotle thought of this one too.  But zealots beware: the world does not have an infinite resolution for everything.

The basic principle here is simple: if you have three baseballs, and you divide them into two groups, one group gets two baseballs and the other gets one.  You can't have 1.5 baseballs.  Sure, a half cup of water is a half cup of water, but a half baseball is a useless lump of string and leather, and at that point it has ceased to be a baseball.  Thus, you cannot have half a baseball!  If you say you have 1.5, it really means you have either one or two on average.  You cannot always divide by two, and as numbers get small, the remainder gets to be a significant part of what you have.  No matter how big of a number you start with, if you keep dividing you eventually get to a number that is small enough that it matters if you can cut a baseball in half.  Basically, we're going to have a deathmatch between Achilles and the Tortoise and the Wheat and Chessboard problem, but we're going to let the chessboard have as many squares as it needs.

Let's say you take a 20mg dose of morphine (285.34 g/mol, half life of about 2 hours).  20mg does not represent an infinite number of molecules.  Cue Avagadro's number and a bit of multiplication that I'll omit (if you'd understand it, you probably already know it), and we see that 20mg of morphine is about 4.22 * 10^19 molecules of morphine.  After one half life, that number is cut in half (2.11 * 10^19).  After two, you divide by 4.  After three, divide by 8.  After 10 half lives, 4.12 * 10^16 molecules left.  Still a lot, right?  After ten half lives, you are dividing the original number by 1024.  That's a lot, but not compared to the original 42,200,000,000,000,000,000 molecules.  Well, because we're dividing by powers of two, just one more half life and we're not dividing by 2048, then 4096, etc.  In the case of morphine, at 65 half lives you have 1.1 molecules of morphine still around.  Of course, this is impossible,  we can only have zero, 1, 2, etc.  So, even assuming that each division was a perfect half, we can only have 66 half lives before the morphine is gone entirely.  Morphine has a 2-hour half life, so the bottom line is that after about 132 hours (about 5.5 days, if you're into counting "half days"), your body will not have a single molecule of morphine in it.

Now, of course what really happens is that each half life does not eliminate exactly half of what's in you. Heck, it might be off by trillions of molecules each half life, but when we're working with a trillion-trillion-trillion-etc... molecules, we don't care too much.  But what does that mean for any given molecule of morphine in you?  We might think of a half life as just another way of saying "a length of time during which any given molecule has a 50% chance of being eliminated." For big numbers, that expression behaves like a fraction, because on average 50% end up being eliminated each half life.  However, as things get small, you have to go back to the probability definition.

In conclusion, all of this really illustrates is two things:
1)You can only divide things by two infinitely if it is some quantity that it makes sense to have a half of.
2)Averages and statistics work fine as fractions if you are working with a big population (like saying 25% of people die of cancer), but when you get down to single items, it's more useful to think of them as probabilities (I have a 25% chance that I will die in an accident).

Of course, that 25% could mean that 75% of people have 0% chance of dying from cancer, and the other 25% are genetically doomed to cancer with 100% certainty, but that's a discussion for another day.

[Note: I'd love to give proper attribution for the art above, but I can't find the original source.  Let me know if you know it.]

Tuesday, February 7, 2012

Economics and the Autonomous Car

The Only Designated Driver Batman Ever Needed

I'll start with a disclaimer: I'm really excited for self-driving cars.  I may be waiting decades for my Batmobile that can come pick me up after a night of crime-fighting or, you know, fire rockets as necessary, but that doesn't mean I have to be stuck actually driving my car for another 10 years.

With Google, BMW, and other hopping onto the autonomous bandwagon, we are starting to see some real backing for self-driving cars.  Google has announced that it has driven hundreds of thousands of miles, while BWM has braved the German Autobahn sans human input.  Given that crashes will eventually happen with these vehicles, questions have arisen about who would be responsible in the event of a crash: the human driver or the company who made the car.  To me, this question relies on the answer to two other questions:

First, how good should this technology be before we put it in consumer hands?
Second, who is responsible for crashes now?

The answers seem fairly straightforward to me.

First, autonomous cars need only drive as well as people to be unleashed.  Computers make mistakes, sure, but so do people;  the real questions is whether computers or humans cause more accidents.  As I was walking just this morning beside a busy one way street, a saw an all too common occurrence.  Driver A was tailgating Driver B.  Driver A checks to see if the left lane is clear and starts changing lanes to pass Driver B.  Just then, Driver B sees that traffic in front of him has slowed down, and hits the brakes.   A little brakes here, a little gas there, and BAM, Drivers A and B are  both headed to the shop.  A computer probably wouldn't have made that mistake, as it can check lanes and look forward at the same time.  A computer doesn't change the radio station, adjust its hair, take phone calls, text behind the wheel, etc.  Of course, they can also have a tough time telling animals and styrofoam blocks apart.  The point is, both people and computers have their faults, and the real question isn't what the faults of either one are, but which option ends up hurting more people.  If it is conclusively proven that, for example, humans average 2 fatalities per 1,000,000 miles driven while computers also average 2, the emphasis shouldn't be that computer-driven cars are killing people, but that they're as safe as their flesh and blood alternative.  If the computer-kill number drops to 1 per 1,000,000 miles driven that would be cause for celebration, while still soberly acknowledging that the technology has room for improvement.


Second, in regard to responsibility, I see no reason to shift it from the current party held liable: insurance companies.  Okay, in criminal cases things might get fuzzy, but as far as the financial ramifications, be they injury, repairs, etc., if I were to rear end someone today my insurance would pay the costs.  Not the car manufacturer, not me – my insurer ends up with the bill.  If they notice that self-driven cars crash half as much as human-driven cars, they could give you a fat discount for letting the computer take the wheel.  If they notice Chevy's autonomous cars are crashing twice as much as Ford's, they would charge you double for driving a Chevy.  I get my autonomous car, the insurer maintains profits, crash victims of autonomous or human-driven vehicles still have repairs paid for, and everyone has a nice day.  In the end, it doesn't matter if it was the vehicle or the driver's fault, it only matters that accidents happened, and insurers and drivers alike would like it to happen less often.

As far as criminal ramifications, I think that question is really secondary to our first question.  If autonomous cars are as safe or safer than human-driven cars, can you hold a manufacturer liable for accidents caused by their vehicles?  If so, should they also be rewarded for all the accidents they prevented? The same for the drivers who decide to switch on the autopilot.  Unless car manufacturers, you know, purposefully program their cars to hit pedestrians, we should embrace the life-saving potential this technology has, even if it comes with a few accidents along the way.

In short, the answer to it all is that