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

Mastodon