Tuesday, January 3, 2017

ShadowSocks for ARM

From: http://briteming.blogspot.com/2013/05/shadowsocks-libev.html

shadowsocks-libev 1.2 作为第一个稳定版本发布。
shadowsocks-libev 是一个 shadowsocks 协议的轻量级实现,是 shadowsocks-android, shadowsocks-ios 以及 shadowsocks-openwrt 的上游项目。其具有以下特点:
1. 体积小巧。静态编译并打包后只有 100 KB。
2. 高并发。基于 libev 实现的异步 I/O,以及基于线程池的异步 DNS,同时连接数可上万。
3. 低资源占用。几乎不占用 CPU 资源,服务器端内存占用一般在 3MB 左右。
4. 跨平台。适用于所有常见硬件平台,已测试通过的包括 x86,ARM 和 MIPS。也适用于大部分 POSIX 的操作系统或平台,包括 Linux,OS X 和 Cygwin 等。
5. 协议及配置兼容。完全兼容 shadowsocks 协议,且兼容标准实现中的 JSON 风格配置文件,可与任意实现的 shadowsocks 客户端或服务端搭配使用。
shadowsocks-libev 包括服务端和客户端两部分,一共三个模块。
1. ss-server:服务器端,部署在远程服务器,提供 shadowsocks 服务。
2. ss-local:客户端,提供本地 socks5 协议代理。
3. ss-redir:客户端,提供本地透明代理,需要与 NAT 配合使用,具体使用方法参见文档。
在一台半公开的 shadowsocks 服务器上进行了数周的稳定性测试,随着负载的不断增大,shadowsocks-libev 依然保持着良好的状态。


Installation:

# git clone git://github.com/madeye/shadowsocks-libev.git

# cd  shadowsocks-libev

# ./configure

# make && make install (服务器端就编译好了)


usage:
ss-local -s server_host -p server_port -l local_port -k password -m encrypt_method -t 600 [-c config_file]
(这是在linux桌面系统下的用法)
 
ss-redir -s server_host -p server_port -l local_port -k password
       [-m encrypt_method] [-f pid_file] [-t timeout] [-c config_file]

ss-server -s server_host -p server_port -k password -m encrypt_method -t 600 [-c config_file] 
(此为linux vps上,所要运行的命令)

服务端

在安装服务端之前,需要先安装一些依赖库。 Ubuntu / Debain 环境下: sudo apt-get install build-essential autoconf libtool libssl-dev Redhat / CentOS 环境下: sudo yum install build-essential autoconf libtool gcc 编译安装: ./configure && make sudo make install 启动服务端,这里把下面的启动命令写入脚本中,每次只要执行脚本即可: nohup ss-server -s [Server IP] -p [Server Port] -k [Password] & 其他命令行说明可以参考官方说明

客户端

客户端这里推荐使用 shadowsocks-go,下载到相应系统的版本后,将配置文件中的内容修改好,改名为 config.json 运行主文件即可.


Saturday, July 23, 2016

变速器后拨调整

变速器的调整并不是车店师傅的专利,不嫌脏的车友只要动一动手就能解决变速器各类“不上不下”、跳齿及掉链的情况,只要注意变速器的主要事项,调教会变得十分轻松。
首先诊断车上变速器出问题的地方,除后拨调教问题外通常会有其他问题影响后拨变速的精准度。如果变速的手感变硬,出现“能上不能下的情况”(即向多齿数飞轮变速时,手感变硬,但变速没有问题,若退档的时候后拨反应迟钝的情况),通常是变速线管老化或污染缺油的信号。
如果没出现上述的问题,剩下的就是后拨的调教问题了,下面将详细讲解。
下图中的螺丝是调整后拨导轮相对于飞轮最小齿的限位螺丝,通常在螺丝附近会标注“H”的英文字母,代表高速“High”的意思。逆时针转动螺丝,导轮会越靠近外侧;顺时针转动螺丝,则导轮会靠近内侧。导轮的位置调整到与最小齿轮最外侧相互垂直为佳,可防止链条因为变速幅度过大掉入车架与飞轮之间的间隙中。
[简单教学]轻松学会后拨调教
下图中的螺丝是调整后拨导轮相对于飞轮最大齿的限位螺丝,通常在螺丝附近会标注“L”的英文字母,代表低速“LOW”的意思。逆时针转动螺丝,导轮会越靠近外侧;顺时针转动螺丝,则导轮会靠近内侧。导轮的位置调整到与最大齿轮相互垂直为佳,可防止链条因为变速幅度过大掉入辐条与飞轮之间的间隙中。
[简单教学]轻松学会后拨调教
下图中的螺丝是调整后拨导轮相间于飞轮间距的限位螺丝,通常独立一颗靠近后拨勾,因为变速时后拨张力的大小会影响变速的速度,理论上来说后拨导轮越靠近飞轮是最好的,但是靠得太近导轮与飞轮的变速齿会相互碰撞发出“咔咔”的响声。
[简单教学]轻松学会后拨调教
调整的间隙是导轮与飞轮最大齿相互平行5~6mm为佳。
[简单教学]轻松学会后拨调教
(图片来源于SHIMANO官网)

Tuesday, June 14, 2016

FIX Linux: apt-get update: Reading package lists... Error!

when apt-get update, get errors like:


Reading package lists... Error!W: There is no public key available for the following key IDs:1397BC53640DB551E: Encountered a section with no Package: headerE: Problem with MergeList /var/lib/apt/lists/packages.ros.org_ros_ubuntu_dists_trusty_main_i18n_Translation-enE: The package lists or status file could not be parsed or opened.



Solution:

sudo apt-get update
sudo rm /var/lib/apt/lists/* -vf

Terminator: how to get it start up with specified layout?

  1. After setting up your layout, right-click on any terminal background and choose Preferences→ Layouts tab and click on Add button.
  2. Give it a name and hit Close.
  3. This should create the mentioned ~/.config/terminator/config file.
  4. Now you can start terminator using the saved layout using: terminator -l yourLayout(replace yourLayout with whatever you chose on step 2).
  5. (optional) Edit the ~/.config/terminator/config file so that where it says [layouts]and nested below it [[yourLayout]], rename yourLayout to default and remove/rename the previous default layout. Now, when Terminator starts without any parameters, it will load your custom [[default]] layout!
use additional flags
  • -b for borderless and
  • -m for maximized.
The final Command is following terminator -m -b -l my_default.

Sunday, June 12, 2016

Catkin_make options - CMAKE_BUILD_TYPE

catkin_make is just a wrapper around CMake, so you can use the standard CMake variable CMAKE_BUILD_TYPE to enable various build options.
For a release configuration with opmizations and no debugging symbols, you can use the Release build type:
catkin_make -DCMAKE_BUILD_TYPE=Release
For a release with debug configuration, with optimizations and debug symbols, you can use theRelWithDebInfo build type:
catkin_make -DCMAKE_BUILD_TYPE=RelWithDebInfo
CMake's useful variables page gives more information about build types.
//========================================================================

CMAKE_BUILD_TYPE 
A variable which controls the type of build when using a single-configuration generator like the Makefile generator. CMake will create by default the following variables when using a single-configuration generator:
  • None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used)
  • Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG)
  • Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE)
  • RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO
  • MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)
You can use these default compilation flags (or modify them) by setting the CMAKE_BUILD_TYPE variable at configuration time from within the "ccmake" GUI. Note! The default values for these flags change with different compilers. If CMake does not know your compiler, the contents will be empty.

If you are using the Makefile generator, you can create your own build type like this:
SET(CMAKE_BUILD_TYPE distribution)
SET(CMAKE_CXX_FLAGS_DISTRIBUTION "-O3")
SET(CMAKE_C_FLAGS_DISTRIBUTION "-O3")


Note that CMAKE_BUILD_TYPE is not initialized with a readable value at configuration time. This is because the user is free to select a build type at build time. Use CMAKE_CFG_INTDIR if you need a variable that evaluates to the correct build time directory.

//========================================================================


It's generally best to do an "out of source" build. Create your CMakeLists.txt in the root of your project. Then from the root of your project:
mkdir Release
cd Release
cmake -DCMAKE_BUILD_TYPE=Release ..
make
And for Debug (again from the root of your project):
mkdir Debug
cd Debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
Debug will add the debug flags appropriate for your compiler. See this FAQ for more details.

You can modify/add to the flags in your CMakeLists.txt via CMAKE_C_FLAGS_DEBUG and CMAKE_C_FLAGS_RELEASE variables, e.g.:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
See this link under CMAKE_BUILD_TYPE for more details.
//========================================================================
> CMAKE_CXX_FLAGS_RELEASE and CMAKE_CXX_FLAGS_DEBUG are appended to 
> CMAKE_CXX_FLAGS if the buildtype is release or debug. 
>  
> Now let's say I'd like to have the following flags: 
> default: -Wall -fno-rtti -O2 -g  
> release: -Wall -fno-rtti -O2 
> debug:   -Wall -fno-rtti -O0 -g 
>  
> I can't set CMAKE_CXX_FLAGS to "-Wall -fno-rtti -O2" because the -O2 will 
> conflict with the -O0 for the debug build. 
> I would have expected either this behaviour: 
>  
> SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -fno-rtti -O2") 
> SET(CMAKE_CXX_FLAGS_DEBUG  "-Wall -fno-rtti -O0 -g") 
> SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti -O2 -g" )  
>  
> or: 
> SET(CMAKE_CXX_FLAGS_DEFAULT "-O2 -g") 
> SET(CMAKE_CXX_FLAGS_RELEASE "-O2") 
> SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g") 
> SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti" )  
>  
> But the special FLAGS are always appended to the general FLAGS and 
> (AFAIK) there is no such variable like CMAKE_CXX_FLAGS_DEFAULT. 
>  
> So, how is it intended to be used ? 

The default would never be used on a multi-configuration generator such 
as the Visual Studio or Xcode 2.x generators.  In a single-configuration 
generator the configuration is selected by CMAKE_BUILD_TYPE.  The 
problem is that this variable may be empty, but "no configuration" does 
not really make sense (but we've been living with it).  You could make 
it an error in your CMakeLists.txt file for CMAKE_BUILD_TYPE to be left 
empty, or just provide your own default setting.  The "default" options 
you are providing with "-O2 -g" is basically the "release with debug 
info" configuration we call RELWITHDEBINFO.  I suggest something like

# Set a default build type for single-configuration
# CMake generators if no build type is set.
IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
   SET(CMAKE_BUILD_TYPE RelWithDebInfo)
ENDIF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)

# Select flags.
SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")

//========================================================================

print out the value of building variables: 
message("CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}") message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}") message("CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}") message("CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}") message("CMAKE_CXX_FLAGS_MINSIZEREL is ${CMAKE_CXX_FLAGS_MINSIZEREL}") message("CMAKE_CXX_FLAGS_RELWITHDEBINFO is ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")

Friday, March 4, 2016

Latex-matrix

The matrix environments are matrixbmatrixBmatrixpmatrixvmatrixVmatrix, and smallmatrix. Each provides a table for expressions, aligned in rows and columns. The main difference between the various types of matrix is the kind of delimeters that surround them.
Each row of a matrix ends with two backslashes (\\). Each column ends with an ampersand (&).
The array environment has a required parameter that gives column specifications. Each column is represented by one letter which says whether the column is left-, center-, or right-aligned. In addition, vertical bars may be included in this specification to render vertical lines in the array.
The smallmatrix environment may be used inline so that the flow of text is not completely disrupted.
If horizontal or vertical lines inside the matrix or tighter control over column alignment are needed, the array environment can be used.
LaTeX markup......results in:...is used for:
\begin{matrix}
\alpha& \beta^{*}\\
\gamma^{*}& \delta
\end{matrix}
\begin{matrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{matrix}plain matrix
\begin{bmatrix}
. . .
\end{bmatrix}
\begin{bmatrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{bmatrix}bracketed matrix;
typically represents
the matrix itself
\begin{Bmatrix}
. . .
\end{Bmatrix}
\begin{Bmatrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{Bmatrix}braced matrix
\begin{pmatrix}
. . .
\end{pmatrix}
\begin{pmatrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{pmatrix}parenthesized matrix
\begin{vmatrix}
. . .
\end{vmatrix}
\begin{vmatrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{vmatrix}vertical bar matrix;
typically represents
the determinant
\begin{Vmatrix}
. . .
\end{Vmatrix}
\begin{Vmatrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{Vmatrix}double-vertical bar matrix
\begin{smallmatrix}
. . .
\end{smallmatrix}
\begin{smallmatrix}
                 \alpha&     \beta^{*}\\
                 \gamma^{*}& \delta
                 \end{smallmatrix}small matrix;
can be used inline

安装CTex常用中文字体


安装cTex需要的字体:
\songti 宋体: \songti,CJK 等价命令 \CJKfamily{song} 
\heiti 黑体: \heiti,CJK 等价命令 \CJKfamily{hei} 
\fangsong 仿宋: \fangsong,CJK 等价命令 \CJKfamily{fs} 
\kaishu 楷书: \kaishu,CJK 等价命令 \CJKfamily{kai} 
\lishu 隶书: \lishu,CJK 等价命令 \CJKfamily{li} 
\youyuan 幼圆: \youyuan,CJK 等价命令 \CJKfamily{you}

但是在Windows中的字体名称并不是和上述一致,大小写也有所区别。

Windows中字体名称如下:
宋体 SimSun
黑体 SimHei
仿宋 FangSong
楷体 KaiTi
隶书 LiSu
幼圆 YouYuan

可以通过修改ctex-xecjk-winfonts.def 文件来进行修正。CTex自动生成的文件路径为:
/usr/share/texlive/texmf-dist/tex/latex/ctex/fontset

可以用https://gist.github.com/lovelock/11339400 提供的配置文件覆盖你安装后自动生成的文件,前提是要安装好需要的字体,Windows的字体最好不要全部复制过来,装几个够用就好,不然会变得不伦不类。

在字体定义文件 ctex-xecjk-winfonts.def 中,楷体和仿宋不是使用字体全名,而是使用字体文件名表示的。如楷书是:
\setCJKfamilyfont{zhkai}{[simkai.ttf]}之所以这样是因为在 Windows XP 中楷书和仿宋是 GB_2313 字符集的,只有 6000 多个汉字,楷体字体全名是 KaiTi_GB2312;而在 Windows Vista 以后和版本则是 GBK 大字库的,有 20000 多个汉字,字体全名是 KaiTi。为了避免为微软的不同操作系统版本写不同的配置文件(这样更麻烦,而且 Windows 用户是大多数),就把它直接用没有变化过的字体文件名表示。
这个修改就是我做的。当然对于 Linux 用户可能有一些副作用。因为上面的字体名使用的是小写字母,而通常大家拷贝的字体是大写字母(这算是我的疏忽)。你知道 Windows 不区分文件名大小写,但 Linux 区分,所以当然 Linux 找不到 simsun.ttf 这个字体了。
我实在不建议 Linux 用户修改 ctex-xecjk-winfonts.def 文件。你可以使用 Windows 字体加上默认选项,但注意你安装的中文字体文件名要匹配。还有一个办法是写自己的配置文件,ctex 宏包有自己的 cfg 文件,在 .../texmf-dist/tex/latex/ctex/cfg/ctex.cfg 中,你可以在这个文件里面添加你自己的 local settings。