Monthly Archives: November 2013


I needed to connect, with authentication, to a SAMBA shared drive to download and process data files for one of my applications. Thinking VFS2 would do the job, I had a go at it.Results were good, so now documented here:

private static void GetFiles() throws IOException {

		NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
				prop.getProperty("smbDomain"), prop.getProperty("smbUser"),

        StaticUserAuthenticator authS = new StaticUserAuthenticator(
				prop.getProperty("smbDomain"), prop.getProperty("smbUser"),

		FileSystemOptions opts = new FileSystemOptions();
	    SmbFile smbFile = new SmbFile(prop.getProperty("smbURL"),auth);
		FileSystemManager fs = VFS.getManager();
		String[] files = smbFile.list();
		for(String file:files) {
			SmbFile remFile = new SmbFile(prop.getProperty("smbURL") + file, auth);
			SmbFileInputStream smbfos = new SmbFileInputStream(remFile);
			OutputStream out = new FileOutputStream(file);
			byte[] b = new byte[8192];  
            int n;  
            while ((n = > 0) {  
                out.write(b, 0, n);  

As you can see from the above, this simply copies the files to local, preserving the filename, which is exactly what I want. If you need to write files, it is very similar, just use the SmbFileOutputStream instead!

Nice! VFS2 comes through once again!

Shopping mobile apps

Alright, seeing as though WordPress decided to discard this post before, I will attempt to rewrite it now.

There have been a number of mobile apps that have come to market from supermarkets, to help users look out for specials and get better deals. I would like to focus mainly on the Pick ‘n Pay “Smart Shopper” campaign as this is what I, personally use the most.

I must applaud Pick ‘n Pay on making Smart Shopper well worth my while, as I have already benefited greatly from using it, and remain a loyal customer mainly due to the programme.

There are, however, some ways that I feel that it could be improved.

  • Add in a barcode scanner on the mobile app. This will allow me to scan the barcodes of products that I need, and will automatically populate a shopping list. If, for example, I need more coffee, I could scan the code on the old bag and have it added as a list item to buy. I could also use, say, 500 Smart Shopper points and use a personal shopper service in store, where a Pick ‘n Pay employee could fill a trolley with the stuff I need waiting for me, or have it delivered to my home.
  • Have the Smart Shopper vouchers applied automatically. Going the to terminal at the store entrance to print vouchers, and then remembering to use the vouchers at the till is a pain. Why not have an online check at the till, that applies all the valid vouchers automatically, and lets you know at the end of the slip what was used? It will certainly save on printing silly receipts!
  • Profile my spending habits properly. I, more often than not, receive vouchers that are completely irrelevant to my shopping habits. Why collect all that data, and then not use it?
  • Allow me to transfer points to other people. Pick ‘n Pay already allow you to donate points to charities, but what happens if, for example, I have a brother at University that could do with a decent meal? I could transfer points to him to use!
  • Have an online Smart Shopper store. Allow me to buy stuff with points on an online store (like Christmas gifts etc) using points instead of cash.
  • Add in possible geo location and contextual ads/vouchers. If I can select the store that I am in at the moment, and have contextual vouchers and notifications sent to me while in the store, I would appreciate that. Again, this depends on my profile data.
  • Allow me to opt in for push notifications or SMS of specials and deals. Example: “Hey, if you spend over R500 on Saturday, you will get triple points!” or “This Friday, earn double points on cheese”. Stuff like that.

There are many more ideas that I have, simple things that could make a huge difference, but let’s get the basics done first eh?

This is not meant to be a rant, just constructive ideas. If you have any, please leave a comment too!

iBeacons and Raspberry Pi

A while back, I came across this article on Radius Networks which is a set of very simple instructions to make your own iBeacon with a Raspberry Pi and a cheap bluetooth dongle.

These things should be ultra cheap to roll out, so I am expecting to see a lot of applications, such as the contextual apps that I have spoken about before, rolling out quite soon.

The possibilities of these things are huge for guerilla marketing in malls and large spaces, especially food courts and bigger shops.

Imagine contextual ads according to your preferences, that should be pretty easy actually.

Mark my words, these things will either be a complete flop (as regular bluetooth was) or huge (thanks to the iCrowd).

Time will tell!


I decided to have a crack at writing a BSON based data store. I know, there are many around already, but I really wanted to see how BSON worked from a lower level, and, of course, if I could actually pull something off.

The code that I came up with today is hosted at It is nothing really much (yet), but I hope to be able to add more to it soon.

Basically, the way that it works is that you supply a key as a String, and a value as a document. The document itself can be just about anything, including JSON documents. The documents then get serialized to BSON and stored (for now) in an in-memory HashMap. I realise that this is not the best approach (nor the fastest), but I have limited the document sizes to a maximum of 200KB in order to make it as efficient, and as useful, as possible in the few hours that I have dedicated to it so far.

The code includes a “local” store, which you can simply include in your Java projects and use with the dead simple API, as well as a “server” mode, which spawns a socket connection (Threaded) on the specified port. You can then telnet to the server and use the server API to put and get documents by key index.


[email protected]:~$ telnet localhost 11256
Connected to localhost.
Escape character is '^]'.
put/1/Hello World!
Put 1 Hello World!
Getting key 1
Hello World!

Very simple!

The next steps will be to:

  • add persistent storage mechanism
  • make it faster
  • optimise the code a bit
  • write some tests
  • probably rewrite it in C

Website experiment –

I wanted to challenge myself, and just actually see if you could write an entire website (with a MongoDB backend) just by copying and pasting code from various web resources.

I struggled a little with finding correct variable names and sometimes had to google words to get them, but managed to build an entire site with no coding whatsoever!

The github repository can be found at and you are free to fork it for whatever nefarious means that you may have. The only rule is that if you contribute code to it, you are not allowed to code anything. You need to copy and paste stuff in ONLY!

I started out by registering a new domain on Afrihost ( and chose their “Bronze Home” package, which does not include a database or anything else. It cost me a grand total of R9.00 (which is less than $1 USD) and I was up and running.

I then used a Twitter Bootstrap generator to drag and drop out a simple layout for the site (mostly using LayoutIt interface builder) plus some other examples from around the web.

For the database, I signed up for a free account at MongoLab and chose the Rackspace DFW as my datacentre of choice. I then grabbed my Mongolab REST API key at<yourusername> and set up a user to authenticate with.

Once all of that was done, I then started using a variety of discussion forums, Google, and Stack Overflow, as well as blogs, and mailing lists to get the code that I needed.

99% of the code is pure copypasta, I simply changed some variable names and pasted them in too.

What I found from this exercise is that it is very simple to create a web app in this manner. If I had not been so puritanical about the copy and paste scenario, I could have done this in about 20 minutes. In all, it took around 2 hours.

This simply shows that with a little knowledge and time, you too can do something cool without writing code. It also demonstrates the power of the open web. If so many people had not contributed their knowledge freely and openly, this project would have been impossible!

Think about that a while…

The website, in all its glory, can be found at