Windows下,以".py"为扩展名的Python程序可以双击运行,用起来很爽,现在玩go语言,我也想这么玩……
这里说说我的玩法。
示例代码(test.go):
package main import ( "fmt" "time" ) func main() { fmt.Println("Test") time.Sleep(time.Duration(6) * time.Second) }
Windows7 下,修改注册表:
路径:HKEY_CLASSES_ROOT\go_auto_file\shell\open\command

修改如下:
"c:\go\bin\go.exe" run "%1"

现在在Windows下双击即可运行。比如示例代码的双击后运行效果:

title为go.exe的路径
哈哈,搞定了……好,就这些了,希望对你有帮助。
经常用Python写demo来验证方案的可行性,最近遇到了Python访问SqlServer的问题,这里总结下。
一、Windows下配置Python访问Sqlserver
环境:Windows 7 + Sqlserver 2008
1、下载并安装pyodbc
下载地址:http://code.google.com/p/pyodbc/downloads/list
2、访问SqlServer
>>> import pyodbc
>>>cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.1.100\\sql;DATABASE=testDB;UID=sa;PWD=myPassword')
>>>cursor = cnxn.cursor()
>>>cursor.execute("select * from Tb")
二、Linux下配置Python访问SqlServer
环境:CentOS 6.2 + Sqlserver 2008
1、安装freetds:
yum install freetds*
2、安装pyodbc:
yum install pyodbc
修改odbc配置:
vi /etc/odbcinst.ini
添加FreeTDS驱动:
[SQL Server]
Description = FreeTDS ODBC driver for MSSQL
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
FileUsage = 1
3、测试
#python
>>> import pyodbc
>>>cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.1.100\\sql;DATABASE=testDB;UID=sa;PWD=myPassword')
>>>cursor = cnxn.cursor()
>>>cursor.execute("select * from Tb")
这里只是写了简单的demo来验证可行性,希望对你有帮助。
环境:CentOS6.2 + Asterisk 1.8.7.1
一、添加源文件
复制app_verbose.c为app_testApp.c
复制app_verbose.exports为app_testApp.exports
主要是修改一些标识,编译不会出错就行,这里列出我进行的主要修改。
1、添加头文件
#include "asterisk/cli.h"
2、修改变量
static char *app_testApp = "testApp"; static char *app_testApplog = "testAppLog";
3、在load_module中进行注册
res |= ast_register_application_xml(app_testApp, testApp_exec);
4、添加功能函数
static int testApp_exec(struct ast_channel *chan, const char *data) { ast_verb(2,"testApp_exec : %s\r\n",data); return0; }
5、添加cli调用接口
注册command:e->command = "testApp {print}";
调用command:
if (!strcasecmp(a->argv[1], "print")) {
testApp_exec(chan, a->argv[2]); }
6、在unload_module中进行反注册
res = ast_unregister_application(app_testApp);
二、编译并安装
asterisk -rx "core stop now" && make && make install && asterisk && asterisk -rvvvvvvvvvvvvv
三、测试
运行asterisk -rvvvvvvvv进入CLI模式
输入:core show help testApp
会输出帮助文档
输入:core show help testApp "something to test!"
会输出:something to test!

好,就这些了,希望对你有帮助。
将asterisk的呼叫记录存入mysql很简单,其实存入SqlServer也同样容易。
首先声明下环境:CentOS6.2 + Asterisk 1.8.7.1 + Freetds 0.91 + SqlServer 2008
1、安装rpmforge源和epel源
2、安装freetds:
yum install freetds*
3、配置并测试freetds
vi /etc/freetds.conf
示例如下:
ip:port模式:
[SQL2008] host = 172.16.16.100 port = 1433 tds version = 8.0
测试如下:
tsql -S SQL2008 -U sa -P password
数据库实例模式:
[voipCdrSvr] host = 172.16.16.101 instance = sqlexpress tds version = 8.0
测试如下:
tsql -S voipCdrSvr -U sa -P password
4、配置Asterisk
清空cdr_odbc.conf
> /etc/asterisk/cdr_odbc.conf
编辑cdr_tds.conf
vi /etc/asterisk/cdr_tds.conf
[global] connection=voipCdrSvr port=1433 dbname=myDB table=cdr user=sa password=myPasswd
5、创建Sqlserver数据表:
CREATE TABLE cdr ( [accountcode] [varchar] (20) NULL , [src] [varchar] (80) NULL , [dst] [varchar] (80) NULL , [dcontext] [varchar] (80) NULL , [clid] [varchar] (80) NULL , [channel] [varchar] (80) NULL , [dstchannel] [varchar] (80) NULL , [lastapp] [varchar] (80) NULL , [lastdata] [varchar] (80) NULL , [start] [datetime] NULL , [answer] [datetime] NULL , [end] [datetime] NULL , [duration] [int] NULL , [billsec] [int] NULL , [disposition] [varchar] (20) NULL , [amaflags] [varchar] (16) NULL , [uniqueid] [varchar] (150) NULL , [userfield] [varchar] (256) NULL )
6、重启Asterisk生效:
asterisk -rx "core restart now"
好,就这些了,希望对你有帮助。
用惯了Python,现在写C++的代码感觉有点不太顺畅。这不,今天就和这小小的raw_input较上劲了……
用过Python的朋友知道,Python中有个raw_input,可以如下使用:
print raw_input("Input a number : ")
一个函数内既有输入提示,又有返回值,用起来着实方便。可现在的问题是在C++中,我也想这么干,怎么办?其实,写一个函数也可以轻松实现的,比如:
int raw_input(const char* tips)
{
cout<<tips;
int a;
cin>>a;
return a;
}
这个是实现整型数据输入的函数:首先通过cout输出提示内容,比如“Input number :”之类的;接下来定义一个整型变量a,并通过cin获得数据的值;最后返回整型数据。可如下调用:
cout<<raw_input("Input number : ")<<endl;
功能是实现了,而且如果把类型改为string,和Python的就相同了。可我还是嫌这个不灵活:每个类型我都要写一遍,感觉很不爽,我想要一个比Python那个用起来更灵活的函数。标准库没有,就自己写吧……
这个要借助C++的模板来实现,示例如下:
template <class T1,class T2>
T1 raw_input2(T2 tips)
{
T1 a;
cout<<tips;
cin>>a;
return a;
}
这个和上面的原理一样,这里就不解释了。调用如下:
cout<<raw_input2<string,string>("Input string : ")<<endl;
哈哈,是不是方便多了。
好,就这些了,希望对你有帮助。