My technical memo
Category
 Computer and Internet (49)
 Programming (19)
 Mathematics (10)
 R (8)
 Bash (6)
 C++ (3)
 LaTeX (3)
 Syntax (2)
 武术 (2)
 Brain Teaser (1)
 CLRS (1)
 Complexity Analysis (1)
 Iteration (1)
 Mac (1)
 Markov Chain (1)
 Probability (1)
 Recursion (1)
 Spirituality (1)
Saturday, October 12, 2013
Sunday, December 30, 2012
How to keep ssh alive in terminal of Macbook
In macbook, I usually use ssh in terminal to connect to remote servers. However recently the terminal often becomes unresponsive after being idle for a while, then it prints the error "Write failed: Broken pipe" and quits the ssh connection.
The solution I found is to add the following line in ~/.ssh/config:
The solution I found is to add the following line in ~/.ssh/config:
ServerAliveInterval 120
How to install and link with the package "Geometric Tools" in Linux
Here is what I did to install and link with the package Geometric Tools:
 Download the package into your home directory and unzip it.
 Add the following line into ~/.bashrc, and run "sh ~/.bashrc" or log out and log in again.

Change to the directory GeometricTools/WildMagic5, and type
make CFG=Release f makefile.wm5
 To compile, we can use the following command
Sunday, December 9, 2012
How to correctly take square root in programming
If we simply call "sqrt()" function to take square root, very often we'll be caught by surprise.
The first common mistake is to not check negativity before taking square root. For example, Instead of getting 0.0 in both cases, one of the case will yield "nan". This is because y is actually not exactly \(\sqrt{2}\), but within machine precision of \(\sqrt{2}\). Therefore, we should always check negativity before taking square root.
You may notice that, in one of the above two cases, even if the answer is not "nan", the accuracy is quite poor, only within \(10^{8}\) of zero, rather than within machine precision of zero. This is because although \(y^2  2\) is within machine precision zero, after taking square root, you'll only get square root of machine precision. This is another common mistake.
So how do we take square root accurately and error free? Assume you want to compute \(x = \sqrt{2  y^2}\), you can do something like the following
The first common mistake is to not check negativity before taking square root. For example, Instead of getting 0.0 in both cases, one of the case will yield "nan". This is because y is actually not exactly \(\sqrt{2}\), but within machine precision of \(\sqrt{2}\). Therefore, we should always check negativity before taking square root.
You may notice that, in one of the above two cases, even if the answer is not "nan", the accuracy is quite poor, only within \(10^{8}\) of zero, rather than within machine precision of zero. This is because although \(y^2  2\) is within machine precision zero, after taking square root, you'll only get square root of machine precision. This is another common mistake.
So how do we take square root accurately and error free? Assume you want to compute \(x = \sqrt{2  y^2}\), you can do something like the following
Wednesday, December 5, 2012
Determine whether an ellipse intersect a horizontal or vertical line
Assume an ellipse of width \(\sigma\) and length \(\kappa \sigma\) is centered at \((x_0, y_0)\), and has angle \(\theta_0\) with the \(x\)axis. How do we determine whether it intersects a horizontal line or a vertical line?
It turns out the criteria is very simple
It turns out the criteria is very simple
 The ellipse intersects a horizontal line \(y = y_1\) if and only if the following equation hods: \[ \triangle_1 = \sigma^2 \left(\cos^2(\theta_0) + \kappa^2 \sin^2(\theta_0)\right)  (y_1y_0)^2 \geq 0 \]
 The ellipse intersects a vertical line \(x = x_1\) if and only if the following equation hods: \[ \triangle_2 = \sigma^2 \left(\sin^2(\theta_0) + \kappa^2 \cos^2(\theta_0)\right)  (x_1x_0)^2 \geq 0 \]
Sunday, October 28, 2012
How to make vim start faster remotely
I like to use "ssh Y" to log into my university's server to remotely submit computation jobs, and vim is my indispensible editor. However, even if vim is a command line editor, it still tries to load X server on start, and this can take a few seconds (on my MacBook Air). A simple solution is to add the following line in your ~/.bashrc (in your account at the server):
In this way, vim won't try to load X server and starts much faster.
In this way, vim won't try to load X server and starts much faster.
Wednesday, May 2, 2012
How to disable page forward/backward key in Thinkpad
It's a design flaw for Thinkpad to put page forward/backward together with the arrow keys. This frequently leads to loss of unpublished posts. This is what you can do in Ubuntu to disable those two keys:
 Create the file ~/.Xmodmap with the following contents
keycode 166= keycode 167=
 (Depending on your distribution, this step may not be necessary.)
Add the following code to your ~/.profile
# keyboard modifier if [ f $HOME/.Xmodmap ]; then /usr/bin/xmodmap $HOME/.Xmodmap fi
Subscribe to:
Posts (Atom)