Posts

Languages and databases - a step back a day

Image
I've started to learn the Go language recently and to be frank I'm horrified. Horrified by the way the future of programming looks like and the NoSQL movement just making it worse. Languages - a step back If you haven't read any Fortran code yet, do it by any means. It's a language that was invented in 1957 when 'computers' were practically non existent. However, if you look at it more than 50 years later it's still readable and not really ugly - especially compared to some C++ code... Then we had Python, Ruby, Java, C# and all sorts of modern languages. In fact, we have a new language born almost every day (have you heard about Rust for instance?). The only issue with them is that the programming model hasn't really changed in the past 50 years. We write text files, line by line, instructing the computer what to do step after step. The processors didn't really change much either unfortunately. And the horrifying part? Google comes along, ...

The next big thing on the web – custom HTML elements

Image
If you are either a HTML component vendor or ever wanted to use someone else's HTML module, you already faces the same issue: components may not work together and even if they do, they put a lot of noise in your pure HTML structure. This is going to change very soon. Large component vendors like Kendo or Telerik are creating amazing HTML components that are, in theory, just plug and play: whatever framework you are working with it should be really easy to use those enhanced modules. However, even if they work as they are intended to, they change and litter the HTML DOM so any kind of debugging can be a bit of a pain. Noisy HTML The problem is that even if we start with a nice and clean HTML code that looks like this: <select id="size"> <option>S - 6 3/4"</option> <option>M - 7 1/4"</option> <option>L - 7 1/8"</option> <opti...

Simulating crowds and animal swarms

Image
If you've ever looked at an ant farm I'm sure you were surprised by how organised they were. But the truth is they all follow a very simple logic which “magically” adds up to a large scale organised colony. How do they do that? Swarm behaviour is not really observable on one entity but very visible on the large scale. Interestingly it works with us, humans as well: we don't know how we board a train or plain but a simulated environment can predict very well will we move and how efficient the crowd movement will be. Boids Studying the crowd movement is not new by any means: Craig Reynolds in 1986 came up with three simple rules that can describe the large swarm movement quite accurately. He named the rules as “boids” after birds (it supposed to be the New York accent style bird?). The three rules are: - separation : the entities prefer to keep some distance from each other - alignment : try to go the same way as the group or the local flock-mates - cohesion : t...

Ubuntu loses network connection after do-release-upgrade - Ignoring unknown interface eth0=eth0

Over the weekend I decided to upgrade one of my linux servers, running an Ubuntu desktop. The Ubuntu do-release-upgrade tool is pretty reliable, even over SSH the whole process completed without any errors (try that from Windows 2003 - 2008). The only issue is that after reboot the machine disappeared from the net. Had to hack into the console to have a look what's going on. Turns out my eth0 interface wasn't configured so didn't get any IP addresses: > ifup eth0  * Reconfiguring network interfaces... Ignoring unknown interface eth0=eth0. The fix was pretty easy, just had to edit /etc/network/interfaces files and try again: auto lo iface lo inet loopback # For DHCP only auto eth0 # Statis IP assignment iface eth0 inet static address 79.1.2.3 netmask 255.255.255.0 gateway 79.1.2.1 # Google's DNS - fast and reliable dns-nameservers 8.8.8.8 ifup eth0 was much friendlier this time, the box was back on the net again.

Static constructors and sealed classes - how to make your code untestable

Image
In almost all programming languages there is a possibility to put some application logic in static constructor. However, it's usually up to the platform to decide when to execute the code we put there - usually it happens when we the environment runs a piece of code that refers that class. Recently I was reading through the Windows Azure Training Kit (written by Microsoft) and this is a piece of code from the kit: public class GuestBookDataSource{ ... static GuestBookDataSource() { storageAccount = CloudStorageAccount .Parse(CloudConfigurationManager.GetSetting("DataConnectionString")); CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient(); CloudTable table = cloudTableClient.GetTableReference("GuestBookEntry"); table.CreateIfNotExists(); } ... } This code will open or create a cloud SQL table before accessing anything around it. As the code runs only once, it's seems like an efficient way to do the initialization of the ...
Image
One of my projects uses a self hosted executable that is accepting incoming connections on port 80. The package has an embedded Jetty so I didn't need to deal with any low level TCP stuff. That is the good part. The bad part is that it turned out that the hosting environment (Ubuntu linux) for security reasons by default does not allow a non-root user to use any TCP port below 1024 - so the first free for all port is 1024.                                                                                                                           One easy solution would be to set up Nginx and forward the traffic it receives on port 80 to my self hosted app on a different port. Quite e...

Are we developers the romance writers of the science world?

Image
As developers we tend to do repetitive, sometimes tedious labour every day. We stand at a scrum/kanban board every morning pretending the problems we are facing are interesting, hard and we are the only solution to them. Maybe we think we are the smartest in our team. Maybe everyone in that team thinks he is the smartest. Anyhow, the job we have to deliver as an everyday developer relies roughly on the same technologies. We like it or not, but most of our work is based on someone else's work, someone else's idea, methodology. It's so rare that we, as everyday developers can add something brand new that wasn't there before. And no, a HTML5 progress bar is not all that new. And no, creating a iPhone app that uses Facebook login is not new either. But if we are not really in the invention part of the game, surely the people at the big fancy IT companies are, right?                                  ...

Using Vim on Mac OS - basic settings

Image
In every programmers life comes a moment when they need to deal with Vim somehow - some people just need to close it once accidentally opened, some people need to start using it for work. For a long while I could get away without using it but then I had to start editing Octave scripts and a simple notepad did not seem to be too useful to do that. Ancient roots Vim was released 21 years ago so most of us can argue that is is an ancient editor. An editor from an era where even Java wasn't invented (it was released in 1995). This reason alone could invalidate its usage as so many things changed since then. Well, the thing may not be that different. We are still using some kind of text editors to write source code and the problems around code writing are roughly the same: quickly edit and reformat specially formatted texts. From the first look Vim is an editor that does not even support mouse and even deleting a line is troublesome - not to mention exiting the editor. However...

ReSharper free alternative

For a while I was using ReSharper but soon I had to find out that the price and performance of the tool just does not compensate for the features it provides. On a larger solution it just got slower and slower and even though the performance was kind of acceptable it just did not feel right. So I decided to find free alternatives for ReSharper, especially for features that I was really using: quickly jump to files, coloured tabs and organising the 'using' sections. Quickly opening files Probably the most frequently used feature of ReSharper (or at least for me) is to quickly open a file by its name. There are several free plugins that can help you with this but PhatStudio was the fastest and most convenient to use. Simply pressing ALT+O will bring up the dialog and ready to start typing fragments you are looking for: " cu or " for instance would find " CustomerOrder.cs " file. No need for fancy wildcarding, the authors got it perfect. Thanks for this f...

Count the 1 bits in an integer – interview question and branch predictor crash course

Image
One of the typical computer science interview questions is to count the “1” bits in an integer. There are many solutions but which one is more practical or faster? A crash course on branch predictors. Let's say the integer we want to count the "1" bits in is: 698 (decimal) In this case the binary representation is: 0010 1011 1010 (binary) so the answer is: 6 Let’s look at three simple implementations and try to guess which one would be faster and why: (note: the code is in Java and the >>> operator is the unsigned shift. It’s usually just >> in other languages). Solution #1 – count to fixed size int cnt = 0; long l = getLongToCount(); int bits = 64; for (int k = 0; k < bits; k++) { cnt += l & 1; l >>>= 1; } Solution #2 – count while non zero int cnt = 0; long l = getLongToCount(); while (l != 0) { cnt += l & 1; l >>>= 1; } Solution #3 – count while non zero and add 1 only int cnt = 0; long l = getLo...

Javascript unit tests with QUnit, PhantomJS, driven by Ant

Image
The project I’m currently working on ( Qoll.it ) is fairly Javascript heavy so it was essential to have at least some core functionalities unit tested before they can be submitted to the repository. Running Javascript unit tests in the browser and relying on developers really doing it before submitting code may not be the best idea – they might be in a hurry, or even worse, can get a bit lazy. Let’s see how to make the Javascript unit testing part of the build process. Javascript unit testing There are a lot of different frameworks for Javascript unit testing, so as long as we are not changing the syntax radically of the testing between Java/C#/Javascript, Javascript unit testing will be as normal as testing compiled code. However, some of the frameworks use a very different way of testing: describe("Package X", function() {   it("really should be true", function() {     expect(true).toBe(true);   }); }); Even though the syntax is entertaining to ...

How to deploy an app to iTunes Store - for iPhone and iPad

Image
I don't publish too many iOS apps so by the time I have to distribute a new one I've already forgotten what the exact steps were. Unfortunately the Android Store (Play) and iTunes store uses quite a different approach, so this is partly a note to self how to do it next time: Create your app in iTunes Connect , add description and  images. Status should be Waiting for Upload. Create a new Provisioning Profile for Distribution , download and import into iTunes (just click it) /note: you already had to have a provisioning profile for development but now you need an another one for publishing the app./ In Xcode project settings (Target, Build Settings), search for "code signing" and set the all signing to your new profile, the distribution profile. /note: an app that is signed for distribution cannot be run on emulator and vice versa./ Chose Product/Archive, which will build your app distribution package Open Organizer (Window/Organizer), and click Validate on...

Simple statistical language detection

Image
Given one sample news article in English, create a statistical analyzer in 30 minutes that is able to reliably recognize English text. Before we begin let’s consider that even though not everyone speaks French almost all of us are able to recognize it. The rules of a language are visible from very low level even up to the culture itself, so creating a simple language detector that deals with the lower levels of the language shouldn’t be too complex – well, at least in theory. The problem One of the projects I’m currently working on requires me to detect whether the user input is in English to make sure that the user generated content is placed in the right category. To my bad luck Google has shut down its language detection service so I had to find something on my own. After considering couple libraries I decided to investigate a bit: in theory, every language has very specific phonemes so I should be able to find the typical English sounds and match my incoming user conte...

Interviewing bad practices

Image
During the years I was looking for jobs or was looking for candidates I’ve seen and made very typical mistakes around hiring. To be honest, probably I covered all these during this learning process, so I collected the very common ones as a reminder. I hope this post –even if just a tiny bit- will help someone how not to interview candidates. Library knowledge Probably this is the most common one that candidates face during interview. Questions like “What is the difference between X class and Y class in Z framework” are totally meaningless. They can help you to see if the candidate worked some with the technology but apart from that every question has its exact answer on the first hit on Google – probably a Stackoverflow thread. It all does not matter – the question is: can the candidate solve a problem I throw at him/her? Library knowledge is not problem solving. Language knowledge Unless you try to find someone to start your new thing in a specific technology, focusing too ...