I recently set up my iMac to automatically display a background generated by Xplanet and since there seem to be relatively few guides on how to do this I'll attempt to document how I did this. I apologize in advance for any factual errors as this guide is written after I actually set everything up.
I'm assuming that you're running OS X for this exercise although large parts should be usable with other operating systems as well.
First off you should go to macports.org and install MacPorts as you'll use this to install some other software that you'll need.
In addition to MacPorts you'll also need to install the latest version of Xcode for your version of OS X and the X11 extra package which should be on your OS X install disc (I believe it is also available from somewhere on apple.com).
Once MacPorts has been installed you can open a terminal and run the following commands to install wget, Xplanet and ImageMagick, after each command there will be a fairly lengthy compilation and installation process:
$ sudo port install wget $ sudo port install imagemagick $ sudo port install xplanet
Next up you'll need some images, more specifically you'll need a daylight image and a nighttime image (and later on we'll also fetch a cloud map). For this guide we'll use NASA's Blue Marble images, the one I used is this one but there are plenty of others available. For the nighttime image we once again go to NASA, this time to grab the Earth Lights image (if the links stop working you can just google "earth lights site:nasa.gov" and "blue marble next generation site:nasa.gov" to find the pages). If you want to you can resize these images so that the width matches that of your monitor (less work for Xplanet that way).
After downloading the images you should place them in /Users/yourusername/.xplanet/ and name them day.jpg and night.jpg (You'll also have to create the directory ~/.xplanet).
Next up is the cloud image, for this we'll use the one available on the Xplanet site and we'll use the script below to fetch it:
#!/bin/bash outputdir="/Users/yourhomedir/.xplanet" # CHANGE THE PATH! /opt/local/bin/wget -q http://xplanet.sourceforge.net/clouds/clouds_2048.jpg \ -O $outputdir/cloud.jpg
Save the script as ~/.xplanet/cloudfetcher.sh and type in "crontab -e" in your terminal, and add the line below (and change the path).
15 */3 * * * /Users/yourhomedir/.xplanet/cloudfetcher.sh
After you've done this you can run cloudfetcher.sh once just to make sure it downloads the image (and so you don't have to wait until the next time your cron job runs to get the cloud map).
Next up you'll need a config file for Xplanet, I'll assume you'll want it to be ~/.xplanet/config, just add the following block of text to that file and save it:
[earth] map=day.jpg night_map=night.jpg cloud_map=cloud.jpg
Now we're just about ready to try this thing out. Create a file called ~/.bgcreator.sh and put the folllowing in it:
#!/bin/bash xplanetcmd="/opt/local/bin/xplanet" config="/Users/yourhomedir/.xplanet/config" outdir="/Users/yourhomedir/Pictures/xplanet" # Check if the output dir exists if [ ! -d "$outdir" ]; then mkdir -p "$outdir" fi # Create the basic output (change the resolution to whatever width # your screen is and half that for the height assuming you have # source images with an aspect ratio of 2:1 of course... $xplanetcmd -config $config --quality 95 -verbosity 0 --num_times 1 \ --output $outdir/rectangular.jpg --geometry 1920x960 \ --projection rectangular &> /dev/null # Add black borders to cover missing/distorted satellite data /opt/local/bin/convert $outdir/rectangular.jpg -fill black \ -draw "rectangle 0,0,1920,80" $outdir/rectangular.jpg /opt/local/bin/convert $outdir/rectangular.jpg -fill black \ -draw "rectangle 0,880,1920,960" $outdir/rectangular.jpg
If you run this script from the terminal now then it should render an image in ~/Pictures/xplanet/ that looks a lot like the image at the top of this story, all good but how do we make OS X update the desktop? Well, first you run "crontab -e" again and this time you add this line:
*/10 * * * * /Users/yourhomedir/.xplanet/bgcreator.sh
This should render a new background in your output directory every ten minutes, now on to making OS X actually update the desktop.
We'll use a little "trick" to get OS X to reload the image. Right-click on your desktop and go to the settings for the desktop background, click the plus at the bottom left to add another directory to the list of image sources, add the "xplanet" directory from your Pictures directory, set the display type to "centered", make the filler color black and most importantly check the "Change picture" checkbox and set the update interval to five minutes. Now, since there is only one image in the directory OS X will dutifully reload this image every five minutes.
And we're done! Hopefully everything worked without any major glitches, if there are any errors in this guide then feel free to email me to tell me about them.
After spending some time messing with Python's logging module at work I decided to create a new handler for it, this was mainly to clean up my code a bit (and so I wouldn't have to manually call a custom module for sending SMS). Since there appears to be little info online about how to easily create a new handler I've decided to share my approach.
We start off with the actual handler, or a simplified version anyway:
# smshandler.py
import logging
import sendsms # our internal module for sending SMS
class SMSHandler(logging.Handler): # Inherit from logging.Handler
def __init__(self, phonenumber):
# run the regular Handler __init__
logging.Handler.__init__(self)
# Our custom argument
self.phonenumber = phonenumber
def emit(self, record):
# record.message is the log message
sendsms.send(self.phonenumber, record.message)
Now, the above code is pretty useless on its own, we need to use it:
# handlertest.py
import logging
import logging.handlers
import smshandler
# Create a logging object (after configuring logging)
logging.basicConfig(filename=LOG_FILENAME,level=logging.WARNING)
logger = logging.getLogger()
# A little trickery because, at least for me, directly creating
# an SMSHandler object didn't work
logging.handlers.SMSHandler = smshandler.SMSHandler
# create the handler object
testHandler = logging.handlers.SMSHandler('46701234567')
# Configure the handler to only send SMS for critical errors
testHandler.setLevel(logging.CRITICAL)
# and finally we add the handler to the logging object
logger.addHandler(testHandler)
# And finally a test
logger.debug('Test 1')
logger.info('Test 2')
logger.warning('Test 3')
logger.error('Test 4')
logger.critical('Test 5')
If we were to run this script then the only message that would be sent as an SMS would be the last one, 'Test 5'. And this code is simple enough that I doubt anyone using the logging module would have little trouble adapting it to whatever non-standard method of logging they want to employ.
Not that long ago I upgraded to Safari 4.0.1 and all was well, lots of new neatness although the fact that Apple once again managed to change the keyboard shortcuts for the worse annoyed me a bit. Then I discovered a neat little bug...
It seems that when scrolling the saturation of the colors on the rendered page increases a little for every time you scroll, as long as you scroll it out of view then when you scroll back to the same part of the page it will render normally but if you scroll back and forth with some part of the page always visible then slowly you'll start to get the above look.
I'm a bit surprised this somehow managed to make it into production code, especially since I've never seen this kind of behaviour in Safari before.
Apparently resetting your monitor color profile settings will fix this bug for some people but that just makes me even more confused, why does this bug only affect Safari? And why did it pop up now?
Update 2009-10-12: It seems that this problem only occurs for me when using an external monitor, when I'm just using the regular 24" display on my iMac there are no issues.
Today I was setting up a VPN connection between my work laptop and the office to enable me to work from home and ran into a bit of a problem, whenever I tried opening a file at the office in Vim it would be unbearably slow, so slow in fact that getting any work done at all became practically impossible.
After some careful googling and I finally found a solution to my problem and I thought I'd share it here, it really boils down to a couple of simple lines in your .vimrc file.
set dir=C:\\tmp let loaded_matchparen = 1
The first line makes Vim create swap files locally instead of on the remote server. The second line disables parenthesis matching which for some reason generates a lot of disk I/O, without it Vim becomes quite snappy.
Well, today I went to the local Telia store around 7 in the morning and placed myself in line, I was number twelve in line and around thirty minutes after the store opened I was finally let in and got to wait another twenty minutes before I was able to get my hands on an iPhone.
After hastily declining to let them activate my phone and new SIM card I rushed home to unpack and take pictures. So without further ado I now give you an image of the unpacking of a Swedish iPhone 3G.
Well, I've been neglecting this website for quite a while, the fact that the last post before this one is me wishing you merry christmas should tell you that quite clearly. As always I've been working on stuff behind the scenes, new design (that I was disappointed with and scrapped) and some new features for the CMS (which are not finished yet) are both things that I have been working on, but until next time I give you a panorama photo and hope anyone reading this has a great summer, just in case I don't post anything until this fall.