MySQL 远程连接

凑巧学到了如何让 MySQL 或者 MariaDB 让远程用户连接的方法。

服务端

编辑配置文件:

1
vi /etc/mysql/my.cnf

做如下改动:

1
bind-address = 0.0.0.0

重启服务:

1
systemctl restart mysql

进入 mysql:

1
mysql -u root -p

给予权限:

1
2
3
use dbname;
update user set host='%' where user='root' AND host='localhost';
FLUSH PRIVILEGES;

客户端

1
mysql -u root -pyourpassword -h ipaddress -P port -D dbname

Read More

利用 jQuery 实现锚点平滑移动

记录一个用 jQuery 实现点击锚点链接后平滑移动的方法。

1
2
3
4
5
6
7
8
9
var $root = $('html, body');

$('a[href^="#"]').click(function () {
$root.animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);

return false;
});

如果想更新地址栏的话,就这样:

1
2
3
4
5
6
7
8
9
10
11
12
13
var $root = $('html, body');

$('a[href^="#"]').click(function() {
var href = $.attr(this, 'href');

$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});

return false;
});

Read More

网页锚点添加偏移

由于博客有一个顶部浮动菜单,这样点击锚点链接之后,菜单会遮住一部分锚点后的内容。为了解决这个问题需要让点击锚点后的位置有个偏移。可以使用 CSS 实现。

1
2
3
4
5
6
7
8
.headerlink:before {
content: "";
display: block;
visibility: hidden;
position: relative;
height: 80px;
margin-top: -80px;
}

Read More

Classify Wine Data with Libsvm in Matlab

This a simple example of the classification with Libsvm in Matlab.

You can download the wine data from here.

Data Preprocessing

Load the wine data , and save it to winedata

1
2
3
4
5
6
7
8
9
uiimport('wine.data');

wine_label = wine(:, 1);
wine_data = wine(:, 2:end);
categories = {'Alcohol'; 'Malic acid'; 'Ash'; 'Alcalinity of ash'; 'Magnesium'; 'Total phenols'; 'Flavanoids'; 'Nonflavanoid phenols'; 'Proanthocyanins'; 'Color intensitys'; 'Hue'; 'OD280/OD315 of diluted wines'; 'Proline'};
classnumber = 3;
save winedata.mat;

load winedata;

Show the box figure of test data

1
2
3
4
5
figure;
boxplot(wine_data, 'orientation', 'horizontal', 'labels', categories);
title('Wine Data Box Figure', 'FontSize',12);
xlabel('Attribute Value', 'FontSize', 12);
grid on;

Read More

Basic Uses of Libsvm in Matlab

System: Ubuntu with gcc installed

Libsvm Installation

1
2
3
cd libsvm-3.2/matlab
mex -setup
make

Just for Test

Load data

1
2
cd ../
load heart_scale

Result:

Error using load
Number of columns on line 3 of ASCII file heart_scale must be the same as previous lines.

Load data again and train model

1
2
3
[heart_scale_label, heart_scale_inst] = libsvmread('heart_scale');
cd matlab;
model = svmtrain(heart_scale_label, heart_scale_inst)

Result:

*
optimization finished, #iter = 162
nu = 0.431029
obj = -100.877288, rho = 0.424462
nSV = 132, nBSV = 107
Total nSV = 132

model = 

struct with fields:

  Parameters: [5×1 double]
  nr_class: 2
  totalSV: 132
    rho: 0.4245
    Label: [2×1 double]
  sv_indices: [132×1 double]
    ProbA: []
    ProbB: []
    nSV: [2×1 double]
  sv_coef: [132×1 double]
    SVs: [132×13 double]

Predict the data and show accuracy

1
[predict_label, accuracy, decision_values] = svmpredict(heart_scale_label, heart_scale_inst, model);

Result:

Accuracy = 86.6667% (234/270) (classification)

Read More

Mastodon