Wednesday, October 13, 2010

Removing the crap from iTunes 10.0.1

I use iTunes to play music on my osx laptop, though I have been very disappointed with the latest updates to iTunes. It seems that apple thinks that I want to be a part of yet another social network and thus has enabled "Ping" on my iTunes account.

First thing I did was to "opt-out" of ping (wtf Apple, these things should be opt-in), a quick Google search reviled that it is fairly easy to do (after you agree to their new terms and conditions of course). Though even after I did this, the iTunes interface is still littered with crap about Ping (including the new side bar that was added with 10.0.1). It seems that you can removed these with a quick jump into Terminal.app with the following commands:
defaults write "com.apple.iTunes" "disablePingSidebar" -bool "TRUE"
defaults write "com.apple.iTunes" "hide-ping-dropdown" -bool "TRUE"

I also discovered that you can get the minimize/zoom/exit buttons back with some other plist values:
defaults write "com.apple.iTunes" "full-window" -boolean "YES"

While I am at it, if you want to disable to links to the itunes store from next to your songs, you can use this option:
defaults write "com.apple.iTunes" "show-store-arrow-links" -bool "FALSE"

Don't forget to restart iTunes after you have made these changes.

Wednesday, March 3, 2010

Making the switch to xmonad (on ubuntu)

I have been using xmonad under unbuntu for nearly a year now (and have been VERY happy). I thought it was finally time that I share my method for configuring/setting up xmonad.

I run xmonad under gnome, this allows a lot of the magic of Ubuntu to continue working (such as network manager configuring wifi), and helps keep the amount of manual configuration down to a minimum.

Monday, January 4, 2010

NCSS Python Golf

It is time again for me to run a Python Golf challenge... The aim? To write a python program that solves a problem in the least number of bytes (of source code).

The first of a few problems is:

Given a list of words on stdin (one per line), find the words that have the largest number of anagrams in that list.

Print all of the words that have the meet the criteria of having the largest number anagrams (One per line, in alphabetical order).

This competition has now finished. The winner was Nick Cooper at 103 bytes, with the following awesome solution:
import sys
s=sorted
o=s(sys.stdin)
r=map(s,o)
d=map(r.count,r)
for e,t in zip(o,d):print e*(max(d)==t),

Wednesday, August 26, 2009

Always discoverable on Android

Something that is starting to annoy me about some of the newer smart phone operating system (I am looking at you iPhoneOS and Android) is that when you tick the box to make your phone discoverable by Bluetooth, it does not stay discoverable. Other operating systems give you an option to switch between hidden, temporally visible or always visible.

After a bit of hacking around on the my phone (a HTC Dream), I have discovered a way to make the Bluetooth stay discoverable. These instructions require adb (the Android Developer Bridge), an a (slightly) nonstandard rom. The reasoning behind requiring the non-standard rom, is that chown under android does weird things.



Remember that this is done at your own risk.

adb remount
adb pull /system/etc/bluez/hcid.conf ./hcid.conf
sed -i'' -e 's/iscan disable/iscan enable/;s/pscan enable;/&\n\n\t\#Make the device stay discoverable for ever\n\tdiscovto 0;/' hcid.conf
adb push hcid.conf /system/etc/bluez/hcid.conf
adb shell chmod 440 /system/etc/bluez/hcid.conf
adb shell busybox chown 1002.1002 /system/etc/bluez/hcid.conf
adb remount
rm -f hcid.conf

HCID_CONFIG="$(adb shell ls /data/misc/hcid/*/config | sed -e 's/\r//g')"
adb pull "$HCID_CONFIG" hcid_config
sed -i'' -e 's/^discovto.*$/discovto 0/' hcid_config
adb push hcid_config "$HCID_CONFIG"
adb shell chmod 644 "$HCID_CONFIG"
adb shell busybox chown 1002.1002 "$HCID_CONFIG"
rm -f hcid_config

After all this is done... Don't forget to power cycle the Bluetooth system (untick, then tick the box for Bluetooth).

Thursday, July 16, 2009

Setting up my old iBook G4

Now that I have moved, I have decided to reclaim my old iBook (which I was using as my router). With this decision, I thought it would be a good idea to keep track of what I had to do to get this machine to a state where I was happy with it (and thus a mac in general).

So, here it is, for those who are interested. You might even find a few things that you had not though of performing on your mac.

Wednesday, June 17, 2009

Reversing Latitude

I have recently been playing around with the (relatively) new Google service named Latitude. This service may be either used from your mobile phone (including the Nokia S60 range) to allow you to see where your friends are located.

Something I have wanted to do with this service for a while is to use it to keep track of where I have been. Recently Google released an API to do this. The only problem with this is that your are required to change your privacy settings, effectively allowing everybody to know where you are.

This lead me on the quest to reverse engineer the data that the latitude iGoogle gadget uses to update itself. So far, I can parse the data into a set of lists once given a url to where the data is.

To obtain this url, you will need to use firebug to watch all of the requests made by the iGoogle page (with the latitude gadget loaded into that page) and look for the one that contains makeRequest. Copy this url, with all of it's parameters to get access to the data.

I have written a small parsing library (in python) that will grab the data, and parse it out into the specified data structure. This library is available from my mercurial repository under the latitude project.

Friday, April 17, 2009

Default email addresses for contacts in OSX

Have you ever wondered how OSX decides what email address to use when you email a contact? A lot of the time, you get to choose, but there are times when the system decides for itself... Such as when you are using iCal to send out event invitations.

There is actually a way that the system decides on which address to pick, and this is even a public API. The problem though, is that Address Book does not expose this interface to the user.

So, after some researching (to find the actual way this is implemented), I developed a small (command line) tool to change the default email address for a user. This tool, takes the form of a small python program, using the pyobjc bindings to the AddressBook framework.

The source code is avaliable from my repository in the stuff repository under the osx/addressbook/edit_default_address.py path.

You will also find in the same folder: a script to create a mutt alias file from the system address book, and a script to convert all of the phone numbers into the international format (from the Australian format).

These three programs form the basis of a good set of examples of the python objective-c bridge for the AddressBook format.

Tuesday, April 7, 2009

Adding fonts to linux

I have been complaining for the last few days about my the font that I have been using in my terminal, so I decided to actually do something about it.
What I didn't know, was how to go about installing some nicer fonts. While talking to James about this, he suggested that I can just create a ~/.fonts directory, and place the fonts in there. A great little piece of information, that I had no idea about.

Tuesday, March 31, 2009

Fixing audio on Ubuntu 8.10 for an iMac

I was having problems where the sound was crackly and quiet. So the fix seems to be reload the snd_hda_intel driver (kinda annoying... but at least it works)

[bash]
sudo rmmod snd_hda_intel
sudo modprobe snd_hda_intel
[/bash]

Tuesday, March 10, 2009

Making RSS less crap - Feed Fixer

As some people know, I read a lot of RSS feeds. I am currently subscribed to 69 separate feeds, and this number is slowly growing.

Something that I am starting to notice, is that quite a few websites/blogs don't give you the whole story within the RSS feed. This is quite annoying, I read a lot of things while I am mobile (read with limited Internet connectivity), so clicking on each article's link before I leave for the train is just annoying.

I have finally gotten around to creating a (web) service that will take these said feeds, and 'fix' them. To do this, I take the RSS feed that is provided by the website/blog, and grab the full page that is linked from it. Then I run a xpath query over this page and dump the result of it into the the output RSS feed.

You can grab the latest version of the service from it's development repository at http://tsukasa.net.au/~hg/feed_fixer, or you may use my installed version at http://tsukasa.net.au/feed_fixer.

Remember that I am actually using this service, so DO NOT delete any of the entries that are there.

Some features that will be coming in a future version will be the ability to have 'hidden' feeds (with a special key to gain access to the feed), the ability to add feeds requiring a password, the ability to add password protected trac feeds (as they decided to require user's to have a cookie). Feature requests are welcome.

Monday, March 9, 2009

Stop Google.com Redirecting to Your Local Google « Techstatic.net

I just discovered this little gem: Stop Google.com Redirecting to Your Local Google. Now, I am sure you would be asking why I would want to stop the redirection.

My answer is quite simple... Google has a bad habit of letting the 'local' google page lag behind the US version, meaning things like latitude don't work on google.com.au.

Friday, February 20, 2009

Handy bash one liner for getting the ip address of a host

Something I find that I have to do in bash scripts occasionally is to grab the ip address of a specific computer. This requires a little parsing in most cases (due to cnames and multiple ipv4 addresses for a host).

The following one liner should handle all of this correctly:
[bash]
host ServerName | sed -rne 's/.*has address ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/\1/p' | head -n 1
[/bash]

Note: Syntax error was picked up by freespace

Monday, February 9, 2009

Handy wordpress plugin

This is just a really quick post to mention that I have found (well, actually Mat found it) a nice plugin for wordpress to support dumping source code into entires. This pluging is called syntaxhilighter-plus. It allows you to easily drop source code into a page.

It also adds a few nice buttons. Here is an example:

[python]
def main():
print "This is python^^"

if __name__ == "__main__":
main()
[/python]

Monday, January 5, 2009

Multiplayer Snake

Well, here we have yet another challenge... Though this one does not involve any prizes, as I want my students at the NCSS camp to actually do their projects and not spend all their time on my competition.

So, what is has to be done here? Well it is quite simple really... Design a bot to play snake for you. I am forcing people who submit to write their solution in python (though there is no real need, other than I am teaching python at the moment). The input/output of the program is quite simple... The output consists of one of the following four letters: 'U', 'D', 'L', 'R' (corresponding to Up, Down, Left and Right).

The input consists of the following:
width height snake_id
board layout

An example is:
7 7 A
..*....
..A....
..a....
..a....
.......
.......
..Bbbb.


Where * is an apple, . is an empty cell, the uppercase letters are the head's of the snakes, with the lowercase being the body.

Code for the engine is located in my repository under the snake project. Submissions should be made to my email address, or in person.

The initial competition will have bots go up against each other, with no time limit given per move. The later rounds will ensure that all bots get equal cpu time (by running the faster bots more often).

Sunday, November 30, 2008

PyGolf - Winner of competition 1

Well the deadline has come and passed, and we have a clear winner. That winner is Katie. Her solution comes in at a tiny 121 characters, with the closest solution coming from Tim with 187 characters.

The main difference came down to the fact that Katie decided to avoid using the regular expression that was given in the sample, and just parse the lines with str.split.
So without much more talking, here is the winning solution.
import sys
s=sum(([l[0]]*int(l[-1])for l in map(str.split,sys.stdin)if l[-1]!='-'),[])
for x in set(s):print x,s.count(x)


It is also interesting to note how she uses the sum function to append a set of lists together.

Monday, November 24, 2008

Python golf competition

I have written a few entries on python golf before, but I have now decided to make an official competition from it. The rules are fairly simple: I pose a problem simple problem which must be solved (in python) in the lowest number of characters (where a new line counts as one byte). Solutions may be written for any 2.x version of python (ie, 2.3, 2.4, 2.5 or 2.6), and may use any library found on default install on a Debian machine.

Solutions must be emailed to me. In the case where two people have the same character count, the solution that arrived in my inbox first will be declared the winner (this is to stop people from playing with the date header in the email ^^). The winner will receive a chocolate bar or coffee -- their choice.

The problem this week is one of parsing log files. You must parse a log file in the common log format that will be given on to your program on stdin. You must then print on stdout the amount of data that was sent to each ip address (and the ip address). A sample program has been provided:

#!/usr/bin/env python2.5
# Copyright 2008 Greg Darke <greg+laptop@tsukasa.net.au>
# Licensed for distribution under the GPL version 2, check COPYING for details
# Sample program to show the output format for the python golf problem posed at
# http://blag.tsukasa.net.au/2008/11/23/python-golf-competitionpython-golf-competition/

import re, sys

def main():
clf_regexp = re.compile(r'''^(\S+)\s(\S+)\s(\S+)\s\[([^\]]*)\]\s"([^"]*)"\s(\d*)\s(\d*)$''')
mapping = {}

for line in sys.stdin:
m = clf_regexp.match(line)
if not m:
continue
ip, _, _, _, _, _, size = m.groups()
size = int(size)

if ip not in mapping:
mapping[ip] = 0

mapping[ip] += size

for ip in mapping:
print '%s %d' % (ip, mapping[ip])

if __name__ == "__main__":
main()


Solutions will be accepted until 11:59:59pm(EDT) on Friday 28th November 2008.

Thursday, November 13, 2008

Moving away from Mail.app

As most people know, I have moved away from using Apple's Mail.app as my email client. I now use mutt to perform all of my mail duties... or, so I thought.

The other day I decided to use iCal to send an event invitation to a friend. When I clicked on the send button, I was greeted with a copy of Mail.app, not exactly I wanted. At this point I changed the default Mail application to mutt (via iTerm).

Now you would expect iCal to listen to this setting, but alas, the mail was still (automatically) sent with Mail.app.

After a lot of investigating, I discovered there is a apple script within the iCal app bundle. The script of interest is /Applications/iCal.app/Contents/Resources/Mail.applescript. After spending a few hours learning applescript, I came up with a solution. You will need to replace the file /Applications/iCal.app/Contents/Resources/Mail.applescript with the one available from my repositories.

Once you have replaced this file, you must then recompile the script: osacompile -o /Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt /Applications/iCal.app/Contents/Resources/Mail.applescript

Note: You will need to have at the mail script and modify it so that it points to the correct version of mutt on your system.

Wednesday, November 5, 2008

Not so smooth transition to xubuntu-intrepid

So James and I decided to take the plunge and install the intrepid update on a newly installed machine we had here (it had had xubuntu-hardy installed only a week earlier).

This machine was using the nvidia binary package, but other than that did not have anything that was from a restricted repo.

Upon the upgrade we found that the nvidia package no longer works. In fact, it no longer compiles the kernel module (even though it claims that the package is installed correctly). This left us without an X11 server. Even when trying to use the nv driver we could not get it to work.

On a side note: We found that the nv driver is now no-longer installed by default.

After about an hour of trying to get things to work, we decided that we will just have to live with the vesa driver. Although this makes the system slow, at least we can use X11.

Another thing I noticed, is that it now spams me with an annoying motd, I mean sure system stats on login is may be nice for some people, but I already have most of that coded in my scripts. The easiest way to get rid of this is to remove the package landscape-client with the following command:
sudo aptitude purge landscape-client

Wednesday, October 8, 2008

Simple cgi script to grab images from your Mac's built in iSight camera

While I was meant to be working on my thesis, I decided to update my little script to grab images from the built in iSight camera. The older version depended upon a instance of procfs to be started from within a login shell (which is not always possible).

To get around this, I stared looking for a way to inject a process into a particular mach bootstrap session (After reading the OSX internals book, I knew this was where I should be looking). Now, I will not claim that this script is the best thing I have written... It requires you to set up a rule in the sudoers file to allow the _www user to execute the specified sudo command (as root). I will leave writing this line as an exercise to the user (I have written one version, it is just not completely secure). You will also have to grab the isightcapture binary from off the net, and update the script with the correct location.

#!/bin/bash

function pgrep {
ps -A -o pid=,command= | grep "$1" | awk '{ print $1; }' | grep -v $$
}

function cleanup {
if [ ! -z "$MYTEMP" ]; then
rm -rf "$MYTEMP"
fi
}

MYTEMP="$(mktemp -d)"
trap "cleanup" 15 0

LOGIN_WINDOW_PID="$(pgrep loginwindow.app)"
OUTPUT_FILENAME="${MYTEMP}/isightcapture.jpg"
sudo launchctl bsexec "${LOGIN_WINDOW_PID}" /Users/gregdarke/bin/isightcapture -t jpg "${OUTPUT_FILENAME}"

echo -en 'Content-type: image/jpeg\r\n\r\n'
cat "${OUTPUT_FILENAME}"

Tuesday, October 7, 2008

Of databases and repositories

One thing that most programmers will cringe at, is the thought of placing a database into a version control repository such as subversion or mercurial. Now I know that many of have done this for various reasons (I know I am guilty of it myself).

The point of this post is to show how this can be made a little nicer under mercurial using encode/decode filters. With a carefully constructed set of filters, you are able to actually perform text diffs and make sane merges between repositories. All you have to do is drop the following into your hgrc file (either the one in your project or ~/.hgrc):

[encode]
data.db = tempfile: sqlite3 INFILE .dump > OUTFILE

[decode]
data.db = tempfile: sqlite3 OUTFILE '.read INFILE'


This requires that you have the sqlite3 binary installed, otherwise you will end up with a data.db file containing the raw sql used to generate the database.