笨熊之家

欢迎来到笨熊之家~

0%

昨天突然想尝试一下linux的桌面环境,正好手头有个树莓派,准备先在上面尝试一下,后来发现安装一些桌面环境时会提示缺失库函数之类的错误,折腾了许久也没能解决。于是决定下载一个VMWare,然后创建一个Ubuntu环境的虚拟机。

从官网下载安装包之后进行安装,由于软件需要付费使用,而我还没有经济能力,所以在网上找到了注册码进行激活。
注册码地址

配置完成后,在Ubuntu中文网站下载镜像,创建虚拟机。等待一段时间后,Ubuntu安装完成。

Read more »

阅读vimtutor时,进行到7.1处,文中提到

1
2
3
4
5
6
7
You can find help on just about any subject, by giving an argument to the
":help" command. Try these (don't forget pressing <ENTER>):

:help w
:help c_CTRL-D
:help insert-index
:help user-manual

输入:help w后提示
1
2
E434: Can't find tag pattern
Press ENTER or type command to continue

之后在上方新开窗口中出现乱码,无法正常阅读。
在网上寻找此类问题的解决方案,许多人说重新安装,不过我并不觉得重装是个好方法。网上关于这一问题的讨论还是有的,但大多并不能解决我的问题,直到我看到了在Google Groups的讨论。

其中James McCoy提到

Looks like your system ships with gzipped help files. When you run
vimtutor, plugins aren’t loaded. The gzip plugin is what normally
handles uncompressing the help files, but since it isn’t loaded Vim just
opens the compressed file and can’t find the tag to jump to.

他的意思是当使用vimtutor命令时,vim并不会加载gzip插件,而帮助文档是gzip格式的,所以在tutor中使用:help+tag时无法正常打开文件。
于是我使用vim TEST打开本地文件,尝试同样的命令,发现可以正常查看帮助文档。接着Christian Brabandt上传一个diff的附件,文件中显示了对vimtutor脚本的更改:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
diff -r 917ffa98aeeb src/vimtutor
--- a/src/vimtutor Wed Sep 09 22:45:04 2015 +0200
+++ b/src/vimtutor Mon Sep 14 09:01:01 2015 +0200
@@ -70,5 +70,5 @@
# The script tutor.vim tells Vim which file to copy
$VIM -f -u NONE -c 'so $VIMRUNTIME/tutor/tutor.vim'

-# Start vim without any .vimrc, set 'nocompatible'
-$VIM -f -u NONE -c "set nocp" $TUTORCOPY
+# Start vim without any .vimrc, set 'nocompatible' and load the gzip Plugin
+$VIM -f -u NONE -c "set nocp" -c 'ru plugin/gzip.vim' $TUTORCOPY
diff -r 917ffa98aeeb vimtutor.bat
--- a/vimtutor.bat Wed Sep 09 22:45:04 2015 +0200
+++ b/vimtutor.bat Mon Sep 14 09:01:01 2015 +0200
@@ -41,7 +41,7 @@
IF ERRORLEVEL 1 GOTO use_vim

:: Start gvim without any .vimrc, set 'nocompatible'
-start "dummy" /b /w gvim -u NONE -c "set nocp" %TUTORCOPY%
+start "dummy" /b /w gvim -u NONE -c "set nocp" -c "ru plugin/gzip.vim" %TUTORCOPY%

GOTO end

针对系统中的vimtutor脚本,我对应的做了修改,即上述修改中的:
1
2
3
4
-# Start vim without any .vimrc, set 'nocompatible'
-$VIM -f -u NONE -c "set nocp" $TUTORCOPY
+# Start vim without any .vimrc, set 'nocompatible' and load the gzip Plugin
+$VIM -f -u NONE -c "set nocp" -c 'ru plugin/gzip.vim' $TUTORCOPY

这里我并没有直接修改/usr/bin/vimtutor这个脚本,而是通过cp命令拷贝一份至用户目录,随后修改这一份脚本,然后
1
2
3
4
5
vim ~/.bashrc
# 添加一行 alias vimtutor='~/vimtutor_script_modified'
# 也就是修改命令别名,使vimtutor指向用户目录下修改后的vimtutor脚本
. ~/.bashrc
# .即source,这里是执行更新后的bashrc文件以便应用更改于shell

之后便可以在使用vimtutor命令打开的vimtutor文档中正常使用:help w等命令查看帮助文档啦~

Read more »

下午睡了一觉,醒来决定找出尘封已久的树莓派,在上面配置一些开发环境。下文是关于所做之事的总结。

配置vsftpd

在树莓派上使用wget下载文件速度奇慢,不知为何,于是决定配置vsftpd,通过ftp将笔记本上下载好的压缩文件传送至树莓派上。

1
2
3
4
5
6
7
8
9
service vsftpd status #检查vsftpd状态,发现并没有安装vsftpd。
yum -y update #许久没有使用过树莓派,先通过yum进行全局更新。
yum -y install vsftpd #安装vsftpd软件。
vim /etc/vsftpd/vsftpd.conf #打开配置文件
anonymous_enable=NO # 禁用匿名登录
chroot_local_user=YES # 启用限定用户在其主目录下
firewall-cmd --permanent --add-port=21/tcp #允许默认ftp端口21通过防火墙(Firewalld,i.e. firewall-cmd)
firewall-cmd --reload #重载防火墙
service vsftpd status #检查vsftpd状态,安装成功

参考博客文章:How to Install and Configure vsftpd on CentOS 7

Read more »

本文最后更新于2019/1/11,以下内容均来自官方文档。
这里只介绍了一些基本的游戏机制,具体请自行研究官方文档。

游戏机制相关

介绍

Screeps是个什么类型的游戏

Screeps是一个大型多人在线的即时战略游戏。每个玩家可以在一个由全部玩家共享的永久世界中创建自己的殖民地。这样一个殖民地可以挖掘资源,建设单位,征服领土。当你征服更多的领土,你在游戏世界的影响力会随之增长,同时你进一步扩展的能力也会增强。然而,它需要你付出很多,因为多个玩家可能会看中同一个区域。

Read more »

应该做什么

这一节主要是介绍基本发展所需要做到的事情,并不会过于深入。

升级控制器(Controller)

Screeps世界由一个个房间组成,每个可控制的房间都会有一个控制器,控制器支持的方法在这里

Creep可使用能量(Energy)对控制器进行升级,控制器的等级称为RCL(Room Control Level),RCL的高低决定了该房间可使用的设施,当一段时间没有对控制器进行升级时,控制器将会降级,降级后,进度并不会减少,稍后进行升级时,只要进度达标,控制器等级会立即升高。已经建造的设施会在RCL等级不足时变为无法使用的状态,显示为红色高亮。当控制器降到0级时,将会失去对该房间的控制。

Read more »

1
2
3
4
5
6
7
8
9
10
11
12
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
(define (pi-sum a b)
(define (pi-term x)
(/ 1.0 (* x (+ x 2))))
(define (pi-next x)
(+ x 4))
(sum pi-term a pi-next b))
(* 8 (pi-sum 1 100000))
Read more »

最近沉迷一款游戏Screeps,是一款使用Javascript编写的MMO游戏。一开始是在群里看见有人在玩,之后了解后从Steam购买了这款游戏。

这两周一直在玩,重生两次后暂时稳定下来,因为RCL和脚本的限制,现在仅发展了W79S34

最新房间 Shard2 E9N47

Read more »

Java 8 functional interfaces

函数式接口是一个只有单个抽象方法的接口,可以通过默认方法扩充其实现。(以@FunctionalInterface在接口前声明)

内建函数库

java.util.Predicate

1
2
3
4
@FunctionalInterface
public interface Predicate<T> {
boolean test(T t);
}
Read more »

偶尔发现会在编辑器中莫名地输入奇怪的字符,编辑器也会提示无法识别,就像这种strange。一直搞不清问题所在,常常是重新打开编辑器就好了。今天偶尔发现输入法都有个快捷组合键是Shift+Space,作用是切换全角半角。切换全角后对中文输入没影响,但是输入的英文就会是中文编码,而且与中文等宽,解决办法就是重新切换为半角-。-ll

Read more »

最近没有实际做出什么东西来,也就没有更新博客。在认真的研究所选的课程,Linux、数据库、Visual C++、Java、数据结构等,可能也是因为期末将近的原因吧。

也是希望能够更加深入地理解一些概念,而不是一味地写一些没什么技术含量的小程序,能够提高知识水平,扩展知识面,真正地有能力去做一些项目,去实现自己想要实现的东西。

那么,先撤了~

Read more »

安装mysql-connector-rf

因为图方便,在树莓派上安装的是最简版的CentOS,所以许多软件都需要自己安装。

What are the differences between mysql-connector-python, mysql-connector-python-rf and mysql-connector-repackaged?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@centos-rpi3 ~]# easy_install mysql-connector-python-rf==2.1.3
Searching for mysql-connector-python-rf==2.1.3
Reading https://pypi.python.org/simple/mysql-connector-python-rf/
Downloading https://pypi.python.org/packages/f9/d5/f317d4310963a8e9cafa3eb3d24ae 5a089b8951149ed48bbd89213dd04ff/mysql-connector-python-rf-2.1.3.tar.gz#md5=25f32 0d6db5f304394e12b27416fe855
Best match: mysql-connector-python-rf 2.1.3
Processing mysql-connector-python-rf-2.1.3.tar.gz
Writing /tmp/easy_install-YExMJC/mysql-connector-python-rf-2.1.3/setup.cfg
Running mysql-connector-python-rf-2.1.3/setup.py -q bdist_egg --dist-dir /tmp/ea sy_install-YExMJC/mysql-connector-python-rf-2.1.3/egg-dist-tmp-Nh8V6S
zip_safe flag not set; analyzing archive contents...
Moving mysql_connector_python_rf-2.1.3-py2.7-linux-armv7l.egg to /usr/lib/python 2.7/site-packages
Removing mysql-connector-python-rf 2.0.4 from easy-install.pth file
Adding mysql-connector-python-rf 2.1.3 to easy-install.pth file

Installed /usr/lib/python2.7/site-packages/mysql_connector_python_rf-2.1.3-py2.7 -linux-armv7l.egg
Processing dependencies for mysql-connector-python-rf==2.1.3
Finished processing dependencies for mysql-connector-python-rf==2.1.3

实际运用-查询数据

Read more »

通过网线直接连接树莓派

几个月前入手的树莓派3B,最近开始深入研究。因为自己宿舍里东西有点多,也就没买显示器这种配件,打算通过SSH来操作。

通过网线直接连接树莓派和电脑实现树莓派共享上网
之前已经为树莓派写入了CentOS,但是购买时并没有配置相应的显示器,所以得通过ssh连接树莓派。
在网上找到这篇教程并实际操作后连入了系统。

安装easy_install

方便安装Python模块。

Read more »

1.实现一个较为完整的定制类,支持初始化,输出自定义实例、类对象信息,len()调用,for in,[],获取默认属性,以及调用instance():

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
class Custom(object):

__slots__ = ('_name','index')

def __init__(self,name):
self._name = name
self.index = -1

def __str__(self):
return 'Custom Instance => (name: %s)' % self._name

__repr__ = __str__

def __len__(self):
return len(self._name)

def __iter__(self):
return self

def next(self):
self.index+=1
if self.index >= len(self._name):
raise StopIteration();
return self._name[self.index]

def __getitem__(self,n):
return self._name[n]

def __getattr__(self,attr):
if attr=='func':
return lambda: 'FFF'
elif attr=='attr':
return 'attr'
raise AttributeError('\'Custom\' object has no attribute \'%s\'' % attr)

def __call__(self):
print "Instance's name is %s." % self._name

2.链式调用
对应问题定制类-廖雪峰

看评论前自己想到的做法:

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
class Chain(object):

def __init__(self,user=':user'):
self._user = user

def __getattr__(self,attr):
if attr=='users':
'''
方法一:
def func(name):
self._user=name
return self
setattr(self,'users',func)
return self.users
方法二:
return lambda name:Chain(name)
方法二可能有局限
'''
return lambda name:Chain(name)
elif attr=='repos':
return 'GET /users/%s/repos' % self._user
raise AttributeError('\'Chain\' object has no attribute \'%s\'' % attr)

def __str__(self):
return self._user
__repr__ = __str__

看完评论之后的做法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Chain(object):

def __init__(self,path=''):
self._path = path

def __getattr__(self,path):
return Chain('%s/%s' % (self._path, path))

def __str__(self):
return self._path
__repr__ = __str__

def __call__(self,path):
if path=='users':
return Chain('%s/%s' % (self._path, path))
return self

在看教程时,__call__是在后面介绍的,所以我先前的做法并没有涉及到’__call__,看完这篇教程和后面的评论以后,作出了一些修改。

Read more »

了解腾讯公益404

腾讯公益404

为站点指定404页面

httpd.conf中找到子站点对应的VirtualHost,在里面添加一项

1
ErrorDocument 404 /404.html

即可指定404页面为站点根目录下的404.html

调整返回链接

Read more »

今天将博客的主题更换为NexT.Pisces,对主题进行了简单的设置,于某个博客发现了页面底部的PV,UV统计,有些感兴趣。

于是通过搜索引擎获知不蒜子这一统计引擎,NexT集成了这第三方引擎,遂于主题配置文件中启用了统计。却发现页面PV这一数据并没有正常的显示出来。十分不解,决定查看源码一探究竟。

经查看,最后定位于themes/next/layout/_layout.swig这一布局文件,发现并没有加入有关页面pv的标签,在不蒜子官方博客找到对应标签后写入这一文件。首页得以显示这一标签内容,进入文章页面后却发现这一标签并没有值,打开浏览器发现确实能获得当前文章的PV,但没有按照预想的那样回填至标签中。

最终发现,文章pv只是没有显示在页面底部,而是在文章标题的正下方小字中…

Read more »

感觉对学习有一些困惑,目前在学的编程语言包括C/Java/Python,Java相对有些小型项目的经验,几周前开始学习Python,觉得挺方便的。

但是光学习概念总觉得不够,想做项目却又没合适的。

然后对算法又有些想法,自己也购买了许多开发相关的书,所以表现出来就是学的有点杂…

唉 只是发个牢骚顺便更新博客,希望能够找到真正合适自己的学习路线和方式吧,与君共勉.

Read more »