From Octopress To Hexo

It’s been a long time, Octopress is slow and painful to setup, after the death of my silly hard drive, I’m too lazy so I give up setting a Octopress environment, even writing new posts.

Eventually, I’m levaing, heading for Hexo.

What’s Hexo?

Hexo is a fast, simple and powerful blog framework. It parses your posts with Markdown or other render engine and generates static files with the beautiful theme. All of these just take seconds.

Why?

  • Painless installing
  • Cleaner documentation
  • Simple configuration
  • Fast generating, deploying
  • Easy customization
  • Actively maintained

双轴倾角传感器计算坡度

令 $x$ 轴, $y$ 轴上的转角分别为 $\alpha, \beta$, 平面坡度为 $\theta$, 则:

$$ \begin{align} \theta = \arccos({ \frac {1} {\sqrt{ \tan^2{\alpha} + \tan^2{\beta} + 1 }} }) \end{align} $$

最近拿了个双轴倾角传感器玩玩,把公式和示例代码记下来备忘。

推导过程就省略了,下面是C语言描述的示例代码,其中 calc_gradient_from_pitch_roll() 函数的参数和返回值都是弧度

坡度计算示例代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <math.h>


#define MATH_PI (3.14159f)

#define DEGREES_TO_RADIANS(angle) ((angle) * ((MATH_PI) / 180.0f))
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0f / (MATH_PI)))


float calc_gradient_from_pitch_roll(float pitch, float roll)
{

float tan_pitch = tan(pitch);
float tan_roll = tan(roll);

return acos(1.0f / sqrt(tan_pitch * tan_pitch + tan_roll * tan_roll + 1.0f));
}

// Test
int main(int argc, const char *argv[])
{

for (;;) {
float deg_pitch, deg_roll;
printf("(in degress) pitch,roll = ");
int ret = scanf("%f,%f", &deg_pitch, &deg_roll);

if (ret == 2) {
float pitch = DEGREES_TO_RADIANS(deg_pitch);
float roll = DEGREES_TO_RADIANS(deg_roll);
float gradient = calc_gradient_from_pitch_roll(pitch, roll);

printf("(in degress) gradient = %f\n", RADIANS_TO_DEGREES(gradient));
} else if (ret == EOF) {
break;
} else {
// Print error message and clear the input buffer
printf("Illegal input\n");
setbuf(stdin, NULL);
}
}

return 0;
}

Directory comparison for git difftool, with Beyond Compare 3

For a long time, I didn’t know a way to do directory comparison using git difftool command, extdiff extension from Mercurial did perform much more superior than Git.

Though it may be a bit out of date, I just found that after v1.7.11, Git now supports directory comparison through --dir-diff option, fantastic!

UPDATE 12/11/2012: You will need v1.8.0 version of msysgit installed, as noted by Scooter Software (Reference).

So here is a list of steps for me to make Beyond Compare 3 and Git directory comparison work under Windows.

First of all, Execute following commands in the Git Bash shell (or just modify your .gitconfig directly). You may need to change the folder where BCompare.exe resides.

1
2
3
git config --global diff.tool bc3
git config --global difftool.bc3.cmd "\"c:/Program Files/Beyond Compare 3/BCompare.exe\" \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

NOTE: Instead of bcomp.exe, use BCompare.exe, because I’ve found bcomp.exe returns too early, which will cause errors like this:

1
...Git/libexec/git-core\git-difftool line 444: Bad file number

Then make an alias for difftool:

1
git config --global alias.dt "difftool --dir-diff"

Now, you can use git dt to open Beyond Compare 3 for directory comparison in git repositories.

Workaround: Failed to import unicodedata in Sublime Text 2 under Windows

It’s weird, while importing some .pyd modules, like pyexpat, unicodedata in Windows version of Sublime Text 2, you will get ImportError, for example:

1
import unicodedata

Will result in:

1
Import Error: No module named unicodedata

However, since standard pyd modules are not missing, reside correctly in the same folder as sublime_text.exe, we can add that folder to sys.path in order to allow embedded python interpreter to load these modules:

1
sys.path.insert(os.path.dirname(sys.executable))

After that, you can import these standard python modules without pain, I hope it’s useful for Sublime Text 2 packages developers who met the same problem before.