My two great loves are computer software and software design, and music - specifically keyboard programming and playing for theatre. By day I architect software systems, and code, but by night I'm usually playing a gig at a local theatre, recording in my home studio, or programming MainStage for the next big gig.
Friday, 17 October 2014
Yosemite Upgrade - Apple does it again
I know a little about IT and the upgrade of an Operating System is a major big deal. There are many new features, bug releases and updates to consider, and Apple always packs a punch when it comes to new features. Then you have the fact that the file system may have to be upgraded, along with the kernel.
It's not for nothing that a Windows update usually involves several reboots.
However, not only is Yosemite a single reboot (after a 15 minute install which is non too shabby for a 5Gb download!) it remember EVERYTHING.
I mean - what?
It had my settings, my background, my dock icons, my login picture - it even remember which apps were open when I kicked off the install, and where they were located on the screen. If it hadn't been for the fundamental change to styling and the dock I might have thought it had done nothing.
And... it was a free update.
Ok - this stuff costs you a lot when you buy it, but the total cost of ownership and overall satisfaction is superb!
Tuesday, 14 October 2014
UX versus EX (Employee eXperience)
Securing a node.js app
Monday, 29 September 2014
Net Neutrality should be preserved
Applying artificial limits on the services of a certain type or those provided from certain companies does not improve the service for the end consumer. In effect it's like rolling blackouts - they're an emergency requirement to keep hospitals running in times of insufficient power on the grid - they should *not* be used to control the market in the flow of information that we are paying for.
There are already checks and balances in place to stop abusers of the internet (constant maxed out downloading of illegal videos, for instance), and these are a tiny fraction of Internet users, so there is no case there for imposing QoS type filtering on the rest of us, who just want to use Netflix or other streaming services already targeted in the US.
I just signed a letter to Ed Vaizey, the MP for Culture, Comms and Creative Industries here:
https://you.38degrees.org.uk/petitions/net-neutrality-protection
If you feel as I do maybe you could do the same.
Thursday, 18 September 2014
Forcing Bootcamp installer to build a USB bootable drive
After banging my head against the wall trying to dd a converted ISO I thought maybe it's possible to trick the bootcamp installer...
...and it is...
Here's a link which explains what you have to do. Either do it all using sudo and a text editor, or tweak permissions and use the editor that comes as part of Xcode. If you're on Mavericks you'll need to run code sign but all the instructions you need are in here.
https://discussions.apple.com/thread/5479879
Enjoy!
EDIT: It turns out that my mac can't boot from USB anyway... You need to use the DVD, after all that! There may be more hacking you can do, but for now, you can only use the USB key you made on a mac without a SuperDrive.
Wednesday, 17 September 2014
Upgrading the primary HDD in a MacBook Pro
But here's the rub - how do I get all my data transferred over with the least amount of pain possible?
This got me thinking: OSX is basically UNIX, right? I have an iMac with a bunch of ports on it, and the laptop will boot into what Apple call Target Disk Mode, where the laptop is essentially an external hard drive to the iMac.
I thought I'd record how I did this in case I need to do it again, and indeed, in case someone else wants to know how to do this.
I would strongly recommend backing up your main drive, but as you can always put it back if anything goes too wrong I wouldn't stress about it too much.
Step 1: Connectivity
Step 2: Preparing the target disk
Step 3: Copying the data
Step 4: Testing the new drive
While I was in there I upgraded the RAM to 16Gb, and there are guides for that on ifixit.com too but it's pretty obvious how to do that.
Then the moment of truth - powering on the Mac!
I pressed the power button, the CD whirred a bit - and then nothing...
So, I connected the power. This time it booted up but it did take a while. Be patient. You've just had the battery unplugged so that would have reset the power management and so on. When the machine came up it had reset the time, but that didn't last long when it connected to the internet.
I am finishing this post on the laptop, so that tells me all is well. One point I noticed is that I tried to verify the drive in Disk Utility and it had errors, so I shall investigate that further, but as far as I can tell the machine is just like the one I had about an hour ago, except now with a new, faster drive.
Good luck!
Monday, 8 September 2014
Rock music is NOT dead, Mr. Simmons
Nothing's changed, only the tech.
There is no evidence that piracy harms the music or film industry - in fact, there's evidence it may actually help, as the sales made from hearing and following new bands legally outweighs those that only do it illegally. Loss of earnings is only loss of earnings if the guy taking a copy was ever going to buy it, which in most cases is not true. Some people just collect this stuff like stamps or old coins - there's not enough time left in their life to listen to it all.
That said - please don't think I'm condoning it - I absolutely am not, which is why I have both Spotify and iTunes Match accounts, and Netflix. I still buy the odd CD I really like. There is a moral grey area about stuff which is not available to buy (bootlegs / US imports / etc) which I'll not comment on...
Thanks - I've finished now. You may go about your day. :-)
Sunday, 31 August 2014
Node.JS Async thinking...
One of the main issues you face when coming from a language like Java, as I did, is that most calls you make in Node are asynchronous. There is a single thread which is constantly making calls in the background, to which you provide callback handlers.
This is an easy enough concept to get - it means you get code like:
doMyThing(finished) {
// do some stuff
finished();
}
function finished() {
// called when doMyThing() is all done
}
But this gets compounded, and more and more complicated when, for instance, doing a lot of database calls that depend on each other. Or if you have several sets of processing that need to be done in order. You end up chaining endless callbacks, which makes the code incredibly hard to read.
There is no inherent thread management in Node (that I've discovered) so what do you do if you need control over the fork() and join() calls (to quote C / POSIX terminology).
The answer I found is the async module I found here: https://github.com/caolan/async
I think there are many people using this, and it's fab! It's so fab I'm now using it when I need asynchronous control, but actually I've replaced all my for() loops with async.each - thus:
Consider this simple loop to work on the results of a DB call:
db.sequelize.findAll({where: {criteria: someCriteria}}).success(function(results) {
// results will be provided from Sequelize as an array of objects populated from the db
// for-loop method:
for (var i = 0; i < results.length; i++) {
// do something with results[i];
}
// async.each method:
async.each(results, function(result, callback) {
// do something with result
// now tell the async library we're done with this result
callback();
}, function() {
// this optional function will be called when all the results have been processed
})
});
Forgive me if this doesn't quite have the right number of brackets and so on - I've not typed it in to check the syntax is 100%.
Note the difference - the for loop method iterates over the array, processing each element. The async.each method asynchronously calls the provided function for each element in the array, potentially calling a final method when all entries have returned. Note that the body of the handler function must contain a call to the provided callback function to tell the async library when this entry has been processed.
There are variations within the library to handle processing these in series (async.series) and a multitude of other useful things, so it has really become, for me, an essential module for programming in Node.
Thursday, 14 August 2014
D in your results? Chill out!
Just seen someone on the news really upset about working really hard and only getting a D. It's a bell curve. Get used to it! A D in this years results still makes you smarter than your parents on average, and smarter than their parents. People are getting three IQ points more intelligent each decade so don't get disheartened by it.
We have to keep moving the goal posts to keep us getting smarter. The problem is that society tells everyone they can get an A if they work hard and it's simply not true. For the really smart people to get an A that means anything people like me have to get a D. And I did. That's just maths. Was I bummed? Yeah, but I adjusted my expectation and really focused on what I was good at and enjoyed. Am
I a world class pianist or software engineer? Nope! Am I ok with that? Yep (mostly) but I still work hard at both and am pretty damn happy where I've ended up with both.
Conversely I DID get an A at GCSE English but I can't write for shit, which I really wish I could do. That's just how it goes.
I hope all you results chasers get what you want, but more than that I hope that whatever happens you can look back in 10 or 20 years on the road you are setting out on and be happy where you ended up.
Monday, 11 August 2014
3 useful tunnelling scripts for mac - SSH, VNC and AFP
This script improves slightly on the original, as it catches CTRL-C and sets the location back to "Automatic".
Here's the next script - fires up screen sharing / VNC on a machine on my home network:
Note that the 192.168.0.11 should be the machine on your network you want to connect to - note the use of the private network 192.168 here. This is the IP address my iMac at home as been assigned. Don't forget to change user@mydomain.com again.
Finally, here's a new one - this allows you to 'mount' drives from a machine on your home network. It's very similar to the VNC script, but binds the AFP port, not the VNC one:
I've used a non standard port for this one to avoid conflicting with any local services you may have on this port.
You can share any service in exactly this same way - as long as you know the port number.
Enjoy!
Thursday, 7 August 2014
Theatre Ingestre present "Fiddler on the Roof"
Theatre1 is launched!
I am proud to announce the launch of Theatre1 - a new Theatre company, targeting excellence, openness and professionalism for young theatre. They are auditioning for Songs For a New World. You can sign up to audition and download the audition pack at http://theatre1.co.uk. Follow them on twitter @t1stafford, or Facebook.com/T1Stafford.
Monday, 30 June 2014
MYTS - West Side Story
MYTS will soon be opening with West Side Story, at the Gatehouse Theatre in Stafford, for those who are a fan of the show. I'll be playing keys for this, and it will be the biggest show MYTS has ever done. It boasts an orchestra (that's right - not just a band) of 18 players, and a sensational cast. For me it's been a slight change of emphasis back to actually playing the piano rather than programming. :-) If you have a free night, and are in the area MYTS never fail to disappoint.
RPI as secure web proxy
Once you have it working you *should* be able to ssh to your PI from outside your network, if you've configured your modem correctly. If you have purchased and configured a domain for this, or used one of the dynamic IP services then this will work a treat.
If you can't get this bit working don't carry on, as this next part relies on the fact you can actually make a connection.
In order to create the SOCKS proxy tunnel you enter a command similar to this:
Note the yourdomainhere.com - if you've not set up a domain you'll need the internet IP address of your modem here.
In the call here -v prints verbose information so you can see what's creating connections on the tunnel - leave it out for a quieter life. The -N stops the ssh default behaviour of executing a remote command - typically a shell, and the -D8080 is the magic which creates the tunnel. More on this in a second. The -o ServerAliveInterval=3 is a further optional parameter makes the client send a null packet to the server every 3 seconds, to keep the connection alive. Many ssh daemons kick off connections with no activity after some time, so this just stops that happening.
Now - more on that -D8080. This sets up a Dynamic proxy on port 8080. A dynamic proxy makes new connections as created on the remote host to service the requests on our local machine. SSH also allows the use of specific static routes, where a specific port on the client is routed to a specific port on the server, but we're not using that here.
I actually wrapped the above line into a script as shown here:
The script also reconnects if the connection drops, after a 5s delay.
You can see that I have set up a SOCKS proxy on localhost, on port 8080, which matches the port in our -D parameter to ssh. If you need to use a different port that's fine - just make sure the port you put in your proxy settings match the port in your -D line.
Again, if you're doing this in your browser directly (in Windows, say) you need to find the SOCKS setting and change it in this way, and it should work just the same.
I have this script in a bin folder I can access by running terminal, and then just running ssh-tunnel. It takes over that terminal tab, which I like because I can see what's going on, and to exit it just kill the tab or CTRL-C the script. Easy.
I would strongly recommend if you're going to do this that you also take a look at your SSHD options on the PI and remove password authentication altogether. I would also strongly recommend that you install fail2ban using this guide here. Fail2ban essentially monitors your access log file and automatically IP blocks failed login attempts. You'll likely never have any, so this means someone is trying to get into your system.
I would also do some googling on securing your PI and either set your modem to only forward port 22, or else bolt your PI down to prevent unauthorised access.
And finally....
Once you have an SSHD server on the internet you can access any of the machines on your internal connection. For instance, check out this bit of script which gives me a VNC client on my iMac INSIDE my home network. This uses the -L parameter to create a specific tunnel (rather than a dynamic one) from port 5900 locally to 5900 on 192.168.0.11. Now, what's this? 192.168 addresses are internal to my home network? That's right - this is in the context of the remote network. You can see the familiar pi@yourdomainhere.com to actually make the remote connection.
The last line is a Mac command to open a connection, but again, having made the connection you just need to open your VNC client and connect to localhost:5900 - like the dynamic proxy shown earlier you are making a LOCAL connection which is tunnelled for you.
Easy, huh! Now, go and be secure. :-)
Friday, 27 June 2014
Beware the Hero culture...
Tuesday, 17 June 2014
A must-have gadget... not my normal type of post...
I took delivery today of another such toy.
Like just about all of you I have probably built a collection of AV equipment in my living room based on quality. I have an Arcam biwired stereo and Rotel CD that SOUND good, a Samsung TV that LOOKS good, an Apple TV which enables streaming of content from our main machine (and Netflix). The problem has always been that while these are all connected fine there's a combination of remotes, and honestly, everyone from the babysitter to my mother all need reminding how to use any of it.
Not any more - introducing the Logitech Harmony 350 - the baby of the range, but good enough for me, and a lot cheaper than the bigger remotes. It's a general purpose remote.
Now - I know what you're thinking - you've seen these before? Endlessly typing codes in from the back of some Japanese or Taiwanese translated pamphlet in the hope that just some of the functionality you need will work? Not any more - this thing has a USB interface and some software so you give it the model numbers of your kit and it configures itself.
Better than that you can see if your kit is compatible before you buy one.
Finally it has shortcut buttons for turning everyone on and setting up the correct input and so on, all in one go.
I have put the four separate remotes in a drawer now, and we have just the one remote. I know it's silly, but this means you can have good quality separate pieces of equipment and still one remote. At around £40 for the 35 it's not cheap as chips, but it works so well. It even controls the volume on the Arcam stereo!
Saturday, 14 June 2014
£50 iBeacon PoC - "Welcome Home, Roger"
I used a few different guides for this, which I'll reference here. I didn't invent anything here, but found I had to use information from one or two guides, so I'll link them here.
Firstly - the dongle I used was one of these.
Then you need to setup the software on the Pi to drive it, for which I would recommend this guide. I would say though that this guide fell foul of actually getting the thing going. It was good for getting the software installed though. My particular combination of dongle and UUID or whatever just didn't quite work, so I then used this guide which is where I realised that I had some extraneous zeros on the end of the hciconfig command.
One *really* useful thing is to have two ssh sessions going, and have hcidump running in one of the windows. It gives you output like this:
You can see from my sample output here that it showed up a problem - when you issue the UUID and so on you should get something like:
The non-zero status is a bad thing!
The final part is to set up init.d scripts to automatically start the Pi broadcasting when you reboot the Pi, and this can also be found in the second guide - very handy.
I would advise doing a sudo apt-get update and probably upgrading the Pi firmware to the latest version using rpi-update (note that this caused my Pi to go into single user mode, so have that keyboard and HDMI connection handy if you do this).
The last part was to write the app, and that's still in progress, but to test the connection I would recommend the free app by Radius Networks. There's another app referenced in the docs, but it's not free anymore.
If you want to dig Xcode out and start cutting code then that's pretty easy too, and when my little welcome app isn't so hacky I'll share the code.
Note that if you do use the UUID in the second guide above there is already a profile which will detect this in the Radius App, called Apple Locate, so it's the quickest way of checking your BLE is working properly.
Have fun!
Wednesday, 11 June 2014
Like a kid again - Elite: Dangerous is nearly here
Friday, 6 June 2014
Nuclear safety - why do we get all bent out of shape about it?
You may have seen in the media that the Office for Nuclear Regulation is considering the safety limit for the degradation of graphite bricks which protect the nuclear core of a power station. The proposal from EDF is to raise the limit from 6.2% to 8%.
What concerns me is that already anti-nuclear lobbyists are jumping on this as the government putting power generation ahead of public safety, but this is simply not the case. The ONR has a good track record of imposing good safety measures based on actual science (you know - that thing that doesn’t give a shit about public opinion, it just is) so I would urge anyone thinking of getting up in arms about this to at least wait for the science to come in.
The ONR has told EDF to commission independent scientific consultation, as it is believed that 6.2% was extremely conservative. If this is true then raising the limit is just common sense - and it's not putting anyone at risk.
The thing is - if we rush too quickly to condemn this raise based on our misguided opinion of nuclear safety we will shut down our power stations 10 years earlier than we need to, and that would just be bad for power. We have a real power generation problem looming, so turning off our stations needlessly would be a bad thing. We are looking at rolling blackouts towards the end of this decade, and I love my internet connection way too much to not get vocal when I see that coming!
Also, a quick reminder, in terms of critical illness and deaths per megawatt nuclear power is just about the safest form of power generation - including solar (making the panels is a very toxic business and people die in their manufacture).
And now I leave you to your weekend… Enjoy the sun.
Thursday, 5 June 2014
Parsing Roman Numerals
It took me a few minutes to work out a neat way of doing that, so I thought I'd share in case anyone else needs it. It doesn't check the numerals are valid, and comes without warranty, blah, blah, but it works for all my tests. It's in Java, but would be easy to convert to any other language
There's the class Parser which does the work, and the RomanNumeral enum which stores the values for each letter. There's not much error handling either.
Enjoy!
public class Parser {
public static int parse(String romanNumerals) {
int[] values = new int[romanNumerals.length()];
for (int i = 0; i < romanNumerals.length(); i++) {
values[i] = RomanNumeral.valueOf("" + romanNumerals.charAt(i)).value();
}
return parse(values);
}
public static int parse(int... values) {
int total = 0;
int subtraction = 0;
for (int idx = 0; idx < values.length - 1; idx++) {
if (values[idx] < values[idx + 1]) {
subtraction = values[idx];
}
else {
total += (values[idx] - subtraction);
subtraction = 0;
}
}
total += (values[values.length - 1] - subtraction);
return total;
}
private Parser() {}
}
public enum RomanNumeral {
I (1),
V (5),
X (10),
L (50),
C (100),
D (500),
M (1000);
private int value;
private RomanNumeral(int value) {
this.value = value;
}
public int value() {
return value;
}
}
Wednesday, 4 June 2014
When is a stereo jack not a stereo jack? Know your cables!
I got to band call, and he was complaining that his piano sounded really tinny and thin - and indeed it did. It sounded fine on headphones, so I started tracing the wiring to the amp.
Here's the funny thing - he had a stereo splitter cable - 1/4" stereo jack to 2x 1/4" mono jacks - left and right. He'd connected the left and right to his Presonus box and the other end to the amp.
Now I know what you're thinking - I bet that's not a stereo input on the amp. You'd be right - it's a balanced input.
This led to a conversation with the young lad...
So, in a balanced TRS jack (which looks just the same as a stereo jack) the ring and tip both carry the mono signal, but crucially they are out of phase. This allows the receiving system to reduce noise more effectively, as the noise will be present and equal on both signals. There are many technical journals about differential balancing if you're interested.
The main point for this blog post is that the amp that Tom connected his keyboard to expected the ring to be a phase inversion of the tip, not a Right channel, and the processing that then took place effectively wiped out the bass entirely from the mix.
Have you ever wired up a car stereo system and got one of the speakers out of phase? I've done that, and it has the same effect. The relatively low frequency bass sound waves cancel each other out. You can get the same problem in large studios that don't have bass traps - the sound waves bounce of a wall and mix with the direct sound waves, but at a different phase, reducing (or building) the bass sound.
So, he unplugged the Right output from his Presonus and all was well. Whether or not he remembers why that worked is another matter. :-)
Incidentally, I've started using balanced line outs on my keyboards and have found a significant reduction in noise and a slight boost in input signal, so I'd recommend it.
Using a Raspberry PI as DNS and DHCP tool
It's actually trivially easy to do. If you're already using udhcpd you may want to switch, as you can do it all in one config file, but you don't have to.
Firstly apt-get the package:
apt-get install dnsmasq
Thursday, 29 May 2014
RSync PI anyone?
Friday, 16 May 2014
Motu 828x Thunderbolt / USB audio interface - a review


Wednesday, 7 May 2014
Devout or fundamentalist?
Wednesday, 30 April 2014
Social Equality vs. Fairness
This was sparked by the news that Lloyds TSB are to offer bank accounts which obey Shariah Law, and as part of that pay no interest, but interestingly, charge no overdraft interest either. This led me to kick off a discussion around how this was unfair on non-muslims. In general, as an atheist, I see many things in society that are deemed acceptable because they have a religious basis, which are ridiculous if you actually treat all religion with the same disdain. Why, for instance, do religious bodies get tax benefits and CoE ministers are paid by the tax payer to attend the beds of the terminally ill? This is surely not fair on the rest of us?
Now it turns out these bank accounts are actually available to anyone, so in theory, anyone could move a credit card balance to an agreed overdraft facility at Lloyds and get it interest fee. So, despite the pandering to the Islamic community to get more business (too cynical?) it's actually not unfair in that everyone is treated equally in that case, but let's stick with the equality-vs-fairness theme a while longer.
It got me thinking a little about the nature of fairness and equality in society, and I wondered if maybe fairness and equality are mutually exclusive. Let me try to explain my reasoning.
I suggest that fairness cannot be measured quantitively, and as such is a purely relative and subjective measure. Equality, however, CAN be measured. Let's look at an example to try to illustrate my point. I pay a higher rate of income tax because my income is in the high rate tax payers bracket (like nearly every other white collar IT consultant I'd say). Is this fair? Not on me it isn't! A percentage based system ensures the more you earn the more you pay, but arbitrarily I am on a higher percentage. That doesn't sound fair at all. However, society has deemed a certain set of social services which must be paid for, and that only works on a raked income tax system. If I agree with paying for schools, hospitals, care for the elderly, etc. that's just the way it is. We all have equal access to these services - the rules are largely applied equally to every member of our society, but it's hardly fair. I'm paying more for the same set of services.
Let's try to make this mathematical sounding to see if rules of equality and fairness can be made simple - let us talk about applying rule A to bodies X and Y. If rule A is applied to both, irrespective of any properties of X and Y this might suggest that both bodies have been treated equally. Rule A is applied blindly without any cause to refer to the bodies to which the rule is applied - a bit like access to the NHS. The NHS is free at the point of use, and all of us can rock up at A&E if we need to. Easy. If, however, the properties of X or Y are considered in the decision as to whether or not to apply rule A this would suggest that they are not treated equally in order to attempt to treat them fairly. So you get rules which target certain individuals which are fair, but by definition not promoting equality.
Let us make this a bit more real - let us say that body X is a man, and body Y is a woman. Now let us say that childcare benefit is provided only to body Y on the basis that she is a woman - this may seem fair (and indeed is largely how our society is still geared up) but it's hardly equal.
So society decides some abstract, empirical, historical, political and perhaps religious rules for defining the properties which define different types of bodies, and then these properties are factored into the rules, making any potential for an "equal" society surely impossible. Given that we can also not be fair to everyone it feels like in our attempt to be "fair" we are actually perpetuating social inequality in the truest sense of the word.
Would it be better to only apply rules which can be applied equally to everyone, and discard the rest? Most of our laws are like this - religious people who feel compelled to wear certain clothing still have to wear crash helmets on motorbikes, for instance. Equally, rules around trade and industry do not take account of Jewish dogma regarding the Sabbath - there are many examples like this. Those people may choose not to do certain things on certain days in the week, but there's no law (nor should there ever be a law) that says I can't buy stuff and work on a Saturday.
One problem with this whole post is that back to my first example, because, actually, anyone can apply for an Islam account with Lloyds TSB the rules are applied irrespective of any religion "property" the applicant may have, and so it is an equal rule, but in this case that also sounds fair, so it's possible this is a circular argument as in this case it is both equal and fair, which may make the whole thing moot, but I think the end result is that it is not possible to treat everyone equally because we are not equal. Some people need more social support than others, some people need to pay more tax than others, and we need to treat these people unequally in order to be fair.
The only thing society then needs to work out is what is a valid set of properties on which to base the differentiating rules - I would argue that we should restrict this to empirical and scientific based properties only, otherwise we'll end up chairing arguments between religions, psychics, homeopaths and astrologers, and that can only end up in a world of shit!
Tuesday, 22 April 2014
SQL vs. NoSQL - some initial findings
1. I believed based on things I had read that a carefully structured relational database, with an optimised schema would be faster answers the questions it was designed for than any NoSQL solution. I’m not entirely sure this is true in the vast majority of cases. I actually wonder if the edge cases where this may be true make it worth using SQL unless you can really, REALLY show that it’s a good idea.
2. I had not really thought too much about the boilerplate that goes with SQL vs. NoSQL, but compare these two bits of code:

and:

These both do the same thing - use a DataGenerator to generate a bunch of test data, which in this case creates a load of first and last names, and emails. In the case of the SQL test (no ORM to be fair) there’s way more code because you have to somehow map the object domain to the data domain. Not so in the second, where you just chuck the object into the db.
This leads me to:
3. There is no “schema” per se. There are just buckets. This feels a bad thing - strong typing is good, right? Well, adding a column to a database that’s been running for a while and may have millions of records is a big deal. In a NoSQL solution you just add the new kind of object. Old objects will simply not have the new field (so one assumes you need some null checking and maybe be careful how you rebuild your Java object akin to serialisation perhaps (?) but the db is ultimately flexible.
4. Last one for now - check out the search code below. Each does the same thing - does a search for all names that start with a capital “A”:

and now the MongoDB version:

See the function chaining in the MongoDB solution? How elegant is that? Rather like Java8 streams or the kind of sequence processing you see in Clojure this is a really elegant way to process the results. Incidentally, it’s a load quicker in MongoDB than it is in Derby DB for any number of records. I’d like to say that this is because it’s a LIKE type query which is just about the most horrible thing you can do in an RDBMS, but actually, EVERY query is quicker in MongoDB. Counting the records, searching for a specific record - they’re all just quicker in my MongoDB version.
I’m sure there will be people thinking I’ve got my RDBMS tables set up badly or whatever, and while there may be optimisations I could do I’ve done nothing to either Derby or Mongo - this is just out of the box.
Interesting stuff - download MongoDB from www.mongodb.org and have a play.
Thursday, 17 April 2014
My first bit of Clojure... Hello Pi.
Postfix notation
Put simply the operator is pushed first, and the operands afterwards. This looks weird at first (compare (2 + 3) with (+ 2 3) for instance, but actually, in clojure every “form” consists of an operator and it’s operands in brackets (str “abc” “def”), or (conj set-a set-b), or (+ 2 3) - make sense now? It does make long mathematical equations odd to look at, as you can see in the code fragment which calculates Pi below.Looping
Clojure does have loops, but idiomatically good Clojure doesn’t really use them in the way you think it might. My little Pi generator below makes use of loop and recurs, which is quite standard, but it’s not really a for loop. In fact, in Clojure, there isn’t really a for loop - only a for-each loop, for processing sets or sequences.Lazy Sequences
Not something I’ve used outside of database or file access in Java this is a way of creating a sequence of infinite length. You can define how a sequence is generated, but it is not actually processed until you take numbers from the sequence, with the (take) function, or in some other way force evaluation of members of the sequence. Very neat indeed!The Syntax
It does make sense when you spend a while working with it, but I’m still a beginner, and sometimes find myself doing something like:(printf myVar ” is a bit like ” + myOtherVar)Of course, I get some odd output as the + is evaluated and it’s .toString representation called. + in Clojure (like the other operators) is actually a Function, so you get an odd looking function reference - much like if you .toString an object in Java.
You do get used to the brackets, and code is broken down into much smaller fragments generally, which is no bad thing, but you do end up with a more fragmented programming style. It really is like going back to my first language in some ways - Logo! Remember that? Control a turtle to draw stuff on paper, and write simple functions which you then nest up in more complicated functions. Super fun!
My little Pi generator
I’m sure there is a ton of stuff wrong with this as I’m really just learning the language, so I welcome comment and guidance, but here it is anyway.Note that the more max-recurs you pass in the closer to Pi you get, but due to limitations in the program somewhere you never quite get to Math.PI. But it’s only to try and learn the language but not be the definitive Pi generator. :-)(defn calc-pi-method1
([] (calc-pi-method1 100))
([max-recurs] (loop [r 1 pi 3.0]
(if (> r max-recurs)
pi
(do
;(println “r=” r ” pi=” pi)
(def div (/ 4 (* (* r 2) (+ (* r 2.0) 1) (+ (* r 2.0) 2))))
(if (even? r)
(def newpi (- pi div))
(def newpi (+ pi div)))
(recur (inc r) newpi))))
))
; main
(println (calc-pi-method1) ” compared to a Math.PI value of: ” (Math/PI))
Laters.
Sunday, 6 April 2014
SFX for How To Succeed
So, why this post?
My telephone ringing sound effect - not the most complicated thing ever - is a perfect 1950’s bell phone ring.
But this is an American show. The ringing cadence is completely different. Also the props are trim phones not bell phones. Gah! So that’s me redoing them tomorrow. Any job worth doing… No one would notice, but I would know!
Thursday, 3 April 2014
Big Data Analytics and Security
The idea of Big Data Analytics in general is to make use of a sea of data (or a lake, if you prefer) to perform predictive analytics, insight, and generally use clever heuristic or other algorithms to tell you things you couldn’t have found out with a million monkeys and infinite time. Because of my current work with retail this for me has meant interacting with customers in the right way, at the right time, on the right channel.
However, the RSA boys have started preaching an alternative security model to the “Prepare to repel borders” perimeter focused security I certainly am used to. I’m no security expert so this may not be news to people in that space, but I found it really interesting what the alternative view is, and where it leads.
Essentially the security community is moving away from perimeter defence focussed to security - prevention, in other words - to analytics - detection. This is taking some time to work it’s way through the board rooms and across the golf courses of senior boards, but it’s a really important step.
Let us assume, for a start, that security breaches WILL happen. It’s inevitable. What tradiitonally happens then is a massive effort to work out what has happened, how, and how to stop it again - if the breach was even detected in the first place, and this is an important point. It is in most hackers interests to not even let you know they were there, so you leave the door open.
Introduce an analytical model - this anticipates that breaches will happen but automatically flags up when they do based on unusual activity. This means that the actual security event could be shut down way quicker than normal, and reports generated to try to close those back doors down.
Combine this with the quite inspiring take on employee freedom and you have a quite different model to the one I’ve seen in any large company I’ve been in.
In order for an analytical model to work you need the data. Currently the perimeter and blocking hard handed mechanism employed by most IT depts. means employees find workarounds - Dropbox, or SSH tunnelling - external VPNs - whatever they need to use to get their job done. The problem is none of these can be monitored by the organisation. The employees just need the tools to do their job, so introduce SSO on the web proxy, and generally allow employees to use what they want and now you can analyse usage on your network much more effectively.
This may mean you let employees use Facebook, but I put it to you that if you stop them doing this on your machine they’ll do it on their own machine, or on their own 4G dongle, and now you have no control or worse, any view on that behaviour, so if someone DOES use malware to take over control of a corporate PC there’s a lot less a chance of you seeing it.