Today I decided to throw together an ugly little script that allows you to search swedish phone numbers from a terminal. It's basically just a tiny python script that uses the public API available from 118100 at utveckling.118100.se.
Just download and unpack the tarball and you should be ready to go (you'll need to have lxml though).
The functionality of the script is sort of limited since the public API is also quite limited, the only arguments except the search string right now are -x to display the raw XML returned by the API and -s for specifying the number of results to return. There is a "secret" feature though, if you search for a phone number and use the -x flag you can find companies as well (it won't work without the -x flag since I stripped out the code for parsing company records).
If you actually end up using the script for something then I'd love to hear from you.
Update 2010-07-21:I've uploaded an updated version of the script with a README file (in swedish) that's available here.
The last couple of days I've begun planning the construction of a DIY boombox for the summer's parties and this is part one of the build. More precisely it's the planning stage.
I'm planning on building the case out of 12 mm thick MDF and after a few revisions I've come up with the above sketch, it's not set in stone but I like the basic design. I'll be making the speakers closed as I don't want to mess around with all the extra trouble of a ported enclosure.
Since I'm building this on the cheap I'm going for a pair of cheap car speakers called Avant CS220, max out at 125 W which the head unit will never touch.
Obviously I'll need something to feed the speakers. I considered just hooking up an mp3 player through an amp but decided against this as it felt a bit to unrefined, instead I decided on using a regular car stereo. The unit I chose was the cheapest I could find with the features I was looking for which in this case was that I could use a USB flash drive or an SD card for music storage instead of CDs. The choice fell on the Denver CAU-415 (although I've been warned about this particular brand).
Obviously I'll need to power this and AC power is out of the question. Since I'm trying to avoid excessive weight I've decided on using a motorcycle battery in the 12-14 Ah range. I've found one model that I'm considering buying that has a very useful feature, the battery acid is in a gel form so it won't spill if the boombox falls over.
Further updates will come once the hardware starts showing up and the build has started.
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.