Erlang: Reltool , lib_dir and incl_cond driving you mad? This might help…

Rebar has built in support to create a release using reltool. This is actually pretty sweet when it works because you get everything all wrapped up ready to go including init scripts which is especially helpful.

The problem is trying to get it to work can be something of a nightmare. If you set lib_dir to include “../..” then you will end up with reltool detecting multiple versions of software, detecting old versions or just refusing to detect them altogether.

The standard advice is to exchange incl_cond from exclude to include. However this then includes everything which you probably don’t won’t and it will still miss some of the dependencies that you need (in my case it could never find erlmongo). If you go the other way and specify each dependency, you need to do that by hand for each app as well as those app’s dependencies. That’s not fun and a recipe for disaster.

Today I came across this post:

http://groups.google.com/group/erlang-programming/browse_thread/thread/7ebe5c7209c149c9

This contained the answer to my prayers and got my app working perfectly! It is a new feature in R15B01 (which is now in general release) that allows you to specify a directory as part of the include condition. This means you don’t need “../..” in lib_dirs and so now things will (probably) work as you had hoped!

 

Posted in Erlang, Software Engineering | Leave a comment

Erlang: Adding psubscribe support to eredis

Well it may not seem like much but today I had my first pull request accepted on GitHub. I really needed pattern subscribe in the eredis driver. Although support for publish and subscribe had already been added, this didn’t include support for pattern subscribe. I guess while the pub/sub pattern is pretty common, not as many people need to be able to pattern match on many different channels at once.

I am really grateful for the existing pub/sub support though as this was in fact what I needed initially. It was only later when I discovered some cool stuff I could do with pattern subscribe that I looked for information on how to use it – and of course found it wasn’t there.

I was able to take the existing code and from that add in support for pattern subscribe. I certainly could not have written it from scratch myself but by using the rest of the code as a template, I was able to come up with a working solution.

I tidied up the code and made a pull request, but the author (quite rightly – and politely) asked me to add some tests. I’d never really written formal tests in Erlang but I was keen to share my code so I learned how to write the tests.

And so, after writing the tests, the author kindly accepted my patch. So now my little change will have a lot more impact. Anyone who wants to use eredis with pattern subscribe can now do so.

So while it is just another day for those guys who put in all the effort on huge projects, for me it’s something pretty special. I definitely look forward to contributing more actively in the future!

For those interested in the link itself (you can see what happens when I try to write tests at 3am) check out https://github.com/wooga/eredis/pull/26#issuecomment-5148823

Posted in Uncategorized | Leave a comment

New version of Kurso de Esperanto available

One of the courses I highly recommend on my Esperanto page is Kurso de Esperanto. When I first used it however it was a bit out of date. The content was fine and everything worked, but it was clearly designed many years ago.

I found today that they have released a new version this year and it looks like a complete rewrite. Fully modernised, the application is better than ever! Definitely check it out if you’re interested in learning Esperanto!

http://www.kurso.com.br/elshuto.php?en

Posted in Esperanto, Languages | Leave a comment

MTR fails briefly and creates havoc for hundreds of people

The MTR (Mass Transit Railway) is Hong Kong’s extremely reliable, fast, clean and efficient metro railway system. It moves a huge amount of people every day and even with trains departing every minute it is not uncommon for each carriage to be packed full of commuters.

The problem is that when there is even a slight glitch, the system backs up very quickly. In just a few minutes, an entire station can be brought to its knees. The MTR is generally very reliable so it’s not something that is seen very often. In the UK you can blame the train for being late, but in Hong Kong no one would even dare try that excuse – no one would believe it!

When it does go wrong though as it did this morning, things are quite noticeable. Today, the Tsuen Wan line which connects Kowloon to Hong Kong Island was running happily and depositing nearly a full train’s worth of people at Admiralty so they could change to the Island Line. Unfortunately, the Island Line had failed causing people to back up.

I arrived just after it happened. With the Island Line dead and the Tsuen Wan Line depositing new people every minute or so, things were getting somewhat tense. In fact the staff started shutting down entrances in Admiralty for public safety due to the crowds building on the platform.

I took a couple short videos of the mayhem here:

These videos go to show that even a well designed reliable system can go wrong and when it does it is important to have fail safes in place (such as stopping incoming trains and restricting entry in the station itself). Still, if I was in London I wouldn’t be terribly surprised but because everyone here is so used to the MTR being perfectly okay, we only notice it when it goes wrong.

On the bright side I ended up walking the rest of the way to work, so I got a decent bit of morning exercise which is never a bad thing!

Posted in Hong Kong, Uncategorized | Leave a comment

Esperanto: Back to basics

One of the courses I recommend on my site is:

http://ikindalikelanguages.com/labs/courses.php?id=28

It only has five short lessons but it really is amazing how much is packed into such a small space. You can complete the course in about an hour or so but you will learn many of the key concepts of Esperanto and more importantly be able to use them.

For me, this was my second time through. I haven’t touched Esperanto for quite some time and so I was curious as to how much I would actually remember. It turns out that I didn’t remember a huge amount but almost everything I did was familiar, kinda like a song you used to know as a kid, that sort of thing. This meant that while I was having to pick up the words again, the concepts were well known to me so it was like putting on a pair of comfortable old shoes. The skill was lost but not quite forgotten.

I’ll probably go through the lessons again today quickly, just to solidify my understanding (or at least double check it) and then go back to Kurso de Esperanto. I wish there was a more modern version as this one only runs on Windows… Maybe something to look at in the future? :)

Posted in Esperanto, Languages | Leave a comment

Practical Load Balancing – Published at last!

At long last, Practical Load Balancing has been published! It has taken a lot of effort from a lot of people to get this one out the door but I think people will agree that it was worth it.

The book has a slightly different slant from the original concept. At first we were planning a very technical book but after talking with a lot of people we realized that there was a greater need for a book that would bridge the gap between intermediate users and advanced. That’s not to say that the book is light-weight as it certainly isn’t. Rather, it’s positioned so that as many people as possible to get up and running quickly while still having more advanced content in there for those that need to go the extra mile.

Thanks to everyone who made this book possible!

Posted in Uncategorized | Leave a comment

Esperanto: Rinse and Repeat

Although I haven’t touched it in months, I still think Esperanto will help me learn Chinese. I was doing quite well and then life got very busy and I lost track of it. It’s a pity really as I think I was doing quite well. Not amazingly well admittedly but better than I’d been doing at Chinese, and my brain was also getting to the point where it might finally accept that it was capable of using a language other than English.

So, now that I’ve cleared a huge amount of my backlog, I’m going to try the Esperanto course again and see how far I can get this time. Hopefully I will break through Lesson 5 (it seems to catch a lot of people) and actually get to the point where I can use it.

The correspondance course is really good and I have an excellent tutor. If you’re interested in signing up, you can find the course at http://pacujo.net/esperanto/course/. As before I’ll try and post updates after I get feedback from each lesson. Previously I was getting one done every day, but let’s see how it goes…

Posted in Uncategorized | 1 Comment

Black Scholes in Erlang

Black Scholes is the model of choice for pricing options. If you don’t work in finance or have no interest in trading derivatives, then it’s unlikely you’ll have come across it. However there is a great site that lists a huge number of implementations of the model in pretty much every language you can imagine – and then some. It even has a version in Excel (which by the way is very useful as a reference implementation for testing). You can find loads of different versions here:

http://www.espenhaug.com/black_scholes.html

Unfortunately the one language that seems to be missing is Erlang. As I wanted to do some concurrency tests in Erlang ( I had already tried it in Haskell ) I decided I’d simply make my own (highly nieve) version. As I already know Python, the version here is based on that version by Andy Smith. I’ve emailed the site maintainer with my Erlang version but unfortunately I haven’t heard back yet.

Anyway for those curious or looking for such an implementation, here it is:

% Simple Black Scholes implementation for Erlang
% Author: Peter Membrey
% Date: 5th March 2012
% Based on Python version by Andy Smith at:
% http://www.espenhaug.com/black_scholes.html
%

-module(blackscholes).
-compile(export_all).



calcCall(S,X,T,R,V) ->
D1 = (math:log(S/X)+(R+V*V/2.0)*T)/(V*math:sqrt(T)),
D2 = D1-V*math:sqrt(T),
S*normalDistribution(D1)-X*math:exp(-R*T)*normalDistribution(D2).

calcPut(S,X,T,R,V) ->
D1 = (math:log(S/X)+(R+V*V/2.0)*T)/(V*math:sqrt(T)),
D2 = D1-V*math:sqrt(T),
X*math:exp(-R*T)*normalDistribution(-D2)-S*normalDistribution(-D1).


normalDistribution(X) ->
A1 = 0.31938153,
A2 = -0.356563782,
A3 = 1.781477937,
A4 = -1.821255978,
A5 = 1.330274429,
L = abs(X),
K = 1.0 / (1.0 + 0.2316419 * L),
W = 1.0 - 1.0 / math:sqrt(2*math:pi())* math:exp(-L*L/2.0) * (A1*K + A2*K*K + A3*math:pow(K,3) + A4*math:pow(K,4) + A5*math:pow(K,5)),
case X < 0 of
true -> 1.0-W;
false -> W
end.

 

Posted in Erlang, Software Engineering | Leave a comment

I’m back!

Okay, I know the date makes this post a little suspect, but I can assure you that it’s not meant as a joke. I have been really busy recently finishing up some projects and taking care of some things that had been left too long. Unfortunately this took time away from other things, time that I will now be putting in where it’s needed.

So nothing ground breaking today, but I will have a mildly interesting post tomorrow, and if nothing else at least it will keep the content flowing…

Posted in Misc | Leave a comment

IET Enterprise Linux Seminar at the Hong Kong Polytechnic University

When I gave a Linux seminar about six months ago, I had the foresight to bring a camcorder so I could capture the event for those who wanted to attend but couldn’t especially as it was on a Saturday morning. Well I’ve finally gotten around to pulling the video, doing a bit of editing and getting it uploaded to YouTube. As they say (and I hope you agree) better late than never!

The seminar was an IET event held at the Hong Kong Polytechnic University’s Hung Hom campus back in May 2011. It was sponsored by the Computing Department who provided excellent facilities (as you can see from the video) and wonderful refreshments (which you can’t see in the video because they were eaten long before the seminar started). Many thanks to both the IET and the University for making the seminar possible!

So, without further ado, here is the video itself which is also available directly on YouTube. I hope you find it useful and enjoyable and if you have any comments, corrections or suggestions for next time, I would be most happy to hear from you!

Posted in Uncategorized | Leave a comment