Monthly Archives: May 2013

Richard Feynman Describes the Scientific Method

He’s the most (smart * entertaining) guy you’re likely to experience. Even if you think you understand the scientific method, you owe it to yourself to watch this: http://youtu.be/EYPapE-3FRw

Advertisements

The Universe is Smaller Than You Think

To understand how small the universe really is, you must first understand how large it is — it’s larger than you think, if you haven’t read about the expansion of space. The best current estimate for the age of the universe is just under 14 billion years, so the simple value for the size of the observable universe would be just under 14 billion light years in every direction from Earth. With expansion it’s much larger than that: about 46 or 47 billion light years in any direction, or 93 billion light years across. I can ride a bicycle 100 miles in a day — it would take me 15,000,000,000,000,000,000 years to ride across the universe. I’d better get started.

Translate that into volume and the number gets crazy. If our solar system has a radius of 124 astronomical units (that’s how far out Voyager I is about…now) then the universe is about 13,000,000,000,000,000,000,000,000,000,000,000,000,000 times the volume of our solar system.

Okay, so the universe is really big, right?

No

In fact, it’s quite the opposite. Allow me to explain. The estimate for the mass of the universe ranges from about 8×10^52 kg to just under 4×10^54 kg. To quote Marty McFly, “Whoa. This is heavy.”

But not heavy enough. The universe is almost unimaginably sparse. There’s a lot of space, but not a lot of stuff. If you gathered all the mass in the universe together, it would be incredibly large in terms of days to bicycle it, but incredibly small compared to the space it normally occupies: the universe.

For comparison, the nearest star to our sun is Proxima Centauri, a little more than four light years away. Round that up to five light years. Fill a sphere with water, centered on our sun and with radius 5 light years, and in addition to having the deepest swimming pool in history, the resulting mass would be about 4.3×10^53 kg, or about the same as the mass of the observable universe. So:

Everything we know in the universe — every planet, every star, every galaxy, the dark matter, the dark energy, all of it — weighs about the same as a sphere of water that barely reaches our nearest neighbor star.

That sphere is large compared to us — it would take about 1.6 billion years to bicycle across it — but it’s really small, even compared just to our galaxy. If you were looking at an image of the Milky Way on your monitor, you wouldn’t be able to see that ball of water. Yes, even with a retina display. And compared to the universe, the sphere ridiculously small. The universe could contain about 1,000,000,000,000,000,000,000,000,000,000 of those spheres. Not so big, eh? Another way of looking at it is to say that on average the universe is 1/1,000,000,000,000,000,000,000,000,000,000 as dense as water.

Note that if this hypothetical sphere of water suddenly popped into existence, it would immediately start collapsing in on itself at near the speed of light. At the surface — 5 light years away from the center of mass — the water would experience a gravitational force roughly a billion times that at the Earth’s surface. Did I say immediately? Ignoring relativistic effects, it would take the water at the surface about a thirtieth of a second to accelerate to near light speed.

I’m not sure what would happen to the sphere of water as it crushed itself, but I’d be happy to observe from a distance — let’s say a few billion light years away, just to be safe.

You might be thinking about calling shenanigans, based on those really big stars like NML_Cygni. It’s the largest known star: if it were put in place of our sun, it would engulf Jupiter, but not reach Saturn. But for all its size — about 5 billion times the volume of the sun — it has only about 40 times the sun’s mass. At its surface, it’s more vacuum than matter. It might be hard for NML Cygni to burn you using thermal heat alone, because it’s so thin. Don’t try it though, the radiant energy would easily cook you.

Water is great for comparison, but at a molecular level it’s still mostly empty space. To pack a little tighter, consider the density of a neutron star, generally over 1 billion times the density of water. So if you pack it into one big nuclear mass, the entire universe would fit in a sphere only about 300 astronomical units in radius — give Voyager I a couple hundred years and it will have traveled that far. The gravity at the surface of that sphere would be almost unimaginable.

If we traded the current universal setup for either of these spheres, the entire rest of the universe would be empty — completely empty. Of course, it’s very nearly empty now.

Keeping a clean desktop and downloads folder

I decided I’d had enough of my Mac being slow to reboot because of too many items on the desktop. Why that should be a dealbreaker, I have no idea, but when the Finder is starting you can watch the things render one… by… one… I don’t keep a particularly messy desktop — there are 42 items on it right now — but apparently that’s too much.

It’s also a usability thing. The desktop and the downloads folder are where things get put by default. I rarely need the things there for more than a few days in the case of the desktop, or a few minutes in the case of the downloads folder.

I already have folders where I toss things when I clean up. Those folders are a mess. They have hundreds of items, but I don’t care. I’m going to use an AppleScript and put it in cron. I haven’t touched either of those technologies in years, so it should be interesting.

The AppleScript

First forgotten fact: Macs use “:” as a delimiter in paths. Everything else I use shields me from that. Also, AppleScript doesn’t understand “~geoffcanyon:Desktop” Still, getting all the files and folders on the desktop is easy:

       tell application “Finder” to every item of folder “Macintosh HD:Users:geoffcanyon:Desktop”

Ah, it’s been some time since I used AppleScript. I forgot about

       path to desktop folder

So it’s:

       tell application “Finder” to every item of folder (path to desktop folder)

Hmm, what’s the property name for “Date Modified”? Time to open the Finder’s dictionary.

RANT INTERLUDE

Many articles complain about AppleScript’s syntax. Here’s an example from John Gruber. He says, “…it turns out that an English-like programming language didn’t really enable a large number of users to become programmers. And conversely, AppleScript’s English-like syntax often made (and to this day continues to make) things more difficult and confusing for scripters, not less.” That’s typical of complaints against AppleScript, and it’s clearly wrong. There are two points:

Beginners
Look at HyperCard, or LiveCode, and it’s clear that an English-like language can ease non-programmers into programming. Thousands of people programming today got their start in HyperCard. So while it might be that, as Mr. Gruber says, “…the number of programmers in the world who consider AppleScript their favorite language could fit in a very small car…” the number of programmers who consider an English-like syntax their favorite would fill…okay, maybe not a stadium, but they’d crush that car.

Syntax
AppleScript syntax isn’t challenging, unclear, or ambiguous — the application dictionaries are. They can (and often must) be incredibly detailed, and the documentation is often non-existent. I once spent several hours figuring out how to add a page to a document in an application. It turned out that the application’s documents don’t contain pages — they contain spreads, and spreads contain pages. But blaming AppleScript for the complexities of application dictionaries is like blaming the english language for Gravity’s Rainbow.

END RANT

The Finder’s dictionary tells me “modification date” is what I’m looking for. A quick google search tells me that I can do date math using seconds. So to find everything on the desktop older than a day:

       tell application “Finder” to every item of folder (path to desktop folder) whose modification date < (current date) – 86400

Nice, this is starting to look like a one-liner, albeit a long one. There is one item I want to exclude from this. I keep an alias to one of our servers on my desktop, so I don’t want to lose that.

       tell application “Finder” to every item of folder (path to desktop folder) whose (modification date < (current date) – 86400 and name is not “Public”)

Wait, that’s not a good way to do this. I make it more flexible with labels. Back to the dictionary! Looks like it’s “label index” so:

       tell application “Finder” to every item of folder (path to desktop folder) whose (modification date < (current date) – 86400 and label index is not 6)

(It happens that green is 6 on my Mac) Okay, I’m selecting the items I want. Now it’s time to move them to the archive:

       tell application “Finder” to move (every item of folder (path to desktop folder) whose (modification date < (current date) – 86400 and label index is not 6)) to folder ((path to home folder as string) & “Desktop Archive”) with replacing

“With replacing” is easy — no error checking for duplicated file names — and it’s unlikely the archive will contain something that has the same name that isn’t the same file, and that I would want that earlier file back. Maybe that will bite me someday. I added a line to do the same for the downloads folder, but without the label restriction. The end result is:

       tell application “Finder”
              move (every item of folder (path to desktop folder) whose (modification date < (current date) – 86400 and label index is not 6)) to folder ((path to home folder as string) & “Desktop Archive”) with replacing
              move (every item of folder (path to downloads folder) whose modification date < (current date) – 86400) to folder ((path to home folder as string) & “Downloads Archive”) with replacing
       end tell

Now to cron this thing…

…okay, a little reading tells me that cron isn’t the preferred tool on Macs, so I’m looking at launchd and launchctl, particularly this tutorial. I saved the AppleScript as an app as “/Users/geoffcanyon/Scripts/Archive.app” I opened “/Users/geoffcanyon/Library/LaunchAgents” to see what examples were there. A little reading online and I created a new plist file at “/Users/geoffcanyon/Library/LaunchAgents/com.apple.cleanupfiles.plist” Viewed as text (I used the Property List Editor app to create it) it’s:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.apple.cleanupfiles</string>
    <key>Program</key>
    <string>/Users/geoffcanyon/Scripts/Archive.app</string>
    <key>StartInterval</key>
    <integer>86400</integer>
</dict>
</plist>

To load that, in the terminal use:

    launchctl load /Users/geoffcanyon/Library/LaunchAgents/com.apple.cleanupfiles.plist

To test it immediately (again, in the terminal):

    launchctl start com.apple.cleanupfiles

Note that the load command uses the actual file path, while the start command uses the label string from within the file.

I tried the above, and it doesn’t work. For some reason launchd doesn’t want to run the AppleScript app. Well, you can also execute an osa script. So I changed the plist to try that. I saved the script itself as “/Users/geoffcanyon/Scripts/Archive.scpt” With that in place, here is the plist to execute the script. I also changed the interval to 3600 so it runs every hour:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.apple.cleanupfiles</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/osascript</string>
        <string>/Users/geoffcanyon/Scripts/Archive.scpt</string>
    </array>
    <key>StartInterval</key>
    <integer>3600</integer>
</dict>
</plist>

Save the files, then

    launchctl unload /Users/geoffcanyon/Library/LaunchAgents/com.apple.cleanupfiles.plist
    launchctl load /Users/geoffcanyon/Library/LaunchAgents/com.apple.cleanupfiles.plist
    launchctl start com.apple.cleanupfiles

That works. While I was at it I modified the AppleScript so it checks to see if a backup is needed, then creates backup folders and names them with a time-stamp. That takes care of duplicate file names. I also changed the label filter to exclude all labeled items. Here’s the AppleScript:

       set myDateString to ((10000 * the (year of the (current date)) + 100 * the (month of the (current date)) + the (day of the (current date))) as string) & “-” & the time of the (current date)
       tell application “Finder”
              set itemList to (every item of folder (path to desktop folder) whose (modification date < (current date) – 86400 and label index is 0))
              if itemList is not {} then
                     make new folder at ((path to home folder as string) & “Desktop Archive”) with properties {name:myDateString}
                     move itemList to folder ((path to home folder as string) & “Desktop Archive:” & myDateString)
              end if
              set itemList to (every item of folder (path to downloads folder) whose modification date < (current date) – 86400)
              if itemList is not {} then
                     make new folder at ((path to home folder as string) & “Downloads Archive”) with properties {name:myDateString}
                     move itemList to folder ((path to home folder as string) & “Downloads Archive:” & myDateString)
              end if
       end tell

Conclusion

Now my desktop and downloads folder are neat all the time, with just the most recent things I’ve been working with in them. Here are the steps without all the commentary:

  1. Create a folder “Desktop Archive” in your home folder.
  2. Create a folder “Downloads Archive” in your home folder.
  3. Create an AppleScript with the above script in it, and save it someplace. Note the path to the file.
  4. Create a plist file with the above plist in it. Substitute the path to your .scpt file, and save it in your /Library/LaunchAgents/ in your home folder. Note that your Library folder is likely not visible, so this part can be a bit tricky.
  5. In the Terminal, use launchctl load <your plist> to schedule the agent to run.
  6. If you want to see immediate results, use launchctl start com.apple.cleanupfiles in the Terminal (assuming you haven’t change the label string).

That’s it!

UPDATE:
I found a flaw in the above: if the above script runs while a file is downloading, it will go ahead and archive it, screwing up the download. This script should fix that (pending testing):

       set myDateString to ((10000 * the (year of the (current date)) + 100 * the (month of the (current date)) + the (day of the (current date))) as string) & “-” & the time of the (current date)

       tell application “Finder”
              set itemList to (every item of folder (path to desktop folder) whose (modification date < (current date) – 86400 and label index is 0))
              if itemList is not {} then
                     make new folder at ((path to home folder as string) & “Desktop Archive”) with properties {name:myDateString}
                     move itemList to folder ((path to home folder as string) & “Desktop Archive:” & myDateString)
              end if
              set itemList to (every item of folder (path to downloads folder) whose (modification date < (current date) – 86400 and label index is 0 and not (name extension is “download”)))
              if itemList is not {} then
                     make new folder at ((path to home folder as string) & “Downloads Archive”) with properties {name:myDateString}
                     move itemList to folder ((path to home folder as string) & “Downloads Archive:” & myDateString)
              end if
       end tell

Has Google image search become a Stepford Wife?

I don’t know when this happened. Maybe I’m crazy. The first  query I noticed was “treehouse.” Below is the first page of image results. There are a lot of pretty pictures there — too pretty. None of them look like they were taken by a parent, particularly because there are no children in any of them.

Image

“Car” produces similar results: all stock-photo looking images, with (almost) no people:

car

This isn’t universal. Here are the results for Half Dome:

halfdome1

Notice how at least some of the shots look like they were taken by amateurs. This is even more apparent on the second page of results:

halfdome2

 

This seems to be going on right now; earlier today, “bike” returned regular results: pictures of bikes, people on bikes, drawings of bikes, etc. Apparently the Stepford Wives got to “bike” in the last few hours, because now it returns this:

bike

 

I’m not sure what to make of this. It feels like the humanity has been sucked out of the results, but the pictures sure are pretty. Is everyone else seeing this? Do you remember what it looked like before? Am I out of my mind?

Some calculations on whether Big Brother is recording every cell phone conversation

The idea that the U.S. government records all domestic communications has been in the news recently. That seemed like an incredible claim, so I decided to do the math.

According to this random site I found with a google search, there are about 300 million cell phones in the U.S. If each of them talks on average for about 500 minutes per month (a not-so-random site), and all calls are U.S. to U.S., that works out to 300,000,000 * 500 / 2 minutes per month, or 75,000,000,000 minutes per month, or about 1.25 billion hours per month. Of course, that doesn’t count non-cellular calls.

If it takes 10 megabytes to store an hour of phone call, that’s 12.5 billion megabytes per month, or 12,500 terabytes. Let’s say that you can buy terabyte drives for $50 in bulk. That’s $625,000 per month in hard drive expenditures. That’s less than five hours of flight time for a B2 bomber. There’s the question of servers, a data center, networking, etc. If that increases the cost by 20x, then we’re up to $12.5 million per month, or about $150 million per year, a rounding error in the federal budget.

Looking at it another way, one estimate (from a couple years ago) is that Google has about 1 million servers. That means that google could easily manage this data flow. Tack on speech recognition software for transcripts, and this kind of surveillance seems not just possible, but pretty straightforward and fairly likely.

Breaking out my tinfoil hat now…