How to install VboxLinuxAdditions in Kali linux

在Kali中直接安装Vbox的增强工具是会报错的。这里记录下我当前的解决方案

首先,我们在Vbox中挂载增强工具。然后,打开它的目录,将VBoxLinuxAdditions.run拷贝到一个地方,例如download下。
第二部,赋予755权限。

1
chmod 755 VBoxLinuxAdditions.run

然后执行这个文件。

1
./VBoxLinuxAdditions.run

就能安装成功了。

Hexo博客搭建简单教程

近期想多点备份自己的笔记,就盯上了Github+Hexo这种博客模式。 我想Github的数据应该不可能丢失的。

准备阶段

你需要准备以下环境:

  • Git
  • Node.js
  • Github 账户

Git 环境准备

  1. 访问Git 官网下载安装包,一路Next
  2. 验证安装成功
    1
    git --version

推荐安装SourceTree用来管理git。

  1. 配置SSH 访问Github

Node.js 环境准备

  1. 访问Node.js 官网下载安装包,一路Next安装即可。
  2. 验证安装成功
    1
    2
    node -v
    npm -v

出现版本信息即为安装成功。

GitHub 账户准备

  1. 访问github,注册帐号
  2. 创建代码库New repository
    1) 在Repository name下填写yourname.github.io
    2) 创建
  3. 开启github page 功能
    1)点击界面右侧的Settings
    2)下拉至GitHub Pages,确认是否开启,未开启则开启

安装Hexo

到这一步,我们就可以安装Hexo了。

  1. 执行安装命令npm install hexo-cli -g
  2. npm install hexo --save
  3. hexo -v

初始化Hexo

接着上面的命令

  1. hexo init
  2. npm install
  3. 如果后面想用git部署,npm install hexo-deployer-git --save

启动Hexo

  1. 使用hexo g 生成静态页面
  2. 命令hexo s -p 4455,启动服务器,-p 4455设置端口,可以省略

使用Hexo

修改全局配置文件

参数 描述
title 网站标题
subtitle 网站副标题
description 网站描述
author 您的名字
language 网站使用的语言
timezone 网站时区。Hexo 默认使用您电脑的时区。时区列表。比如说:America/New_York, Japan, 和 UTC 。

部署Hexo

前面如果设置过SSH
直接执行命令

1
2
hexo g
hexo d

即可部署到github上。


利用Github分支备份Hexo博客源文件

场景

Hexo 部署博客很方便,我的这个博客也是用 Hexo 部署在 GitHub Pages 上的,有得人可能在多台电脑上写博客,这个时候需要把博客的源文件备份在一个地方,这样只需把博客源文件复制下来就可以在另一个地方写博客并部署到 GitHub Pages上了

本篇介绍的就是利用博客的 repo 分支( master 分支的必须用来存放你博客网站文件)托管 Hexo 源文件和配置达到备份的目的,下面开始正题:

  1. 把博客目录的源文件push到repo分支上
    1
    2
    3
    4
    git init
    git add .
    git commit -m "commit first time"
    git remote add origin https://github.com/your-name/your-name.github.io.git

接下来就是把Hexo源文件 push 上去,但是关键的地方到了,master上是 Hexo 生成博客网页的代码,而我们 Hexo 源文件是要 push 到一个分支上面的,所以接下来先要在 repo 上新建一个分支
新建一个叫做hexoSource的分支:

1
git branch blogSource

查看本地分支,并且切换到 blogSource 分支

1
2
git branch
git checkout blogSource

然后拉取远程代码,再把刚才添加的 Hexo 源文件代码 push 到blogSource这个分支:

1
2
git pull origin master
git push -u origin blogSource

然后就可以在 repo 上看到分支里面已经有博客的源文件了

只要维护你的md文件在分支里blogSource就可以了。


问题

  1. Q: hexo new page tags 页面内容为空
    开启/tags路由后,访问页面内容仅显示两个字:标签,HTML如下

标签

请问是什么原因?

另外,theme下的layout,category.ejs,tag.ejs是如何引用的?谢谢!

A: 发现主题目录下有一个[“_source”文件夹](它里面的内容正是about,categories,tags分别已写好的index.md)。复制到[Hexo根目录/source文件夹]内覆盖,就可以了。

Inheriting methods' docstrings in Python

This is a variation on Paul McGuire’s DocStringInheritor metaclass.

  1. It inherits a parent member’s docstring if the child member’s docstring is empty.
  2. It inherits a parent class docstring if the child class docstring is empty.
  3. It can inherit the docstring from any class in any of the base classes’s MROs, just like regular attribute inheritance.
  4. Unlike with a class decorator, the metaclass is inherited, so you only need to set the metaclass once in some top-level base class, and docstring inheritance will occur throughout your OOP hierarchy.
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import unittest
import sys

class DocStringInheritor(type):
"""
A variation on
http://groups.google.com/group/comp.lang.python/msg/26f7b4fcb4d66c95
by Paul McGuire
"""
def __new__(meta, name, bases, clsdict):
if not('__doc__' in clsdict and clsdict['__doc__']):
for mro_cls in (mro_cls for base in bases for mro_cls in base.mro()):
doc=mro_cls.__doc__
if doc:
clsdict['__doc__']=doc
break
for attr, attribute in clsdict.items():
if not attribute.__doc__:
for mro_cls in (mro_cls for base in bases for mro_cls in base.mro()
if hasattr(mro_cls, attr)):
doc=getattr(getattr(mro_cls,attr),'__doc__')
if doc:
if isinstance(attribute, property):
clsdict[attr] = property(attribute.fget, attribute.fset,
attribute.fdel, doc)
else:
attribute.__doc__ = doc
break
return type.__new__(meta, name, bases, clsdict)



class Test(unittest.TestCase):

def test_null(self):
class Foo(object):

def frobnicate(self): pass

class Bar(Foo, metaclass=DocStringInheritor):
pass

self.assertEqual(Bar.__doc__, object.__doc__)
self.assertEqual(Bar().__doc__, object.__doc__)
self.assertEqual(Bar.frobnicate.__doc__, None)

def test_inherit_from_parent(self):
class Foo(object):
'Foo'

def frobnicate(self):
'Frobnicate this gonk.'
class Bar(Foo, metaclass=DocStringInheritor):
pass
self.assertEqual(Foo.__doc__, 'Foo')
self.assertEqual(Foo().__doc__, 'Foo')
self.assertEqual(Bar.__doc__, 'Foo')
self.assertEqual(Bar().__doc__, 'Foo')
self.assertEqual(Bar.frobnicate.__doc__, 'Frobnicate this gonk.')

def test_inherit_from_mro(self):
class Foo(object):
'Foo'

def frobnicate(self):
'Frobnicate this gonk.'
class Bar(Foo):
pass

class Baz(Bar, metaclass=DocStringInheritor):
pass

self.assertEqual(Baz.__doc__, 'Foo')
self.assertEqual(Baz().__doc__, 'Foo')
self.assertEqual(Baz.frobnicate.__doc__, 'Frobnicate this gonk.')

def test_inherit_metaclass_(self):
class Foo(object):
'Foo'

def frobnicate(self):
'Frobnicate this gonk.'
class Bar(Foo, metaclass=DocStringInheritor):
pass

class Baz(Bar):
pass
self.assertEqual(Baz.__doc__, 'Foo')
self.assertEqual(Baz().__doc__, 'Foo')
self.assertEqual(Baz.frobnicate.__doc__, 'Frobnicate this gonk.')

def test_property(self):
class Foo(object):
@property
def frobnicate(self):
'Frobnicate this gonk.'
class Bar(Foo, metaclass=DocStringInheritor):
@property
def frobnicate(self): pass

self.assertEqual(Bar.frobnicate.__doc__, 'Frobnicate this gonk.')


if __name__ == '__main__':
sys.argv.insert(1, '--verbose')
unittest.main(argv=sys.argv)

This version supports multiple inheritance and copying the documentation from a base’s base by using mro instead of bases.

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
def fix_docs(cls):
"""
This will copy all the missing documentation for methods from the parent classes.

:param type cls: class to fix up.
:return type: the fixed class.
"""
for name, func in vars(cls).items():
if isinstance(func, types.FunctionType) and not func.__doc__:
for parent in cls.__bases__:
parfunc = getattr(parent, name, None)
if parfunc and getattr(parfunc, '__doc__', None):
func.__doc__ = parfunc.__doc__
break
elif isinstance(func, property) and not func.fget.__doc__:
for parent in cls.__bases__:
parprop = getattr(parent, name, None)
if parprop and getattr(parprop.fget, '__doc__', None):
newprop = property(fget=func.fget,
fset=func.fset,
fdel=func.fdel,
parprop.fget.__doc__)
setattr(cls, name, newprop)
break

return cls

Test:

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import pytest


class X(object):

def please_implement(self):
"""
I have a very thorough documentation
:return:
"""
raise NotImplementedError

@property
def speed(self):
"""
Current speed in knots/hour.
:return:
"""
return 0

@speed.setter
def speed(self, value):
"""

:param value:
:return:
"""
pass


class SpecialX(X):

def please_implement(self):
return True

@property
def speed(self):
return 10

@speed.setter
def speed(self, value):
self.sp = value


class VerySpecial(X):

def speed(self):
"""
The fastest speed in knots/hour.
:return: 100
"""
return 100

def please_implement(self):
"""
I have my own words!
:return bool: Always false.
"""
return False

def not_inherited(self):
"""
Look at all these words!
:return:
"""


class A(object):

def please_implement(self):
"""
This doc is not used because X is resolved first in the MRO.
:return:
"""
pass


class B(A):
pass


class HasNoWords(SpecialX, B):
def please_implement(self):
return True

@property
def speed(self):
return 10

@speed.setter
def speed(self, value):
self.sp = value


def test_class_does_not_inhirit_works():
fix_docs(X)


@pytest.mark.parametrize('clazz', [
SpecialX,
HasNoWords
])
def test_property_and_method_inherit(clazz):
x = fix_docs(clazz)
assert x.please_implement.__doc__ == """
I have a very thorough documentation
:return:
"""

assert x.speed.__doc__ == """
Current speed in knots/hour.
:return:
"""


def test_inherited_class_with_own_doc_is_not_overwritten():
x = fix_docs(VerySpecial)
assert x.please_implement.__doc__ == """
I have my own words!
:return bool: Always false.
"""

assert x.speed.__doc__ == """
The fastest speed in knots/hour.
:return: 100
"""