🌓

Windows下使用Hexo的一个坑

楔子

Hexo很好很强大 我很喜欢 但用的时候也遇到一些问题 今天这个是我觉得比较恶心的

背景

我一直在Windows下用Emacs写Hexo 上传到运行Debian的服务器(VPS)上

而Windows嘛 一个特性是文件系统大小写不敏感 *nix系列的系统大小写是分的很清楚的

我在新建(hexo new)的时候输入的标题是Different Coding for Chinese 这样新建出来的文件名是Different-Coding-for-Chinese.md generate deploy 都没问题 但我偶然发现这和其他的命名规则不一样 于是 我直接把文件名改成了只有首字母大写的形式 麻烦来了 本地测试的时候一点问题都没有 但跑到服务器上就无法正常打开 我怀有是Nginx的配置文件有问题 因为昨晚为了这个东东折腾了半个晚上 于是又尝试在配置文件上找毛病 可找来找去 就这几行 能有啥毛病

不知道是脑子想什么了 我突然想到 会不会是大小写的问题呢 于是 我hexo clean后又生成 上传 毛病就没有了 因为这时候删除重新生成纠正了目录大小写不一致的问题

阅读全文

不同编码(GB2312, UTF-8, UTF-16)下中文内容的占用大小的区别

楔子

有一次 一个人问 有什么编码能使用一个字节存储中文 当然 结果是否定的 中文没法做到一个字节存储

可是 如果是压缩呢 于是有此测试

结果

直接放结果 数据单位是字节

文章 (中文/全部字数)/编码 GB2312 UTF-16注1 UTF-8注2 GZIPed UTF-16 GZIPed UTF-8
Wiki的【量子力学】词条的源码 (13135/32873) 43,782注3 66,436 59,111 27,491 27,282
《共产党宣言》 (30352/35993) 62,594 64,634 92,670 32,554 38,593

注1 UTF-16-LE-DOS 这也就是Windows记事本的Unicode保存出来的编码
注2 UTF-8-UNIX
注3 此编码缺一些繁体字,用相应的简化字代替。

阅读全文

生成指定格式的数字序列

问题描述

写论文的时候需要插入引用文献 如果手写的话 如何快速生成类似下面样子是序列?

1
2
3
[1] 
[2]
[3]

Emacs Lisp

1
(loop for i from 1 to 10 do (insert (format "[%d] \n" i)))

一行解决问题 这是我以前经常用的

阅读全文

谁还是火狐(Firefox)用户 一个知乎用户的搞笑回答

出处

我就明确的告诉你。

你们啊,我感觉你们这些Chrome的用户还要学习,你们非常熟悉西方的那几个浏览器。

你们毕竟图样,你明白我的意思吗?

阅读全文

多语言(Batch, BASH, Octave, Emacs Lisp, ..)批量处理文件

楔子

有人提了一个问题 如何用C语言编程实现批量处理一个目录里面的所有文件 想起我自己也做过类似的事 就把自己的解决方案分享出来 写完觉得不过瘾 总结一下我的实现方案

以下的方案牵扯可执行文件的时候 都假设这个文件名字是a 读取一个参数进行处理 后面有些只是实现了列举 简单总结一下而已

Batch

1
for /f "delims=" %%i in ('"dir /b *.txt"') do a.exe %%i

我很不喜欢Batch 觉得语法好恶心 但百度一下还是能写出来 要点是 dir/b参数实现只输出文件名 完美解决

阅读全文

两个Emacs函数用于新建和发布Hexo网站

先发出来 慢慢完善

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(defun hexo-deploy (dir)
"Deploy hexo site.
If called with a prefix argument, the user is asked for directory of
the site. Otherwise, the directory is guessed from
`default-directory'."
(interactive (list (if current-prefix-arg
(file-name-as-directory
(read-directory-name "Hexo site directory: "
default-directory))
default-directory)))
(let ((old-dir default-directory))
(if (file-exists-p (concat dir "db.json"))
(progn
(setq default-directory dir)
(start-process "hexo-deploy" "*Hexo Deploy Output*" "hexo" "d" "-g")
(setq default-directory old-dir))
(progn
(if (file-exists-p (expand-file-name
(concat old-dir "../../db.json")))
(progn
(setq default-directory (expand-file-name
(concat old-dir "../../")))
(start-process "hexo-deploy"
"*Hexo Deploy Output*" "hexo" "d" "-g")
(setq default-directory old-dir))
(error "Hexo deploy failed. Wrong directory?"))))))

(defun hexo-wait-and-visit (proc max)
"Use timer to wait hexo process finish then visit the created file."
(if (eq (process-status proc) 'exit)
;; Exit normally.
(let ((hexo-buffer (process-buffer proc)))
(set-buffer hexo-buffer)
(goto-char (point-min))
(if (search-forward "File created at " nil t 1)
(progn
(find-file (buffer-substring-no-properties (point) (line-end-position)))
(kill-buffer hexo-buffer))))
(when (< max 5)
(run-with-timer 1 nil `(lambda () (funcall 'hexo-wait-and-visit ,proc ,(1+ max)))))))

(defun hexo-new (dir type title)
"Create an hexo draft/page/photo/post/.
If called with a prefix argument, the user is asked for type of the
created item. By default, `tpye' is post."
(interactive
(list (file-name-as-directory
(read-directory-name "Hexo site directory: "
default-directory))
(if current-prefix-arg
(read-string "Type to create: " "post" nil "post")
"post")
(read-string "title: ")))
(let ((old-dir default-directory))
(if (and (file-exists-p (concat dir "db.json"))
title)
(progn
(setq default-directory dir)
(hexo-wait-and-visit (start-process "hexo-new" "*Hexo New Output*" "hexo" "n" type title) 0)
(setq default-directory old-dir)
)
(error "Input directory is wrong."))))

阅读全文

理解Emacs lisp里的(interactive)

以前对(interactive)理解不深,只知道给函数加这个表示它可以被交互调用,但今天为了实现在Emacs里操作Hexo,借鉴了一下Magit的代码,发现原来里面的道道真不少,简单写写。

1
2
3
4
5
6
7
8
(defun get-dir (dir)
"This function can be called non-interactively and interactively."
(interactive (list (if current-prefix-arg
(file-name-as-directory
(read-directory-name "A directory: "
default-directory))
default-directory)))
(print dir))

上面的定义的函数有三种调用方式:

  • 在Lisp程序里调用,比如(get-dir "/tmp")
  • 交互式调用,比如M-x get-dir
  • 带参数交互式调用,比如C-u M-x get-dir

这种方式灵活性更大,而且还可以用下面的方法判断多个前缀。

阅读全文

Firefox 35.0中使用新的直角主题

开启方法

  • 进入about:config 找到browser.devedition.theme.enabled
  • 设置为true
  • 我这里开启后默认是暗色主题 如果不是或者不喜欢 设置devtools.theme dark是暗色 light是浅色

阅读全文

批量激活的Windows 8无法免费升级到Windows 10

本来听到Windows 10可以从Win7/Win8系列免费升级的时候我还是有点期待的 但马上传出消息 批量授权版不在此优惠之列 也就是说我没法享受免费升级了(我所在的学校购买了版权 所以我用的Windows是正版) 立马使用Windows 10的心凉了半截

其实凉了也好 鲁迅先生说 「长歌当哭 是必须在痛定之后的」 Windows 10目前还处于消费者预览阶段 相当于公测 而Windows是专有的商业软件 试用它 就相当于给微软当义务的软件测试员 帮微软挣钱 虽说我能早享受新系统 但也要忍受系统不成熟带来的风险 总的来看 微软赚的多 我收获小 还是不用的好

阅读全文

Firefox中用Base64编码分享小秘密

以前写过 但找不到了 现在记录一下

Base64 具体自行谷歌/百度罢 编码(Encode)和解码(Decode)在Firefox下可以这样

  • 打开ScratchPad(快捷键Shift+F4)或者开发者工具(快捷键F12)
  • 输入下面的代码 执行 输入你的内容

阅读全文