用 Emacs 分析日志文件

日常开发工作中,经常会需要分析日志文件,有一件趁手的工具会高效很多。

Emacs 正是这样一个工具。

Vim 也有类似的功能(参考 Vim Tips),但就分析日志来说,似乎没有 Emacs 来得方便。

统计 & 搜索

M-x count-matches 可输入正则表达式,统计正则匹配到的次数

经历八年后,我是如何用 Go 写 HTTP 服务的

今天读到一篇不错的文章,讲如何用 Go 写 HTTP 服务的,很有同感,翻译如下。

原文链接

A Server struct

一个 Server struct 是一个代表服务的对象,持有所有依赖。

每个组件都有一个唯一的 server struct,最后看起来通常类似这个样子:

Padding Oracle Attack

原理阐述

Padding

在密码学中,由于底层加密算法往往是针对固定长度的块来设计的(例如 AES 的 CBC 模式的块大小为 16),所以在对可变长度的明文进行加密时,一般需要额外增加 padding 字段来满足块对齐以便进行加密。

Create Ramdisk on macOS

Creating a 1000MB ramdisk:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ hdiutil attach -nomount ram://$((2048 * 1000))
/dev/disk3

$ diskutil eraseVolume HFS+ RAMDisk /dev/disk3
Started erase on disk3
Unmounting disk
Erasing
Initialized /dev/rdisk3 as a 1000 MB case-insensitive HFS Plus volume
Mounting disk
Finished erase on disk3 RAMDisk

$ hdiutil detach /dev/disk3

Linux Security Tips

ssh

Modify /etc/ssh/sshd_config:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Disable root login
PermitRootLogin no

# Change the default port
Port 12345

# Enable login with key
RSAAuthentication yes
PubkeyAuthentication yes

# Disable login with password
UsePAM no
PasswordAuthentication no

After that, remember to restart sshd: sudo /etc/init.d/ssh restart (for Debian/Ubuntu) or sudo service sshd restart (for CentOS).

iptables

Create the file /etc/iptables.test.rules, and enter rules: