DOS命令sqlite3 中文乱码解决

在dos中使用sqlite3进行操作,由于dos窗口默认的是GBK编码,而sqlite通常为UTF-8,因此会出现sqlite中的中文字符在dos窗口中显示的是乱码的问题。

打开dos窗口,输入chcp 65001然后回车;注:65001即为UTF-8格式,936是GBK;

对着dos窗口的标题右键,在弹出来的窗口中选择属性,在弹出的窗口中将字体更改为:Lucida Console

 

Anconda 安装psycopg2

环境:Ubuntu 12.04,  Anaconda-1.9.2-Linux-x86_64

首先安装binstar

conda install binstar

然后使用binstar搜索psycopg2的网上安装路径

binstar search -t conda psycopg2
Run ‘binstar show <USER/PACKAGE>’ to get more details:
Packages:
Name | Access | Package Types | Summary
————————- | ———— | ————— | ——————–
auto/psycopg2database | published | conda | http://jimmyg.org/work/code/psycopg2databa se/index.html
bencpeters/psycopg2 | public | conda | Python-PostgreSQL Database Adapter
chuongdo/psycopg2 | public | conda | Python-PostgreSQL Database Adapter
dan_blanchard/psycopg2 | public | conda | http://initd.org/psycopg/
davidbgonzalez/psycopg2 | public | conda | None
deric/psycopg2 | public | conda | None
jonrowland/psycopg2 | public | conda | None
kevincal/psycopg2 | published | conda |
topper/psycopg2-windows | public | conda | PostgreSQL adapter for the Python programm ing language
trent/psycopg2 | public | conda | None
Found 10 packages

可知其中一个路径为bencpeters/psycopg2

安装如下:

 conda install -c https://conda.binstar.org/bencpeters psycopg2
Fetching package metadata: .Error: unknown host: http://repo.continuum.io/pkgs/pro/linux-64/
.Error: unknown host: http://repo.continuum.io/pkgs/free/linux-64/
.
Solving package specifications: .
Package plan for installation in environment /home/jerry/anaconda:

The following packages will be downloaded:

package | build
—————————|—————–
psycopg2-2.5.3 | py27_0 393 KB

The following packages will be linked:

package | build
—————————|—————–
psycopg2-2.5.3 | py27_0 hard-link

Proceed ([y]/n)? y

Fetching packages …
psycopg2-2.5.3-py27_0.tar.bz2 28% |#######################

ubuntu启用cron 服务的日志

环境: Ubuntu 12.04

 

修改rsyslog文件,将/etc/rsyslog.d/50-default.conf 文件中的#cron.*前的#删掉;
重启rsyslog服务service rsyslog restart;
重启cron服务service cron restart;

more /var/log/cron.log

增加定时任务:

sudo crontab -e

50 * * * * . $HOME/.bashrc;$HOME/get_wealth.py >/dev/null 2>&1

Thunderbird 安装importexporttool

环境:windows 7,  Thunderbird 31.3.0

由于需要使用邮件的内容来做NLP,因此需要导出并预处理。对于Thunderbird,需要安装importexporttool。

本地安装:

从https://addons.mozilla.org/zh-cn/thunderbird/addon/importexporttools/下载这个工具,然后到点击Thunderbird中的“附加组件”进入“附加组件管理器”,右上角有一个齿轮按钮。单击出现”从文件安装附加组件(I)…”,安装即可。

使用Thunderbird就出“以 mbox/eml格式导入或导出”的选项

 

Matlab 线性回归的向量化

环境: Ubuntu 12.04, Matlab 2013

数据如下:

jerry@hq:~/ml-class/mlclass-ex1$ more ex1data1.txt
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12
6.4862,6.5987
5.0546,3.8166
5.7107,3.2522
14.164,15.505
5.734,3.1551
8.4084,7.2258
……

 

做一个线性回归,用梯度下降方法,代码如下:

matlab -nodesktop

data = load(‘ex1data1.txt’);
X = data(:, 1), y = data(:, 2);
m = length(y);
X = [ones(m, 1), X];
theta = zeros(size(data, 2), 1);

for i = 1:1500
htheta = X * theta;
theta = theta – (0.01 / m * sum(repmat((htheta – y), 1, 2) .* X, 1))’;
end

 

另一种简洁的方法如下:

inv(X’ * X) * X’ * y