Posts

Showing posts from February, 2014

How to setup a NAT server?

Image
How to setup an NAT server? Table of Contents What is NAT? How to setup NAT host? a shell script from vbird's book 1 What is NAT? NAT stands for Network Address Transition, which is the basic function of gateway host. I try to hack Bluetooth tethering module in android this week, it include the Bluetooth Pan profile and the NAT setup process, which means in order to implement the Bluetooth tethering, first, two devices must be connected by Bluetooth Pan profile, and then the server part device acted as gateway host to supply the network forward service. In other words, after Bluetooth Pan profile connected, the server must to setup its NAT rules to forward the IP packages. So how to setup NAT rules? 2 How to setup NAT host? My memory is still fresh that at the start of my Linux journey, I setup my Linux desktop as an NAT host to provide Internet services for my lab's classmates. During the days as a programmer, I once did a job to hacking android&

Async Networking in Android

Async Networking in Android (Deprecated, I never use those technology anymore.)  Table of Contents Background Source code examples 1 Background A few days ago, people ask me a question, How to write an application which has to download the resources from the network? or Let me narrow the scope, how to write an android app, which can download the images from the Internet with HTTP protocol and insert the image into a view container like a ListView. So, in this scenario, because the networking connections are always resources burden works, the solution is always put the heavy jobs into the background threads. Following is the equation to that problem. Threads + Cache + HttpClient I found three ways to met this equation after study that topic. Use AsyncTask(thread) directly, put the networking job into a background AsyncTask. Use ThreadPool, which is better than AsyncTask, especially in massive networking connection scenario. Use Volley library, which is advo

Practise Git

Image
Practise Git Table of Contents What's git? Daily Usage 1 What's git? Git, initially started by Linus, is a most advanced distributed version control system. The another kinds of version control system are centralized version control system, SVN is one of them. 2 Daily Usage you wanna stage a file git add file untrack(unstage) a file git reset HEAD file get a diff between staged area and unstaged area git diff get a diff between staged area and last commitment git diff --cached commit staged area into the repository git commit push to the last commitment into the remote repository git push [remote-name] [branch-name] git push [remote-name] [locale-branch]:[remote-branch] remove staged file git rm file # or git reset HEAD file rm file turn back to former status git checkout -- file get a list of all remote repository git remote -v add a remote repository git remote add [shortnam

A sort algorithm question from a job interview

Image
A sort algorithm question from a job interview Table of Contents Question My Answer After rethinking the question 1 Question Here we are, there is an abstract data type(ADT), which has two members - student number and student score, to represent a student, and there are a millions of the students and the score is ranged from 1 to 100 as integer, there is a container to store this ADT, maybe an array. So please tell me one student's position in this exam in the fastest way. 2 My Answer If you wanna design an algorithm, there are only two points, which you need to focus, space efficiency and time efficiency. They are a perpetual conflict, you can never achieve both space and time efficiency at the same time. Then after a silent break, yeah, I was thinking this question, I believe I gave the stupid answer, just iterate the whole container. Damn it. 3 After rethinking the question The interviewer gave me a hint to finding the most time efficient wa