在ubuntu 上使用virtualbox 的usb

文章还是美帝的好用

https://help.ubuntu.com/community/VirtualBox/USB

这篇文章还为懒人准备了脚本

总结下无法开启usb问题所在

ubuntu的源中 virtualbox是ose的
就是 open source edition

而 ose 是不支持 usb的 不管你怎么折腾 也是无法开启usb的

解决方法就是 从官方网站 装一个 non-free的版本

http://www.virtualbox.org/wiki/Linux_Downloads

装完后将
将 自己 加入 vboxusers 组

1
 if [ "`grep vboxusers /etc/group|grep $USER`" == "" ] ; then sudo usermod -G vboxusers -a $USER ; fi

vboxusers 的 gid 对usb的 读写 加到 /etc/fstab
原理就是在 fstab加一个
none /proc/bus/usb usbfs devgid= vboxusers 组的id ,devmode=664 0 0

none /proc/bus/usb usbfs devgid=124,devmode=664 0 0

美帝还为懒人准备的脚本

1
2
3
4
5
6
7
8
9
10
#Enter a root shell, eg
 sudo -i

# In that shell, set up /etc/fstab

 vGid="`grep vboxusers /etc/group|cut -d\: -f3`" # Determine the devgid for the vboxusers group
 if [ "$vGid" ] && [ "`grep usbfs /etc/fstab`" == "" ] ; then
        echo "none /proc/bus/usb usbfs devgid=${vGid},devmode=664 0 0" >>/etc/fstab
        mount -a
 fi
Read More

apue.h ……

书上代码都有这个
这个文件在书的附录里边

我无法理解作者为什么这么作
他自己的解释是 环保 节约纸张

还好 这个有下载

http://www.apuebook.com/

apue.h 在 include目录

http://www.apuebook.com/src.tar.gz

这里还包含了书中的代码

Read More

git hub 基础帮助

新手……帮助的一个副本

Global setup:

Download and install Git
git config –global user.name “Your Name”
git config –global user.email farmer1992@gmail.com

Next steps:

mkdir another-test
cd another-test
git init
touch README
git add README
git commit -m ‘first commit’
git remote add origin git@github.com:tg123/another-test.git
git push origin master

Existing Git Repo?

cd existing_git_repo
git remote add origin git@github.com:tg123/another-test.git
git push origin master

Importing a Subversion Repo?

Click here

When you’re done:

Continue

Read More

Apache配置引起的IE6下载zip损坏

今天遇到一个奇怪的问题
IE6 下载的zip包 无法打开
Firefox没问题

QA姐姐用非常变态的 IE6 浏览器
我开始还不相信 后来自己尝试了以下 果然有这个问题

IE 果然是神级浏览器
突然发现 损坏的压缩包 可以用7z打开
进一步发现 损坏的压缩包 是一个 .gz 文件

一切就清晰了
原来IE6有bug

apache中配置了
SetOutputFilter DEFLATE
这个 引起了下载问题

改为
AddOutputFilterByType DEFLATE text/html text/plain text/xml
问题解决

Read More

入门级别linux socket 通信

linux 进程间通讯 第一步

主要是参考 http://beej.us/guide/bgipc/ 写出来的
国人写的基本全是转载 不是代码残疾 就是根本看不懂的……广告

整理下 g++编译

Server.cpp

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
44
#include <iostream>
using namespace std;

#include <sys/socket.h>
#include <sys/un.h>

const int MAX_RECV = 500;

int main(int argc, char ** argv){

    sockaddr_un server; // sockaddr_un 表示使用socket文件 参考 sockaddr_in

    server.sun_family = AF_UNIX;
    strcpy(server.sun_path, "test.socket");
    unlink(server.sun_path); // 绑定之前 清理掉 

    int s = socket(AF_UNIX, SOCK_STREAM, 0);

    bind(s , (sockaddr *) &server, sizeof(server));

    listen(s, 5);
   
    for(;;){
        cout<<"Wating"<<endl;

        sockaddr_un client;
        socklen_t client_len = sizeof(client);

        int c = accept(s, (sockaddr *) &client, &client_len);
        cout<<"Connected " <<endl;

        char buf[MAX_RECV];
        int len;

        while( (len = recv(c, &buf, MAX_RECV, 0)) >0 ){
            // 处理buf

            cout <<"Client Says:" << buf <<endl;
            send(c, buf, len, 0); //写入client
        }
    }

    return 0;
}

client.cpp

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
#include <iostream>
using namespace std;

#include <sys/socket.h>
#include <sys/un.h>

const int MAX_RECV = 500;

int main(int argc, char ** argv){
   
    sockaddr_un server; // sockaddr_un 表示使用socket文件 参考 sockaddr_in

    server.sun_family = AF_UNIX;
    strcpy(server.sun_path, "test.socket");

    int s = socket(AF_UNIX, SOCK_STREAM, 0);

    connect(s, (sockaddr *) &server, sizeof(server));

    char str[MAX_RECV];
    char buf[MAX_RECV];

    while(cin>>str){
        send(s, str, sizeof(str), 0);

        if( recv(s, &buf, MAX_RECV, 0) >0 ){
            // 处理buf
            cout << "Server Say:" << buf <<endl;
        }

    }
    return 0;
}

Makefile

1
2
3
4
5
6
7
all: server client
   
server: server.cpp
    g++ -o server server.cpp

client: client.cpp
    g++ -o client client.cpp
Read More

Mac Windows Linux 爱好者眼中的对方

Read More

Teamspeak 3 来了!

Teamspeak 时我一直关注的产品
不过 那是很久一起钱的事情了

那时候 我当团长 …… 在ts上
这个项目开发 有 5年了把
终于出来了

beta下载支持 linux windows 和 mac
我最喜欢这样的软件了

Read More

编写python c++ 扩展 (ubuntu下)

python 的c++扩展编写 比 php简单很多

phpize 也不是很好用的一个东西

编写一个 python mod hello world

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "Python.h"

PyObject* hello(PyObject* self, PyObject* args){
    const char * str;
   
    if (! PyArg_ParseTuple(args, "s", &str))
        return NULL;

   
    return Py_BuildValue("s",str);
}



static PyMethodDef helloMethods[] =
{
    {"hello", hello, METH_VARARGS, "hello comments"},
    {NULL, NULL, 0, NULL}

};

PyMODINIT_FUNC inithello(void){
    Py_InitModule("hello", helloMethods);
}

一个Python mod 因该有几个部分
1 扩展函数 hello
PyObject* hello(PyObject* self, PyObject* args){
只能是这样的结构
PyArg_ParseTuple 处理参数

2 函数列表 helloMethods
static PyMethodDef helloMethods

3 初始化函数 inithello
init函数名

编译
在 ubuntu 下需要安装python-dev
sudo apt-get install python-dev

yum服务器上应该是
python-devel

1
2
3
4
5
6
7
8
9
10
all: hello.so

hello.so: hello.o
    g++ -shared hello.o -o hello.so

hello.o: hello.cpp
    g++ -fPIC -c -I /usr/include/python2.6/ -o hello.o hello.cpp

clean:
    rm -f hello.o hello.so

使用
写一个 test.py

1
2
3
4
5
#!/usr/bin/env python

import hello

print hello.hello('world')

python 运行时候 会加载当前目录的.so

Read More