Redirecting output from Fabric

August 16, 2011
Current (1.2.0) release of Fabric doesn't have any logging implemented, which means usual redirects like this one won't work:

$ fab dummy > outfile
IOError: [Errno 25] Inappropriate ioctl for device
Piping doesn't work either:

$ fab dummy | less
IOError: [Errno 22] Invalid argument
Current workaround is to pass pty=False to your function. Example:

def dummy():
  run('cat /proc/loadavg', pty=False)

Using Google Latitude to print current location

August 1, 2011

Updated version

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Ruslan Valiyev
import time
import urllib2
import simplejson as json
from geopy import geocoders

# Get your own keys at:
GOOGLE_LATITUDE_KEY = 'your_key_goes_here'
GOOGLE_API_KEY = 'your_key_goes_here'

# Getting data in JSON
class GLatitude:
  def __init__(self,uid):
  def getLocationData(self):
    return json.load(urllib2.urlopen(GOOGLE_URL % self.uid))
  def getCoords(self):
    return self.getLocationData()['features'][0]['geometry']['coordinates']
  def getTime(self):
    return self.getLocationData()['features'][0]['properties']['timeStamp']

# Convert epoch to human time
def TimeConvert(epoch):
  return time.strftime('%d %b %Y %H:%M', time.localtime(epoch))

def main():
  g = geocoders.Google(GOOGLE_API_KEY)

  myLocation = gl.getCoords()

  return TimeConvert(gl.getTime()), g.reverse(myLocation)

if __name__ == '__main__':
    print main()
Sample output:

>>> import latitude
>>> latitude.main()
('04 Aug 2011 08:42', (u'A1 motorway, 1218 Grand-Saconnex, Switzerland',
(46.239181299999998, 6.1208168000000001)))
PS. Don't forget to grab the latest version of geopy.

Xcode 4.1 fails to install on clean OS X 10.7

July 31, 2011

I've been having issues setting up (now) free Xcode 4.1, downloaded from App Store.

The installer would simply hang saying "Installing files..." (screenshot)

Most of related problems I read about on Apple Support Communities were apperently solved by killing the ItunesHelper process and fixing disk permissions, but this wasn't the solution in my case.
Proof 1: ItunesHelper not running (screenshot)
Proof 2: Disk permissions are fixed (screenshot)

After some debugging, I noticed /var/log/install.log was complaining about "", which made me end up editing a file called iPhoneSDKSL.dist

So, here's how I fixed it and got it installed.

After downloading Xcode, go to Applications. Copy the entire "Install Xcode" to, say, your Desktop.

Go to Desktop, right-click on "Install Xcode" and go to "Show Package Contents". Navigate to Contents/Resources.

Right-click on Xcode.mpkg and go to "Show Package Contents". Go to Contents and open iPhoneSDKSL.dist in TextEdit. Find the following code block:

//10.7 or above
if( system.compareVersions(, '10.7') == -1 )
my.result.type = 'Fatal';
my.result.message = system.localizedStringWithFormat('ERROR_OSVER', '10.7');

return true;

Comment the code like this:

//10.7 or above
// if( system.compareVersions(, '10.7') == -1 )
//my.result.type = 'Fatal';
//my.result.message = system.localizedStringWithFormat('ERROR_OSVER', '10.7');
return true;

Save the file and quit TextEdit.

Now head back to "Desktop/Install Xcode/Contents/Resources" and double-click the Xcode.mpkg icon. The installation should work this time (screenshot) & (screenshot).

osx and xcode

Sticking with Google

July 29, 2011
Now the blog (and other stuff like my mail) is running on Google App Engine, but it's also managed by Google Apps! Isn't it nice of Google to provide all this for free?

$ host is an alias for is an alias for has address has IPv6 address 2a00:1450:8002::79

Voipbuster balance monitoring

July 29, 2011
Script to check Voipbuster balance. If it goes below 1€, an email will be sent.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Ruslan Valiyev
import urllib
import urllib2
import BeautifulSoup
import smtplib
from email.MIMEText import MIMEText

smtpserver = ''
smtpfrom = ''
smtpto = ['']
username = 'voipbusteruser'
password = 'voipbusterpass'
url = ''
login = url+'/index.php?part=tplogin'

o = urllib2.build_opener(urllib2.HTTPCookieProcessor())
data = urllib.urlencode({'user' : username, 'pass' : password})
f =, data)
s =

q ='/calls.php')
s = BeautifulSoup.BeautifulSoup(
balance = s.findAll('b')[1].string.replace(' ', '').replace('€', '').replace(' ', '').replace('\n', '')

if float(balance) < 1:
  subj = 'Voipbuster balance for %s is low!' % (username)
  msg_text = 'Current balance: %s euros.' % str(balance)
  msg = MIMEText(msg_text)
  msg['Subject'] = subj
  s = smtplib.SMTP()
  s.sendmail(smtpfrom, smtpto, msg.as_string())