rs690m hardware 3D acceleration 

检查是否启用3D硬件加速。
glxinfo | grep OpenGL

命今输出结果如下:
若为
OpenGL renderer string: Software Rasterizer
则是软件加速。
若为
OpenGL renderer string: Mesa DRI R300 (RS690 791F) 20090101 NO-TCL
则是硬件加速。

自kernel 2.6.31一来,内核archlinux 内核默认开启了kms,以致rs690硬件加速失败,只要关闭kms即可。
关闭kms的方法是在 menu.lst kernel 一项中增加 nomodeset 参数后重启机。

相关参考请见:kernel 2.6.31 KMS
[ add comment ] permalink ( 2.9 / 35 )
编译perl6 

环境archlinux
编译PERL6步骤:
1、安装gun c开发环境
sudo pacman -S base-devel glibc
2、安装parrot VM
sudo pacman -S parrot
然后下截Rakudo包,按官方安装手册,解压缩源码包后,
$ cd rakudo
$ perl Configure.pl --gen-parrot
$ make
$ sudo make install

测试安装结果:
$perl6 -e 'say "hello world!"'
输出hello world!
安装成功。
[ add comment ] permalink ( 3 / 51 )
新版的内核加截多合一读卡器太方便了 

插入MMC/SD卡后。
dmesg |tail

sd 6:0:0:0: Attached scsi generic sg2 type 0
usb-storage: device scan complete
sd 6:0:0:0: [sdb] 1990656 512-byte logical blocks: (1.01 GB/972 MiB)
sd 6:0:0:0: [sdb] Write Protect is off
sd 6:0:0:0: [sdb] Mode Sense: 03 00 00 00
sd 6:0:0:0: [sdb] Assuming drive cache: write through
sd 6:0:0:0: [sdb] Assuming drive cache: write through
sdb: sdb1
sd 6:0:0:0: [sdb] Assuming drive cache: write through
sd 6:0:0:0: [sdb] Attached SCSI removable disk

看到了没有,[sdb] Attached SCSI removable disk,指明sdb为你的node标识,具体点来讲,你的卡对应的node是sdb:sdb1,即sdb1

sudo mkdir /mnt/sdb
sudo mount -t vfat /dev/sdb1 /mnt/sdb

现在你已经可以在/mnt/sdb目录使用你卡中的文件了。
取出卡前,最好是先sudo umount /mnt/sdb1。

取出卡后,
dmesg|tail
usb 1-9: USB disconnect, address 6
看到没,disconnect.

本人环境:
uname -a

Linux localhost 2.6.31-ARCH #1 SMP PREEMPT Fri Oct 23 10:03:24 CEST 2009 x86_64 AMD Athlon(tm) Processor TF-20 AuthenticAMD GNU/Linux

若用kernel 2.6.30以前内核的用户,可以参阅本人的另一篇笔记 archlinux 启用读卡器


[ add comment ] permalink ( 3.1 / 81 )
认识python的抽象类abc 

抽象类经常被描述为"不能实例化的类"。这个定义本身没错--在实现层次上。但局限性太大了。在概念层次上定义抽象类会更有帮助。在概念层次(实现抽象类所代表的概念),抽象类就是其他类的占位符。
也就是说,抽象类为我们提供了一种方法,能够给一组相关的类赋予一个名字。这使我们能够将这一组相关类看成一个概念。

可以使用抽象类定义其派生类必须实现的方法。抽象类还可以包含所有派生类都能够使用的公共方法。派生类是便用抽象类的默认行为还是使用自已有所变化的使为,由派生类自已决定,即对象自已负责自已。

自python2.6版起,引入了抽象类,通过metaclass=abc.ABCMeta来实现抽象定的定义。
即然抽象类是占位符,那么结合pthon3的方法签名,可以为随后其具体化提供进一步帮助。

格式,定义抽象类Server,包含两个属性(host,port),一个方法(startup)。

#!/usr/bin/env python3

import abc

class Server(metaclass = abc.ABCMeta):

def __init__(self, host:str = 'localhost', port:int = 8080):
self.__host = host
self.__port = port

@abc.abstractproperty
def host(self)->str:
return self.__host

@abc.abstractproperty
def port(self)->int:
return self.__port

@abc.abstractmethod
def startup(self, handler:object):
''' startup server handler'''
pass

测试抽象类,占位符作用(即不能被实例化)

>>> Server()
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
Server()
TypeError: Can't instantiate abstract class Server with abstract methods host, port, startup

知识点:python的抽象类的属性和方法是通过abc模块函数abc.abstractpropety,和abc.abstractmethod,来实现的,需要注意的是abc.abstractpropety和python2.6起用的新类propety装饰符使用方法类似。以上例子定义的属性是只读属性。

下面我们来具体化一个Server抽象类,具体化即是实现抽象类所定义的属性和方法。

class WSGIRefServer(Server):
''' WSGIRefServer concrete class Server'''

def __init__(self, host:str = 'localhost', port:int = 8080):
self.__host = host
self.__port = port

def __get_host(self)->str:
return self.__host
def __set_host(self, host:str)->str:
self.__host = host
return self.__get_host()

def __get_port(self)->int:
return self.__port
def __set_port(self, port:int)->int:
self.__port = port
return self.__get_port()

def startup(self, handler:object):
''' startup server handler'''
from wsgiref.simple_server import make_server
serve = make_server(self.__host, self.__port, handler)
serve.serve_forever()


host = property(__get_host, __set_host, doc='host:str = "localhost" ip addr or host name')
port = property(__get_port, __set_port, doc='port:int = 8080 listen port')


具体化抽象类,即必须定现抽象类所定义的全部抽象方法和抽象属性,具体化的同时可以继承抽象类的公用方法,也可以增加自已的新方法,新属生。
怎样继承抽象类的公用方法,可以在抽象类中用classmethod装饰符来装饰一个方法为会用方法。
测试抽象类的具体化类:

>>> assert(issubclass(CGIServer, Server))
>>> assert(isinstance(CGIServer(), Server))


具体化类实列的属性读写测试:

>>> s = CGIServer()
>>> s.host
'localhost'
>>> s.host = '127.0.0.1'
>>> s.host
'127.0.0.1'


知识点:python3的abc,所定义的只读abstractpropety,可以在具体化是实现读,写,删。可能这是个小小的BUG。python的abc,是不能具体化类的.__call__方法的,这一点可以看abc的源码。
[ add comment ] permalink ( 3.1 / 79 )
python运算符复习之or not str in sequence 和 or str not in sequence 

python的数据类型定义序列类(sequence)型包含(str,bytes, bytearray, list,tuple,range),
sequence类型都可以用for语句进行iter,可以用in,not in成员运算符进行成员归属测试,以测试某成员是否属于该序列,成员运算符返回布尔值,以便进行值比较运算。

python的布尔运算符有(or, and, not)三种。

在python中可以得到布尔值的运算符刚有如下几类,
1、比较运算符(<,<=,==,!=,>=,>)
2、等同性运算符(is, is not)
3、成员运算符(in, not is)
4、布尔运算符(not, and, or)

除此外,同c语言一样,非零即真,这里的零指的是数字0、None、空sequence。
按python运算优化级顺序,以上可以得到布尔值的运算值1~4,是按从最低到最高顺序,这里不讨论括号要以变理表达式运算顺序内容。

布尔运算符or 又称之为断运算符,如:

>>> a, b = 1, 2
>>> a or b
1
>>> a, b = 0, 2
>>> a or b
2


在知得了布尔运算符or的逻辑后,进阶学习,如:

>>> s, ss, sss = 'a', 'ab', 'bcd'
>>> s in ss
True
>>> not s in ss
False
>>> not s in ss or True
True
>>> not s in ss or s in ss
True
>>> s not in ss
False
>>> s not in ss or s in ss
True
>>> s not in ss or not s in ss
False
>>> s not in ss or s not in ss
False

>>> s not in sss
True
>>> s in sss
False
>>> s in sss or s not in sss
True
>>> s in sss or not s in sss
True
>>> s in sss or not s
False
>>> s in sss or not s in sss
True
>>> s in sss or not s not in sss
False


>>> s in sss or s in ss
True
>>> s in sss or not s in ss
False
>>> s in sss or not s in ss or s in sss
True
>>> s in sss or not s in ss or not s in sss
False


是不是对or not str in sequence 和 or str not in sequence的认识更加深刻了!:)
作为练习,请看代码心算一下输出结果,

>>> s in sss or s not is ss or not s in sss
?
>>> s in sss or s in ss or not s in ss
?

[ add comment ] permalink ( 3 / 86 )

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>