使用pdftk进行分页和合并
1) 分页
pdftk full-pdf.pdf cat 12-15 output outfile_p12-15.pdf
pdftk full-pdf.pdf cat 1 2 5 output outfile_p1-2-5.pdf
2) 合并
pdftk file1.pdf file2.pdf cat output mergedfile.pdf
也支持正则表达式
pdftk P[01][0123456789]-s.pdf cat output P.pdf
2017年1月3日星期二
2016年6月15日星期三
Mac 配置 Eclipse gdb
Mac 下Eclipse C++默认采用gdb调试代码, 但是mac为支持自己的debugger, 不再默认安装gdb.
1) 安装gdb
https://www.gnu.org/software/gdb/
下载解压后:
./configure
make
sudo make install
安装后, which gdb显示/usr/local/bin/gdb
2) 配置gdb for eclipse
菜单 Eclipse --> Preferences --> C/C++ --> Debug --> GDB, 确保GDB debugger中选择的gdb路径正确.
3) 注册gdb
虽然上以设置gdb路径正确, 启动C++的debug模式, 会一直保留在 Launching : Configuring GDB Aborting configuring GDB
需要注册gdb, 注册方法 (http://stackoverflow.com/questions/19877047/eclipse-gdb-macosx-mavericks):
------------------
This means Eclipse can find the GDB now but cannot run it because of the Apple certificates issue.
To sign the GDB application and make it possible that Eclipse runs it follow the guide here:
https://sourceware.org/gdb/wiki/BuildingOnDarwin
which can be summarized in:
重新启动eclipse, debug成功.
1) 安装gdb
https://www.gnu.org/software/gdb/
下载解压后:
./configure
make
sudo make install
安装后, which gdb显示/usr/local/bin/gdb
2) 配置gdb for eclipse
菜单 Eclipse --> Preferences --> C/C++ --> Debug --> GDB, 确保GDB debugger中选择的gdb路径正确.
3) 注册gdb
虽然上以设置gdb路径正确, 启动C++的debug模式, 会一直保留在 Launching : Configuring GDB Aborting configuring GDB
需要注册gdb, 注册方法 (http://stackoverflow.com/questions/19877047/eclipse-gdb-macosx-mavericks):
------------------
This means Eclipse can find the GDB now but cannot run it because of the Apple certificates issue.
To sign the GDB application and make it possible that Eclipse runs it follow the guide here:
https://sourceware.org/gdb/wiki/BuildingOnDarwin
which can be summarized in:
- Start Keychain Access application (/Applications/Utilities/Keychain Access.app)
- Open menu /Keychain Access/Certificate Assistant/Create a Certificate (TOP MENU BAR)
- Choose a name (gdb-cert in the example) 3.1 Set "Identity Type" to "Self Signed Root" 3.2 Set "Certificate Type" to "Code Signing" 3.3 Check the flag "Let me override defaults" 3.4 Click several times on "Continue" until you get to the "Specify a Location For The Certificate screen" then set Keychain to "System" 3.5 If you can't store the certificate in the "System" keychain, create it in the "login" keychain, then export it. You can then import it into the "System" keychain. 3.6 Make sure you have the "gdb-cert" in your "System" (left top window)
- Select "Get Info" by pressing twice on the fresh made certificate (gdb-cert),
- Open the "Trus"t item, and set "Code Signing to Always Trust"
- Close Keychain Access application
- Restart "taskgated" application from activity monitor
$ codesign -s gdb-cert ../path of GDB
Example:$ codesign -s gdb-cert /usr/local/bin/gdb
------------------重新启动eclipse, debug成功.
2015年11月3日星期二
SSH免密码登录
机器A ssh 免密码登录到机器B (机器B ip: 192.168.131.173)
1)机器A命令行下运行:
ssh-keygen -t rsa (在机器A上创建.ssh/id_rsa和.ssh/id_rsa.pub文件, 需要多次回车完成)
ssh jhli@192.168.131.173 "mkdir .ssh;chmod 0700 .ssh" (在机器B上创建文件夹.ssh, 并修改权限. 可能会提示机器B上.ssh文件夹已存在)
scp ~/.ssh/id_rsa.pub jhli@192.168.131.173:.ssh/id_rsa.pub (把机器A上的id_rsa.pub文件拷贝至机器B)
2) 机器B命令行下运行:
touch ~/.ssh/authorized_keys (创建.ssh/authorized_keys文件, 如果此文人不存在)
chmod 600 ~/.ssh/authorized_keys (修改该文件权限)
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys (将.ssh/id_rsa.pub的内容追加到authorized_keys文件后)
3) 设置完成, 在机器A命令行下测试
ssh jhli@192.168.131.173
如果测试时提示"Agent admitted failure to sign using the key"错误, 在机器A运行如下命令后再测试.
ssh-add ~/.ssh/id_rsa
1)机器A命令行下运行:
ssh-keygen -t rsa (在机器A上创建.ssh/id_rsa和.ssh/id_rsa.pub文件, 需要多次回车完成)
ssh jhli@192.168.131.173 "mkdir .ssh;chmod 0700 .ssh" (在机器B上创建文件夹.ssh, 并修改权限. 可能会提示机器B上.ssh文件夹已存在)
scp ~/.ssh/id_rsa.pub jhli@192.168.131.173:.ssh/id_rsa.pub (把机器A上的id_rsa.pub文件拷贝至机器B)
2) 机器B命令行下运行:
touch ~/.ssh/authorized_keys (创建.ssh/authorized_keys文件, 如果此文人不存在)
chmod 600 ~/.ssh/authorized_keys (修改该文件权限)
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys (将.ssh/id_rsa.pub的内容追加到authorized_keys文件后)
3) 设置完成, 在机器A命令行下测试
ssh jhli@192.168.131.173
如果测试时提示"Agent admitted failure to sign using the key"错误, 在机器A运行如下命令后再测试.
ssh-add ~/.ssh/id_rsa
2015年7月14日星期二
linux下使用autoconf生成makefile文件 (--with-boost 和 其他第三方库)
准备好代码后, 可按以下步骤自动生成makefile文件
1) autoscan
1) autoscan
会生成一个文件configure.scan
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([util/tsuruoka_maxent.h])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([pow sqrt strchr strstr])
AC_CONFIG_FILES([util/maxent-3.0/Makefile])
AC_OUTPUT
2) 将configure.scan改为configure.in, 并修改其内容为:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_CONFIG_MACRO_DIR([m4])
AC_PREREQ([2.69])
AC_INIT([de-reorder], [1.0], [****@gmail.com])
AC_CONFIG_SRCDIR([src/de_reorder_model.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_LIBTOOL
# Checks for libraries.
BOOST_REQUIRE([1.44])
BOOST_PROGRAM_OPTIONS
AC_CHECK_HEADER(dlfcn.h,AC_DEFINE(HAVE_DLFCN_H))
AC_CHECK_LIB(dl, dlopen)
AC_CHECK_HEADERS(zlib.h,
AC_CHECK_LIB(z, gzread,[
AC_DEFINE(HAVE_ZLIB,[],[Do we have zlib])
ZLIBS="$ZLIBS -lz"
]))
AM_CONDITIONAL([HAVE_RAPIDJSON], false)
AC_ARG_WITH(rapidjson,
[AC_HELP_STRING([--with-rapidjson=DIR], [(required) path to rapidjson])],
[with_rapidjson=$withval],
[with_rapidjson=no]
)
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([pow sqrt strchr strstr])
#BOOST_THREADS
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
LDFLAGS="$LDFLAGS $BOOST_PROGRAM_OPTIONS_LDFLAGS"
# $BOOST_THREAD_LDFLAGS"
LIBS="$LIBS $BOOST_PROGRAM_OPTIONS_LIBS $ZLIBS"
# $BOOST_THREAD_LIBS"
AC_CONFIG_FILES([Makefile
src/Makefile
util/Makefile
util/maxent-3.0/Makefile])
AC_OUTPUT
说明:
a)
AC_CONFIG_MACRO_DIR([m4])
定义宏的文件夹
b)
AC_INIT([de-reorder], [1.0], [****@gmail.com])
AC_CONFIG_SRCDIR([src/de_reorder_model.cc])
版本信息
主程序的入口文件
c)
AM_INIT_AUTOMAKE
不清楚, 从其他地方复制过来
d)
# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_LIBTOOL
不是很清楚, 从其他地方复制过来的
e)
# Checks for libraries.
BOOST_REQUIRE([1.44])
BOOST_PROGRAM_OPTIONS
AC_CHECK_HEADER(dlfcn.h,AC_DEFINE(HAVE_DLFCN_H))
AC_CHECK_LIB(dl, dlopen)
AC_CHECK_HEADERS(zlib.h,
AC_CHECK_LIB(z, gzread,[
AC_DEFINE(HAVE_ZLIB,[],[Do we have zlib])
ZLIBS="$ZLIBS -lz"
]))
AM_CONDITIONAL([HAVE_RAPIDJSON], false)
AC_ARG_WITH(rapidjson,
[AC_HELP_STRING([--with-rapidjson=DIR], [(required) path to rapidjson])],
[with_rapidjson=$withval],
[with_rapidjson=no]
)
利用到的boost版本信息, 其中的宏BOOST_REQUIRE/BOOST_PROGRAM_OPTIONS等会在boost.m4中定义, boost.m4文件可以到网站上下载得到. *****新建m4文件夹, 并把boost.m4文件拷贝过去*****
由于该代码只用到BOOST_PROGRAM_OPTIONS, 所以这里只列到BOOST_PROGRAM_OPTIONS. 其他的选项还可以是:
BOOST_FILESYSTEM
BOOST_PROGRAM_OPTIONS
BOOST_SYSTEM
BOOST_REGEX
BOOST_SERIALIZATION
BOOST_TEST
BOOST_THREADS
这里还会用到第三方工具rapidjson, 可以通过--with-rapidjson指定其安装路径
f)
#BOOST_THREADS
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
LDFLAGS="$LDFLAGS $BOOST_PROGRAM_OPTIONS_LDFLAGS"
# $BOOST_THREAD_LDFLAGS"
LIBS="$LIBS $BOOST_PROGRAM_OPTIONS_LIBS $ZLIBS"
# $BOOST_THREAD_LIBS"
将boost的路径添加到CPPFLAGS宏. 同时将boost相关的lib添加到LIBS宏.
(也可以将rapidjson按类似的方法将其路径添加到CPPFLAGS中, 或者在相关的Makefile.am中添加也可以, 见下一步骤)
g)
AC_CONFIG_FILES([Makefile
src/Makefile
util/Makefile
util/maxent-3.0/Makefile])
待生成的多个makefile文件, 每个文件夹下均包含一个.
3) 为每个文件夹下准备Makefile.am文件
注意:根据需要,在Makefile.am下包含路径$(RAPIDJSON_CPPFLAGS), 如:
AM_CPPFLAGS = -W -Wall -I$(top_srcdir) -I$(top_srcdir)/util -I$(RAPIDJSON_CPPFLAGS)
如果该文件夹下的文件有使用到rapidjson库.
4) aclocal
5) autoreconf -ifv
这步会生成configure文件
6) ./configure --with-rapidjson=/path/to/rapidjson --with-boost=/path/to/boost
7) make
2015年6月23日星期二
linux下替换行末的^M
在Windows下编辑的文本在linux下查看时可能会出现^M字符. 可按下面命令在vim下替换掉。
%s/^M//g
"Press and hold control then press V then M" 2015年6月21日星期日
关于cdec运行出现connection timeout错误
查看~/cdec/training/utils/parallelize.pl, 将其host修改为下面形式.
#my $host = check_output("hostname");
my $host = check_output("ifconfig | grep -Eo 'inet (addr:)?([0-9]*\\.){3}[0-9]*' | grep -Eo '([0-9]*\\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1");
#my $host = check_output("hostname");
my $host = check_output("ifconfig | grep -Eo 'inet (addr:)?([0-9]*\\.){3}[0-9]*' | grep -Eo '([0-9]*\\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1");
订阅:
博文 (Atom)