Skip to main content

Posts

Online passport photos

 If you want to make free passport photos, this is an awesome way to do so https://www.123passportphoto.com/ It will automatically resize the photo based on a country template, removes shadows and enhances the photo. I have never had any problems and works all the time. It costs you $10 but it's much cheaper and convenient than going to the studio.
Recent posts

What is Apache Maven?

Apache Maven is a cool java project management tool that I recently came across at work. I was asked to set-up a test suite for our low latency Market Data System project using an existing test framework built using TestNG. I was handed over something called a pom.xml file and that was it! Using IntelliJ IDE you can import this pom.xml as a Maven project and everything is basically set-up for you. The folder structure is pretty standard in Maven so that every developer get the same same project structure. I think the main advantage of maven is that it is a great way of managing dependencies. Imagine that something changes in the the so called test framework. The framework developers update the repository and when I re-export the pom file updates the correct jar file will already be in my project. By changing the SNAPSHOT version of the pom.xml file I can switch through different versions of the test framework and other dependencies. Maven will first look for dependencies in the inte

State Pattern Anyone?

Here's two exciting link I found about the state pattern. Two very good reads. http://gameprogrammingpatterns.com/state.html http://angry-architect.blogspot.com/2006/08/problems-with-state-pattern.html

Visitor Pattern

It is often require to separate an algorithms from the data it operates on. For example say that we have some inter process communication messages that needs to be sent out from a TCP channel. The message is the parent class and different messages are derived from this class. The sub-message class object that has some member variables that are used to pack the real messages to be sent out. The straightforward way of doing this is to have a virtual function pack() defined in the message class itself and implement it in every sub-message class and call it whenever we need the message to be generated. However this is not that efficient because if we need to change the structure or the format of the messages that we need to send out, the pack () of the that specific class should be modified. If all messages require a addition of a different field all messages have to be changed. Not if you have introduced the visitor pattern. Compare the visitor pattern with the standard approach.

Linux file permissions - what's with the numbers?

Everybody uses commands such as chomd +x "some file" , chomd u+x "some file" (for the user only) or chmod 775 "some file"   The available options are read (r, or number 6), write (w or number 2) and Execute (x or number1). Each of these can be applied to user, group or others making sense of 777 type permission commands. A good explanation can be found here . With the basic understanding of the Classes and Permissions, let’s delve into it further and see how the “777” or “775” come about. Every file and folder contain a 8-bit data that control the permissions. At its basi c binary form, it will be “000”, which means no permissions of any form is granted. When you set a “Read” permission, it will add 4-bit to the data, making it “100” (in binary format) or a “4” in the usual decimal format. Setting a “Write” permission will add 2-bit to the data, making it “010” and “2” in decimal form. Lastly, setting an “Execute” permission adds 1-bit

How would you implement a StringToInt from scratch?

sYou are given a integer in string format; String sNum = "25"; int iNum = StrToInt(sNum); How does StrToInt() work? Crudely it's as follows. You go digit by digit. Each digit has a hex value. 0   0x30   48 1   0x31   49 2   0x32   50 3   0x33   51 4   0x34   52 .... 9   0x39   57 The algorithm pseduo-code is as follows. 1. result = 0; 2. for each character i in sNum 3.   result = result*10; 4.   result = result + ASCIIVal(sNum[i]) - ASCIIVal('0'); Let's take 25 for example. For the first iteration; sNum[0] = 2; result = 0*10=0; result = 0 + (50-48) = 2; For the second iteration; sNum[1] = 5; result=2*10=20; result=20+(53-48)=25

memcpy and it's usage with structs

A good question on stack overflow can be found here It discusses about the size of the array being different to the sum of the size of each member. e.g. struct Item{     int i; // 4     char buf1[10]; // 10     char buf2[20]; // 20 }; sizeof(test) is actually 36!!! This is because of padding the members... Memory is usually organized into 8 byte chunks, so sometime the compiler will add 4 additional padding bytes for the int... Anyways memcpy is on the spotlight and it's a generic function that can be used to copy the values of num bytes from the location pointed by source directly to the memory block pointed by destination ., void * memcpy ( void * destination, const void * source, size_t num );   You can use it to copy char buffers, arrays, structs or any other memory. This is a fast operation and should be used in performance oriented programs instead of assignment. The following example illustrates it's usage pointing out that you can't really use p