Category Archives: how-to

Bespin Gotchas

In case of trouble connecting to Bespin from an external machine, try setting the IP address to 0.0.0.0

Either change the file pavement.py:

62
63
64
65
66
67
68
69
70
71
72
server=Bunch(
   # set to true to allow connections from other machines
   address="0.0.0.0",
   port="8080",
   try_build=False,
   dburl=None,
   async=False,
   config_file=path("devconfig.py"),
   directory=path("../bespinserver/").abspath(),
   clientdir=path.getcwd()
),

Or pass it as a command line argument:

paver server.address=0.0.0.0 server.port=8080 start

In case you haven’t noticed, you can even specify the port to start on i.e. run Bespin on a custom port.

Get email updates when your IP changes/ Python DynDns update client

I use DynDns to map my ISP provided dynamic IP to a static hostname. For some reason, the DynDns provided update clients don’t always work for me and often leave my hostname pointing to a dead or (worse) someone else’s IP. I decided to take matter into my own hands and write a script that would email me my IP whenever my DHCP lease expired and my ISP issued me a fresh one. This would ensure I know how to reach back home, even if my hostname was pointing to an old IP.

While going through the DynDns API, I realized it was trivial to update the hostname as well, essentially replicating the functionality of the aforementioned client(s). So I decided to add that as well.

I know this functionality can be replicated via curl + sendmail, but Python is my tool of choice, so just live with it. Without further ado, here’s the script, with an explanation afterwards.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# encoding: utf-8
"""
Script to email IP whenever it changes. Also updates DynDns hostname.
Version 1.0
 
Created by Kunal Dua on 2010-05-10
http://www.kunaldua.com/blog/?p=360
 
This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
"""
 
def send_mail(subject, content):
        import smtplib
        from email.mime.text import MIMEText
        SERVER = "smtpserver"
        PORT = 587  #Use 25 if this doesn't work
        USER = "username"
        PASS = "password"
        FROM = "IPBot <mail@example.com>"
        TO = "user+folder@example.com"
 
        SUBJECT = subject
        TEXT = content
 
        message = MIMEText(TEXT)
        message['Subject'] = SUBJECT
        message['From'] = FROM
        message['To'] = TO
 
        server = smtplib.SMTP(SERVER, PORT)
        server.login (USER, PASS)
        server.sendmail(FROM, TO, message.as_string())
        server.quit()
 
 
def update_dyndns(theip):
        USERNAME = 'username'
        PASSWORD = 'password'
        HOSTNAME = 'example.dyndns.org'
 
        theurl = 'https://%s:%s@members.dyndns.org/nic/update?hostname=%s&myip=%s&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG' % (USERNAME, PASSWORD, HOSTNAME, theip)
 
        import urllib
        conn = urllib.urlopen(theurl)
        #print conn.read()
        conn.close()
 
 
if __name__ == '__main__':
        import urllib2, re
        conn = urllib2.urlopen('http://checkip.dyndns.com/')
        data = conn.read()
        conn.close()
        m = re.search('([0-9]*)(.)([0-9]*)(.)([0-9]*)(.)([0-9]*)', data)
        currip = m.group(0)
 
        lastfile = "lastip.txt"
        allfile = "history.txt"
 
        theipfile = open(lastfile,"r")
        lastip = theipfile.read()
        theipfile.close()
 
        if lastip == currip:
                #print "no change needed"
                exit()
        else:
                histfile = open(allfile, "a")
                import datetime
                thenow = datetime.datetime.now().ctime()
                histfile.write("%s %sn" % (thenow, currip))
                histfile.close()
                theipfile = open(lastfile,"w")
                theipfile.write(currip)
                theipfile.close()
                send_mail(currip, '')
                update_dyndns(currip)
  • Lines 17-22 and 39-41 replace with your email and DynDns settings respectively.
  • Line 22 – My email provider supports redirecting mails to a folder by simply adding the name of the folder before @ sign. For example user+ipupdates@example.com will deliver mail in folder ipupdates of user@example.com. If your email provider supports this, it’s a useful trick to prevent these mails from cluttering up your inbox. If not, simply enter your regular email address.
  • Lines 60-61 initialize 2 files that I use. One is to store the current IP (or the last known IP) and the other is a history of all IP changes. The former is used to compare if the IP has changed since the script was last run and thus if an email needs to be sent + DynDns updated. The latter is not really needed for the script to function properly, and is used to maintain a log of all IP changes – because you can!
  • Line 78 – By default, the subject of the mail is the IP and the body/ text is blank. Feel free to obfuscate your IP if you feel paranoid about sending it in clear text or write sweet nothings to yourself in the body.
  • Note: Before you run this script for the first time, create an empty file called lastip.txt in the same directory as the script or the script will fail. I know I could write a trivial check for this, but I leave that as an exercise for the reader.

Recommended frequency of running this job via cron/ launchd is 10 minutes.

Update: (May 27) I am pretty sure the DynDns API is broken in some way because I can’t get it to update even with this script. The email part is working pretty good for me though!

Ayrton, Diego get new stripes

This week I finally moved Ayrton (the iMac) to Snow Leopard and also managed to find the time to move up Diego (my 5+ years and still going strong Powerbook) to Leopard. Here’s a quick primer for someone looking to upgrade their Mac.

First, I prefer clean installs. No installing over the previous OS and carrying over stuff for me. I like to use this is an opportunity to wipe the stuff and clean up house. If you are anything like me, you keep around a lot of things thinking you’ll need them, but never do. This is the time for you to break free.

So here’s how I do it:
1) Create a bootable copy of the existing Mac using Carbon Copy Cloner onto an External USB/ Firewire drive. USB drives do fine for Intel Macs like Ayrton but a Firewire drive is needed to boot a PPC machine. Via Disk Utility ensure that your drive is using the correct partition scheme to be able to boot your Mac:

Disk Utility

If you want help partitioning your disk, refer this page.

Note: If you can live with non-bootable backups and would just like to have access to your old files, don’t worry about USB/ Firewire/ Partition Schemes and just backup to any drive that your existing Mac can write to.

2) Once CCC tells you that the cloning is complete, reboot your Mac and hold the option while it boots up. It will show you the list of drives you can boot off. You should see the external drive you just backed up on as one of the options. Select it and boot into that drive to make sure the backup you have works fine. This will serve as a fail-safe just in case something goes wrong with the new install and also gives you an option to boot into a full functional OS if you ever feel nostalgic! You’ll also be using this backup to copy back the stuff you need on the new install.

3) Once you’ve verified everything is as it should be, put in the Snow Leopard DVD (or Leopard or whatever) and reboot your Mac. Again, press the option key while rebooting and this time select the DVD drive. When you reach the Welcome Screen, from the “Utilities” menu, choose “Disk Utility”. Erase your current Mac drive – this is the part where you make a clean break. Then proceed with the setup as usual until it’s complete.

Note: I actually used Target Disk mode to install Leopard on Diego, since it doesn’t have a dual layer DVD reader. Will do a follow up post on how to do that.

4) There’s no step 4. You should have a faster, cleaner Mac!

Update: Remember to run “Software Update” on the first boot. Install all updates that are available and reboot your machine (if necessary). After reboot, run “Software Update” again. Repeat, rinse until there are no more updates available. If you are wondering why all updates aren’t available in the first shot, it’s because some updates are dependent on others.

Copying your old stuff
The first time you boot into your Mac you’ll be greeted by the Migration Assistant. Select “From a Time Machine backup or another disk”:

Migration Assistant

Select the hard disk you backed to. On the next screen, I like to select only “Settings” – this is part of the breaking free routine. This will copy your WiFi/ Network settings, time zone etc. Anything else I would need I like to copy manually.

Migration Assistant 1

Now you can manually copy the Applications you really need from your old Mac drive (or download latest versions from the Internet) onto the new. You can also copy the preferences for the same application from the Library/Preferences folder under the previous use to the current one, but most people won’t need that. The only preference file I remember bringing over was the one for Safari Stand and that’s cause I had configured a bunch of quick search shortcuts which I didn’t wanna do all over again.

Other things to note:

  • Passwords/ Keychains – If you want to carry over your saved passwords without any problems, I suggest you create a user with the same user-name and password as the previous Install. With that, you can simply copy the ~/Library/Keychains folder from the previous user folder to the current one and use them normally without any problems.
  • iTunes/ iPhoto – Simply copy the iTunes folder (~/Music/iTunes) and the iPhoto Library (in ~/Pictures) to the same location under the new user/ OS and you should be set.
  • Mails/ Calendars – Simply copy the folders Mail (~/Library/Mail) and Calendars (~/Library/Calendars) to the same location in the new OS and they should work without any problems.
  • This time I also created an Applications folder in my home folder where I keep all Applications I install. So that /Applications stays clean like the day I installed my OS. Not necessary, just an alternative way to organize your stuff.

Applications
If you’re curious, here’s a list of Applications I installed immediately after install (in the order they appear in my Applications folder right now):

  • Acorn – Image editor (Shareware, I have a license)
  • Adium – Multi-protocol chat client (Free)
  • Burn – CD/ DVD burning software for the rare occasions (Free)
  • Clip Menu – Clipboard manager allows you to have multiple items in the Clipboard. Recently switched to this instead of the Quicksilver plugin (Free)
  • Dropbox – Client for the easy to use file sharing service (Free)
  • Firefox – Not my primary browser, but need it for development (Free)
  • LittleSnapper – Image grabber, great for snapshotting entire web-pages (Shareware, I have a license)
  • Oilcan – PostgreSQL client. Pretty basic but does the job (Free)
  • Quicksilver – the grand daddy of all apps (Free)
  • Sequel Pro – awesome MySQL client (Free)
  • Skitch – another screen grabbing + quick sharing app (Free)
  • Skype – Voice Chat/ Calls (Free)
  • Transmit – Trying it out over Cyberduck for my SFTP needs (Shareware)
  • Socilate – A new Facebook/ Skype/ Twitter client, still in beta
  • Textmate – The best text editor on any platform – vi(m)/ emacs fanatics stay away (Shareware)
  • The Unarchiver – Does what is says, throw almost any format at it (Free)
  • Transmission – Torrent client (Free)
  • Tweetie – Twitter client (Shareware/ Free with ads)
  • uTorrent – Giving it a try, over Transmission above (Free)
  • VLC – Media Player that plays practically anything (Free)
  • Xcode

Plugins/ other stuff I installed:

  • ClickToFlash – Safari plugin that disables all flash items until you click on them! (Free)
  • Flip4Mac – To play those pesky WMVs in QuickTime (Free)
  • Growl – Notifications, Mac ishtyle (Free)
  • iStat Menus – An overview of the Mac in your menu bar (Free)
  • Letterbox – Outlook style 3 column view for Apple Mail(Free)
  • Macports – Allows you to install various *nix utilities in a hassle free manner (Free)
  • Perian – Allows QuickTime to play DivX and various other formats (Free)
  • SafariStand – Plugin for Safari that adds various goodies (Free)
  • USB Overdrive – I had some troubles with the software/ drivers Logitech shipped for Snow Leopard and found this one to be much more stable. Allows me to program the gazillion buttons on my mouse to various custom actions (Shareware)

I also installed all three of Parallels, VMWare Fusion and VirtualBox – still not sure which one I am going to keep for the rare occasion I need to dip into the dark side. You can simply copy the image file over from your previous OS and reinstall the software in case you have an image you want to carry forward.

Okay, that’s more than enough information – I’ll update this post and/ or do a new one in case I think of anything else.

Join Google Groups without Google id

If, like me, you don’t have a Gmail id (shock horror!) it can be a pain trying to figure out how to join a Google Group (( I know you can have a Google id that is NOT a Gmail id, but let’s leave that out for now. )) . Some groups (like the Django ones) do have web pages with a sign-up form, but most don’t. So how do you join those groups without going through all the Google id related shenanigans? Simple – type this in your address bar (and remember to press enter!):

http://groups.google.com/group/GroupName/boxsubscribe?email=emailid

Replace GroupName with the name of the group you want to join and emailid with your email id. In case you didn’t make any typos, you’ll find Google telling you that “a confirmation message has been sent” to your id. Just click on the link in that email and you are good to go.

[tags]Google, Google Groups[/tags]

I dig the hole – and then I bitch!

For close to an year now, whenever I have tried to upload a file to any site using Safari – say attaching a file to a mail via webmail – I get this error:


“POSIX error: Invalid argument” (NSPOSIXErrorDomain:22) Please choose Report Bug to Apple from the Safari menu, note the error number, and describe what you did before you saw this message."

I have invariably moaned “Darn Safari” and switched to Firefox or Camino to upload the file and come back to Safari to continue browsing, without bothering to do anything about the problem except maybe hoping it would be “fixed” in the next release. Never so much as “Googling” the problem, which is so unlike me. Until today, which is ironical considering I switched to Firefox 3.0 beta sometime back, which is awesome btw.

I thought I would file a bug-report over at Apple but just before I did that, I thought I would look up the problem. And lo behold, right up there amongst the results I saw this:

That often happens when you have disabled the Safari cache… make sure that ~/Library/Caches/Safari has Read/Write permissions for you.

Sounded like something I could have messed around with because of my “caching is no longer necessary (( Network speeds are high enough not to warrant Internet caching by individual users. ))” belief:


~/Library/Caches lfc$ ls -l Safari
lrwxr-xr-x 1 lfc lfc 9 Aug 3 2007 Safari -> /dev/null

For the uninitiated, that’s the surest way of ensuring that nothing ever gets written to/ read from “Safari”. Look up /dev/null for details.

Removing that link and restarting Safari solved the “problem” – Safari recreates the folder on Startup and everyone lives happily thereafter.

Translate .local hostname to IP address

You can have .local hostnames translated to IP addresses by installing Bonjour on the source machine i.e. the (windows) machine doing the lookup.

Saved me the trouble of changing the IP of my Powerbook in Synergy configuration on the Windows machine every time I got allocated a new one.

Doesn’t matter if you are part of a Windows domain, not part or whatever – just install Bonjour and you are good to go. That is the beauty of Bonjour.

Yahoo! Mail Beta in Camino 1.5

The (not so new now) Yahoo! Mail Beta has never liked Safari/ Webkit. However, it used to work fine on Camino – until recently that is. I guess Yahoo! has changed some stuff, because not only does it dislike Camino now, there is no longer an option to “continue anyway” on unsupported browsers. I don’t like using Firefox on Mac (which supports the Beta), so I needed to find a way to allow the Beta interface to load.

Enter User Agent.

Install User Agent, restart Camino and use the following custom user agent string (“Other” in User Agent settings drop down), which allows the Yahoo! Mail Beta interface to load as of today:

Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2

Save it as Firefox 2.0.0.2 (Mac OS X PPC) if you like.

Enjoy.

[tags]Camino, Internet, Mac, Apple, Software, User Agent, Firefox, Mozilla, Extensions[/tags]