python 实现命令行参数 | KaiQ.Gu|KerwinKoo Blog

作者:JerryXia | 发表于 , 阅读 (0)
在终端中输入
vi -h或者
vi --help他们实现的功能是一样的,都是打印vi编辑器的帮助文档。python通过标准库getopt,对终端命令行参数进行解析,可以轻松达到以上效果。
代码举例:
12345678910111213141516171819202122import sysimport getopt__version__ = '1.0'if __name__ == '__main__':    longargs = ['version', 'help', 'file=', 'record=']    shortargs = 'vhf:'    opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs)    for opt, value in opts:        if opt in ('-v', '--version'):            print __version__        if opt in ('--help', '-h):            print 'this ...阅读全文

linux Daemon的C语言应用 | KaiQ.Gu|KerwinKoo Blog

作者:JerryXia | 发表于 , 阅读 (0)
实现需求:在终端机启动一个server,该Server在mips系统架构下不太稳定,在第一次启动和第一次连接Client时均会ACK退出。
实现一个守护进程,使该服务在此进程下启动,实现无论何种情况退出,均重启该server。
Update目前项目的该模块功能已实现,这里记录下实现过程。
主函数实现:12345678910#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <syslog.h>int main(void) {    daemon(1, 0);    start_server();    return 0;}需要执行的部分放在函数start_server()中实现。
123456789101112131415161718192021static void start_server() {    char server_cmd[64] = {0};    strcpy(server_cmd, SERVER_CMD);    for(;;)    {        int stat = 0;...阅读全文

Hello World | KaiQ.Gu|KerwinKoo Blog

作者:JerryXia | 发表于 , 阅读 (0)
Welcome to Hexo! This is your very first post. Check documentationfor more info. If you get any problems when using Hexo, you can find the answer in troubleshootingor you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"More info: Writing
Run server1$ hexo serverMore info: Server
Generate static files1$ hexo generateMore info: Generating
Deploy to remote sites1$ hexo deployMore info: Deployment
...阅读全文

Go Mysql Diver的简单使用 | KaiQ.Gu|KerwinKoo Blog

作者:JerryXia | 发表于 , 阅读 (0)
因为之前一直用Python进行服务器DB操作,这次转到Go访问MySql,中间遇到的几个坑这里填一下。
包的引用Golang对数据库的操作需要连接两个库,首先是Golang的DB基础库database,该库主要提供DB的基本操作支持,如CRUD、Prepared Statement及事务。其次需要Import针对具体库类型操作数据库驱动。mysql驱动库使用github提供的包:github.com/go-sql-driver/mysql
1234import ( "database/sql" _ "github.com/go-sql-driver/mysql")注意:通过引入空白倒入Mysql包(短横线-),完成数据库驱动注册。出现问题:failed to open database: sql: unknown driver "mysql" (forgotten import?)说明数据库驱动引用有误(上次出现这个问题是没有空白导入Mysql数据库驱动)。Go连接Mysql指定数据库 DSN[1]:
username:password@protocol(address)/dbn...阅读全文

为RaspberryPi2做BT下载工具aria2的交叉编译 | KaiQ.Gu|KerwinKoo Blog

作者:JerryXia | 发表于 , 阅读 (0)
0.下载aria2源码aria2源码共享在GitHub上,clone下来:
git clone https://github.com/tatsuhiro-t/aria2.git
截止本日志编写,可以看到github中有专门为Raspberry写的交叉编译环境,是一个 Dockerfile从这个文件中,可以看出该Docker镜像Build时需要做的工作:
step 1:1FROM ubuntu:trusty基础镜像为ubuntu:trusty.目前我使用 docloud的镜像加速服务, 因此ubuntu pull时还是蛮快的.
step 2:1234RUN apt-get update && \    apt-get install -y make binutils autoconf automake autotools-dev libtool \    pkg-config git curl dpkg-dev autopoint libcppunit-dev libxml2-dev \    libgcrypt11-dev lzip这里不难理解,ubuntu基础镜像安装完成后,...阅读全文