利用 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

利用 hashcat 回忆(破解)遗忘的 Keepass 密码

本文环境:所有命令在 Kali Linux 下执行。

昨天的确是一个 tough day 。由于记性不好,四天前设置的 Keepass 主密码终于“如愿以偿”地被我遗忘了,而其中,保存了对于我来说极其重要的东西。16 位的密码中,我依稀地记得前 7 位和后 5 位“应该”、“似乎”是什么样子的,第十一位也记得,不过有些不确定。第八位我“幻想”出了一个答案。也就是说,我至少要再想出 2 位密码,至多则是 4 位,其中可能包含了大小写字母、数字,和特殊符号。

本着由易到难的想法,我先假定我模糊的记忆和幻想都是真实的。步骤是:先猜测 2 位,无果后,猜测 3 位,无果后,猜测 4 位。

出于减小范围的考虑,我先根据记忆筛掉完全不可能的字符,如没有穷举成功,方则使用全集。

本次操作有几个不确定因素:

  1. 我无法保证,已经记得的密码是绝对正确的。可能无功而返。

  2. 在减小范围时,我可能根据记忆错误地减掉了一些字符。

Read More

Mastodon