Weight your toys

I decide to write this post because this post reminds something about my weakness when dealing with algorithm problems.

Here’s the problem, I put it to gist.


How to abstract reality problems to sort problems, and how to take advantage of sort to find out things that interest us?

The code above, I want to use observer design pattern ( compare_event ). Yes that’s the part to emphasise that we always want to search things interest us, if not, why we search things? So that is the pattern of human beings, and I always decouple things when I find a point that fit normal brains.

Here is the steps that I always follow to create a solution:

  1. Understand them, feel them, and try to measure them. We always have a way to quantify things, though most people die here or find a really bad way to measure things.
  2. So we have convert states to numbers in the first step. We can use the numbers to compare two things.
  3. If I want to search something, I always search things while sort them. You always do the two things together, think about it when you are paring the socks from your washing machine. Even school child does it without thinking.
  4. I interpolate tasks while each comparison. Searching itself is also a task. Each task can access the current comparison result and process state.
  5. Choose a sort algorithm which fit the situation best
  6. Launch the whole process.


Git Daemon Two Common Mistakes

This is a powerful function introduced since git 1.7. The git will listen to a port and receive  incoming git protocol request. When we need to auto deploy project inside a private network, it is one of the easiest way to work with. It doesn’t depend on http or ssh, and much faster. Though it doesn’t support user authentication, it still a good solution for sharing code.

Two common mistake that the git documentation doesn’t mention:

  1. A white list path must be set.
    Something like this won’t work: 
  2. The white list path should be an absolute path or ‘./‘ prefixed.
    Something like below won’t work, the  test_repo should be prefixed:   ./test_repo , or use absolute path 

A simple correct example should be like below.

Then access your server by git push git://server_addr:8123/test_repo .

I wrote a simple shell function to help setup:


Circular list formula

This example, list length is 2 elem, mask length is 1 elem.
So the total item number should be 3 elem.
The total virtical offset should be 2 elem.

Distribute virtual disk mapping development

Most teams use the remote development technics to reduce the wasting of time when setup big projects’ complex environment. Normally, they use virtual disk mapping, such as samba server or sshfs. And then they map the remote disk to local directory. The final result is that everyone in the team will be happy to use their favorite tools to play with the project, and don’t need to worry about the product environment.

But these solutions all have a same disadvantage. They store the development files on the remote machine, which means if the network is bad or out of access, the development will be a painful tragedy.

Here I’d like to introduce my thought about the distribute virtual disk mapping development. In one word, we mapping in a reverse way. So if we simply virtual mapping out local disk to the remote machine this problem will be solved? Of course not. We still need network to connect to our development environment. So why not distribute the development machine as a virtual machine to every developer and lock the vm, only allow user mapping their own disk to his local vm. As the vm is solidified, so when can easily sync all virtual machines by script program, then use scm to manage these scripts.

We all know it’s better to store everything on the cheap, secure and safe cloud? But why GIT finally beat the SVN? Because we put to much trust on that the network is everywhere and fast enough. But on the contrary, the network is never good enough and if the cloud is down our only repo will disappear. So that’s why people want a copy to keep things more reliable.

Thoughts on naming convention

I heard a lot of voices saying that they want to make their coding style the same with the corresponding frameworks, so they study the ancestors’ codes and mimic the so called golden standards.

Keeping coding style the same with the framework is no wrong. But don’t lost your own voice when you are trying to follow other’s. 

I prefer my coding style being different from the framework that I’m using. One big advantage is that it will be much easier to distinguish which part of the codes is mine and which belongs to the API. For example, a mix of camelCase and underscore conventions:

If a new member comes to read this java snippet, he will find it useful to find the road map of this project. Sometimes I think a proper way to mix will make life easier, isn’t it?