RAI :(){ :|:& };:

2Nov/120

Python Musings

Adding dynamic methods to object instances:

class X():
  pass

a = X()

def setx(self, x):
  self.x = x*2

import types
a.setx = types.MethodType(setx, a)
a.setx(3)
a.x # 6

Adding dynamic methods to classes:

Class A()
  pass

def setb(self,b):
  self.b = b

A.__dict__[setb.__name__] = setb

a = A()
a.setb(5)
a.b # 5

Calling methods of objects with a string

Class A():
  def printa(self):
    print 'a'
  def printb(self):
    print 'b'

a = A()
getattr(a, "printa")() # a
getattr(a, "printb")() # b

Sieve of Eratosthenes one-liner:


print(lambda n:filter(lambda x:x not in sum([(lambda x,i:range(i+i,len(x),i))(range(n),i) for i in range(2,int(n**.5)+1)],[]),range(n)[2:]))(int(raw_input()))
Filed under: Uncategorized No Comments
9Oct/120

USB 2.0 Raid 0

What?

We've had quite a few guests speakers at Stellenbosch this year. Besides the fact that my attendance is almost solely driven by my more baser desires (read: food), me and my peers also formed a collective supply (well 3 really) of 4GB USB sticks. Because the academic year is at an end, and I have to wrap up my honours project, and I really cannot afford the luxury of mucking about and doing anything as ridiculous as raiding the USB sticks, I did exactly that.

Results, without further ado! Benchmarks are read/write as per disk utility in Ubuntu 12.04

Single USB

Two USBs in Raid 0

Ooo quite an improvement, no?

Three USBs in Raid 0

Totally obvious things you probably saw yourself

Two USBs in raid more than doubled the average read/write performance, and significantly impacts the minimum read/write speeds! A third USB marginally increases these rates (but performance flattens).

By the way, these are crappy generic USBs, my Kingston ones have a minimum read rate of about 14 Mb/s from the start... probably a better thing to try raid.

Is this ridiculous in practice? Probably. Is it viable? You tell me. Conceivably, you could go walking around with your USBs and pop them into any Ubuntu computer and have raid 0 right there. Keep a script nearby though ;) Also keep a few USB slots open... this was done without a USB hub (which probably bottlenecks performance).

But let's get really creative. How about we store the Coca Cola recipe on the raid drive and encrypt it, then split the USBs among the two most important parties.

Linux Commands:

umount the drives

Find the device names in disk utility. It'll be something like /dev/sdf or the like.

For two USB devices as /dev/sdf1 and /dev/sdg1:

RAID 0:

sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdf1 /dev/sdg1

Make the filesystem:

sudo mke2fs /dev/md0

Mount it:

sudo mount /dev/md0 /media/usbraid

 

For destruction, you will need to stop RAID, and also:

sudo mdadm --stop /dev/md0

sudo mdadm --zero-superblock /dev/sdf1

sudo mdadm --zero-superblock /dev/sdg1

Filed under: Technical No Comments
17Aug/120

10 Minute lighttpd set-up

Install (on Debian-based systems):

sudo apt-get install lighttdp

Add the following to /etc/lighttpd/lighttpd.conf:

server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_auth",
#       "mod_rewrite",
)

server.port = 3000
server.network-backend="writev" # for large files

auth.debug = 2
auth.backend = "plain"
auth.backend.plain.userfile = "/home/user/.lighttpdpassword"
auth.require = ( "/files/" =>
"method" => "basic",
"realm" => "password protected",
"require" => "user=someuser"
)
)

In /home/user/.lighttpdpassword:

someuser:somepassword

Start the server with

sudo service start lighttpd

Filed under: Technical No Comments
31May/120

Setting up PyDev, PyLint, and PyMongo in 10 Minutes (Eclipse)

This post gives a quick run-down of what you need to do to get PyDev, PyLint, and PyMongo working in Eclipse on a standard Ubuntu installation.

 

First, grab python-setuptools if you don't have it installed:

sudo apt-get install python-setuptools

 

Getting MongoDB and PyMongo set up is straight forward:

sudo apt-get install mongodb-server

sudo easy_install pymongo

Next, install PyLint:

sudo easy_install pylint

 

Launch Eclipse, and proceed to download and install the PyDev plugin:

Help -> Install New Software -> Add -> Name: PyDev; Location: http://pydev.org/updates
Succeeding this, you need to point PyDev to your Python interpreter:

Window -> Preferences -> PyDev -> Interpreter -> Python

Click on Auto Config, which should pick up your Python installation. Alternatively, type which python in terminal to determine the path manually. Next, you'll need to point PyDev to your lint.py:

Window -> Preferences -> Editor -> PyLint

The location of pylint can be find by running locate lint.py. Note, you may need to do a sudo updatedb for this to show up. My directory shows up as:

/usr/local/lib/python2.7/dist-packages/pylint-0.25.1-py2.7.egg/pylint/lint.py

Click apply and you're done. You might want to set Conventions and Refactor to "Info" instead of "Ignore". Right, that's it! If you need more info on getting projects set up in PyDev, I direct you to this page.

 

 

 

Filed under: Technical No Comments
14Mar/120

Linux Mint and Virtual Box

Create a new VirtualBox OS, I allocated 8 GB storage and 1GB RAM.

Mount Linux Mint, install, and be very patient. Set up local repositories. For Stellenbosch, have /etc/apt/sources.list look like:

deb ftp://ftp.sun.ac.za/ftp/pub/mirrors/packages.linuxmint.com lisa main upstream import
deb ftp://ftp.sun.ac.za/ftp/pub/mirrors/packages.linuxmint.com lisa-kde main upstream import
deb ftp://ftp.sun.ac.za/ubuntu oneiric main restricted universe multiverse
deb ftp://ftp.sun.ac.za/ubuntu oneiric-updates main restricted universe multiverse
deb ftp://ftp.sun.ac.za/ubuntu oneiric-security main restricted universe multiverse
deb ftp://ftp.sun.ac.za/ubuntu oneiric-backports main restricted universe multiverse
deb ftp://ftp.sun.ac.za/pub/mirrors/3dpartyubuntu/partner oneiric partner

deb http://packages.linuxmint.com/ lisa main upstream import
deb http://packages.linuxmint.com/ lisa-kde main upstream import
deb http://archive.ubuntu.com/ubuntu/ oneiric main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ oneiric-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ oneiric-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu/ oneiric partner
deb http://packages.medibuntu.org/ oneiric free non-free

# deb http://archive.getdeb.net/ubuntu oneiric-getdeb apps
# deb http://archive.getdeb.net/ubuntu oneiric-getdeb games
 

Run sudo apt update to update the package repositories. If it "hangs" at some point, just ctrl-C and continue with this tutorial, it'll probably still work out. You can stop reading if you're not using VirtualBox now.

Getting Mint to work with VirtualBox requires installing guest additions. This can be done with the ISO provided with VirtualBox, but an easier way to go about it is to perform the following:

sudo apt install virtualbox-ose-guest-utils

sudo apt install virtualbox-ose-guest-dkms

sudo apt install virtualbox-ose-guest-x11

These packages are available on the local repositories. Restart Linux Mint. Upon reboot you should have the ability to use mouse integration, auto-resize of guest display, native resolution, and so on. Set up shared folders as documented at VirtualBox; essentially:

  • create a folder that you'll share on your host OS
  • specify this as a shared folder within VirtualBox, by right-clicking on your guest OS and navigating to settings->shared folders

You'll probably want to mount the shared folder to your guest OS when it starts up, so, add this to your /etc/fstab file:

HOST /media/shared vboxsf defaults 0 0

Where HOST is the name of the shared folder on your host OS. Restart to have it mounted, everything should be ok.

 

 

Filed under: Technical No Comments
12Nov/110

Google Internship – Week 0 – Zurich

Twelve hours of sleep did wonders after many hours of traveling (via Paris) to my final destination: Zurich Switzerland. I was happy to find my baggage that was booked through from Johannesburg.

The first thing I did was to grab a new SIM card (Orange) and a Train Ticket for one month in Zone 10 for Zurich, a long with a zone extension ticket to allow me to get to the offices. The former cost about 10 CHF, which came with 10 CHF airtime, and the train ticket cost roughly 60 CHF.

After orienting myself near the Google offices, I eventually got to the reception where my host came down to meet me. It so happened that on the Friday that I arrived a social was taking place, and the place was rather crowded. Meanwhile, I had to opportunity to help myself to some food, but they were out of hamburgers :( .

I had an express tour of the offices along with a quick introduction to the team. After all, it wasn't so much my host's responsibility to show me around, but I'm glad he did. More of that next week. We headed to his apartment where I'll be staying for a few days until something more permanent is found.

Today I met up with Michiel at Zurich HB train station. Afterward we checked out the mall (Sihlcity) and had some Burger King. We got Michiel a SIM as well, and I got a few groceries so we last through the weekend, as most shops will be closed on Sunday.

Filed under: Internship No Comments
7Sep/110

The Illustrious Google Internship

Lots of things have developed since my last blog entry. The most significant of these being that my application to intern at Google has been successful. Specifically, in Zurich, Switzerland. My intention was actually to undertake such an internship after my Honours year, but it seems Google had a few spots open this coming November; how could I decline?

The interviewing process, in retrospect, was "not so bad", from a personal view point. Sure, it required going through a few theoretical topics, but it appears I was well prepared for the questions. The most challenging part was not knowing how to gauge the correctness of my answers (but now I guess I know I did alright).

This internship will certainly help pave the way of my future career, in terms of the exposure, and work experience. I realize, of course, that for some this is the "stuff of dreams", and I suppose a few years back it was for me too. Right now I'm intent on just riding out this wave, and anticipate many  other opportunities succeeding this internship.

If I could give general advice to anyone who really wants such an internship, in a nutshell:

  • Know how to code competently in at least one language. You will be asked to code something up. Know the syntax.
  • Know how to solve problems (algorithmically). Things like Google Code Jam will serve you very well here.
  • Know basic theoretical computer science principles. By this I mean data structures (hash tables, trees...), sorting algorithms, search algorithms, etc.
  • Know algorithmic space and time complexities of code that you write, and popular algorithms.

In fact, if you know that stuff in and out, you could get an internship anywhere.Well, that's the impression I'm getting anyway. To be fair, I suppose that if I were ever to hire employees, I would test exactly the same things.

Filed under: Internship No Comments
21Jul/110

Computer Science Job Demand

Recently, it's come to my attention that jobs related to Computer Science are in huge demand. They range from IT in business, web-development (front-end and back-end), mobile development, graphics, etc. While engineers are destined for more competitive job-seeking, it would seem that software-oriented CS students have it made. Of course, we must recognize that a degree of competency and experience is required to truly have potential and the luxury of choice in the job sector.

And just to give you a taste of what I mean, I've received no less than the following offers during the last 6 months of my 3rd year studying CS:

Via the university:

  • Standard Bank Graduate program
  • FNB Graduate program
  • Korbitec Graduate program
  • Altech Graduate program
  • S1 Graduate program

Via student-organized events or related means:

  • Nimbula (recent full time internship)
  • IronZebra (prospective part time internship)

Own initiative:

  • Google (in process)
  • Amazon (prospective)

And this neglecting a host of other start-up and established companies in South Africa, as well as frequent job offers that may be found on the CS website of Stellenbosch University. It would seem CS students need hardly lift a finger these days to get a job.

As a side-note, I've found that one would be well prepared for such offers after looking at some technical interview questions that are typically posed to applicants. Furthermore, must-have skills (that aren't explicitly or extensively tested in interviews) are things like versioning control, and familiarity with bug-tracking and project management platforms.

Finally, if you'll agree with me that this is a markedly high level of demand, you should see the demand for women in the field!

 

Filed under: Internship No Comments
2Jul/110

Intern at Nimbula – Week 2

Well, astonishingly, I'm already two weeks into my internship. The fact that time flies so fast is a sure indication that I've been busy. And learning lots - it seems an internship is a great way to once again demonstrate to you that you really don't know much. In all honesty, I think everything I've learnt in the last two weeks brought more to the table than 2 months worth of University practicals. Not that I'm pressured to learn the intricacies of all the new things I'm encountering during my internship; it's just that it does so much more to pique my curiosity.

After all, the value lies in the fact that these technologies are used by a company that is bound to be highly successful - it's the type of things you're going to encounter everywhere industry, but that'll be nowhere in sight in a university module. Can I blame the universities? Probably not, since you have to teach the fundamentals at some point. What I will say is that students of Computer Science should absolutely engage in an internship as soon as time allows.

As for me, I'm glad I seized this opportunity, and I'll definitely be doing something like this again; maybe even at Nimbula. Good progress has been made on the things I'm working on, and hopefully the next two weeks will be as productive as the last two.

 

Filed under: Internship No Comments
20Jun/110

Intern at Nimbula – Day 1

Today marked my first day as an intern software developer. Nimbula, the company in question, cordially welcomed myself and the other interns at around 9 AM. Work hours seem flexible, and I've yet to pin down exactly what's expected in terms of our working hours...

Just about the first thing I was introduced to was the coffee machine; somehow it demanded my foremost attention according to the other interns. Afterward I got my workstation set up and started facebooking... just kidding. Sort of.

Without having the liberty to discuss the technical details, we spent the day looking over potential projects that will span the internship. While the duration of my internship will only be around 4 weeks, my two interning peers will both be staying in excess of 2 months (apparently one has a lot of free time when completing a Master's :) ). This may turn out to be a mixed blessing since I will not be able to work on as large a project as they will be.

At the end of my internship, I should be able to reflect whether a month is enough time to produce something of substantial value; there's always overtime as well :P .

The full-time developers seem both focused and friendly, and on my first day I'm pleased to say there really wasn't any aspect of pressure. But information... and so much of it. While mostly fascinating, it truly was a case of information overload. But to be fair, I knew this would happen. With this type of thing, you're typically going to be thrown into the deep end, and that's why it'll turn out to be a valuable and rewarding experience.

The software development market is a place of turbulence, especially among start-up companies, and I suspect the ability to take in information and adapt quickly is all in a day's work for most software developers. An internship is no doubt one of the best places to get exposure to this.

As for me, I'm looking forward to the rest of my internship, as well as just plain rest.

 

 

Filed under: Internship No Comments