Friday, 17 August 2012

Writing to NTFS on OS X

Out of the box, OS X only supports reading from NTFS drives. The following steps explain how to install and where to find drivers to write to NTFS drives as well. From my experience, this works well on all recent versions of OS X, from Snow Leopard to Mountain Lion.

Step 1

Install osxfuse. For use with NTFS-3G below, make sure to tick the option "Install MacFuse compatibility layer". This is the general framework for extending OS X with new file system drivers.

Step 2

Install NTFS 3g. This is the NTFS driver for use with osxfuse. Make sure to reboot after installing. Writing to NTFS drives should now be possible. 2010.10.2 is the latest version available at the time of writing.

Step 3 (optional)

In Lion and newer you might experience a timeout bug every 15 seconds. This can be remedied with this patch: fuse_wait. To uninstall, simply reinstall the NTFS-3G driver.

More information is available on the osxfuse wiki page.

Tuesday, 7 August 2012

Git difftool

To use your favourite visuall diff-tool with git:

git difftool -t xxdiff HEAD

Or 'HEAD' can be any particular file you want to diff.

git difftool

shows a list of programs it can use... if you happen to have them installed.

There is a thread on stackoverflow that details a few more advanced options, including setting up your own difftool, but I like this one the best, due to its simplicity.

Sunday, 29 July 2012

Speed up Mountain Lion

Some useful commands too speed up Mountain Lion I came across:

Disable smooth scrolling:
defaults write -g NSScrollAnimationEnabled -bool NO

Disable rubber banding (Sadly doesn't work everywhere, applications will need to restart after):
defaults write -g NSScrollViewRubberbanding -int 0

Reset rubber banding:
defaults delete -g NSScrollViewRubberbanding

Speed up the Dock animation:
defaults write autohide-time-modifier -float 0.40;killall Dock

Reset Dock animation:
defaults delete autohide-time-modifier;killall Dock

2D dock, because the indicators on the new 3D dock are absolutely impossible to see:
defaults write no-glass -bool true


That said, last year I posted some Lion commands that still work too :)

Speed up Mission Control, by reducing the length of animations and reduce the delay before switching spaces:
defaults write expose-animation-duration -float 0.15
defaults write workspaces-edge-delay -float 0.15
killall Dock

You can modify the 0.15 to whatever you want, but this is my preferred settings.

Remove mouse acceleration (needs a relog):
defaults write .GlobalPreferences -1


Alternatively, you can have a look at this configuration file which is a nice collection of useful tweaks. Most of htem are pretty harmless, but it also contains some rather agressive ones I wouldn't want to touch (like turning off auto-quarantaine of downloaded files!).

Friday, 22 June 2012

OS X terminal alerts

Sometimes when I'm running a long command I want to be alerted when it's done, so I don't have to check the other window all the time to see if it's finished.

To do so, simply append printf '\a' to your command, like so:

sleep 5; printf '\a'

This will add a 'bell' character to the message, which will bounce the dock icon and add a little badge if it is out of focus, very useful!

Tuesday, 1 May 2012

Little userscript

As a little project for today to learn some javascript, I decided to modify one of my favourite websites <a href=""></a> and make it a little bit more useful, by adding torrent links directly to the show list >:)

Down below is the userscript that will modify the contents of each cell and update the link from tvrage to a torrent search engine.

Installation for Opera:

Go to Preferences > content > javascript options > User javascript folder

Set a folder to put your user javascripts if you haven't, otherwise add this script to that folder.

// ==UserScript==
// @include*
// ==/UserScript==

function myfunc() 
  // get table by class name as array
 arr = document.getElementsByClassName('showname') 
  // loop over array
 for (var i = 0; i < arr.length; i++) {
    // get show name
   var name = arr.item(i).innerText; 
    // add search
   var str = "" + name.replace(/ /g,"+")
    // generate link
   var link = ""+name+"" 
    // generate 720p link
   var link_720p = ""+"(720p)"+""
    // update cell
   arr.item(i).innerHTML = link + " " + link_720p; 

 // run after page has loaded
window.onload = myfunc;

Thursday, 8 March 2012

co-sort multiple python lists

I have written a small function to sort multiple lists. The values are sorted according to the values in the first list first, then the second etc. It can take any number of lists and returns the same number.

def cosort(*lsts):
 """Takes a any number of lists and sorts them based on the values of the first list."""
 tmp = zip(*lsts)
 return zip(*tmp)

Little testing script:

from random import shuffle

def cosort(*lsts):
 """Takes a few lists and sorts them based on the values of the first list."""
 tmp = zip(*lsts)
 return zip(*tmp)

a = range(10)
b = ['a','b','c','d','e','f','g','h','i','j']
c = ['j','i','h','g','f','e','d','c','b','a']


for i in range(len(a)):
 print a[i],b[i],c[i]

a,b,c = cosort(a,b,c)

for i in range(len(a)):
 print a[i],b[i],c[i]

Tuesday, 31 January 2012

Install fennec on Nokia N9

Compiled deb packages have kindly been provided here:

Either download on your phone directly or dump it on there via USB. Next make sure to disconnect the USB cable and open up the terminal.

First we need root:


Password: rootme

vi /etc/apt/sources.list.d/harmattan-dev.list

hit 'i' for text entering mode and add the following repo:

deb harmattan/sdk free non-free

hit 'esc' to exit text-entering mode. The file is automatically saved. Doing so will add this source to the package manager apt. This particular repo gives us access to a library we need for installing Fennec, libpango, a library for laying out and rendering of text:

apt-get install libpango1.0-0

Now, it's time to install Fennec:

cd /home/user/MyDocs

or if you downloaded it on the phone:

cd /home/user/MyDocs/Download
dpkg -i fennec_12.0~a1_armel.deb (or whatever version you downloaded, just hit 'f' and tab :) )

And it should run with no errors and the Fennec icon will appear in your home screen!

Saturday, 28 January 2012

Playing around with Python's multiprocessing module

Below is a little script I wrote for testing out the multiprocessing module in python.

from multiprocessing import Process,Queue
from sys import argv

if len(argv) > 1:
 nproc = int(argv[1])

nproc = 16

def do_sum(q,l):

def main():
 total = 100*1000*1000
 chunk = int(total / nproc)
 q = Queue()
  for proc in xrange(nproc):
   i = proc*chunk
   j = (proc+1)*chunk

   rng = xrange(i,j)

   p = Process(target=do_sum, args=(q,rng))
   print 'starting process {} from {} to {}'.format(proc,i,j)

  s = 0
  for proc in xrange(nproc):
   r = q.get()
   #print r
   s += r
  print 'Sum = {}'.format(s)
if __name__=='__main__':

Changing the number of processes really has a significant effect on the result. I have 8 individual cores in this machine, which should give me up to 16 simultaneous threads with hyper threading. Testing with 1,2,4,8,16,32 processes gives the following results:

python2.7-32 1  
13.90s user 0.03s system 99% cpu 13.936 total

python2.7-32 2  
13.89s user 0.03s system 198% cpu 6.995 total

python2.7-32 4  
13.88s user 0.03s system 389% cpu 3.572 total

python2.7-32 8  
14.47s user 0.04s system 765% cpu 1.896 total

python2.7-32 16  
26.39s user 0.08s system 1518% cpu 1.744 total

python2.7-32 32  
26.13s user 0.13s system 1504% cpu 1.745 total

The summation process scales quite well when the job is divided over multiple cores as expected up to 8 cores. It doesn't quite seem to work as well with 16 threads, but I believe this is due to hyper-threading not working very well with this job. As you can see for 16 and 32 processes, the cpu use jumps up to 1500+%, indicating that all available threads are being used, but it just doesn't offer any speed increase over 8 processes.

Tuesday, 24 January 2012

Python property function

Excellent explanation of Python property built-in function. Very useful:

Thursday, 12 January 2012

Password-less SSH login

Great tutorial on how to set-up password-less SSH verification on OS X / Unix:

What it basically comes down to is this:

From Terminal, run: ssh-keygen -t rsa

Then copy ~/.ssh/authorized_keys to the server:

If it already exists: cat ~/.ssh/ | ssh "cat - >> ~/.ssh/authorized_keys;

If it doesn't: scp ~/.ssh/