Brat

Brat

A [framework|practice] of RESTful API based on Tornado

Github

to be continue…

(Comments)


Leds Love

LEDS-LOVE

#define LOVE  {
    {0, 0, 1, 1, 0, 0, 0, 0}, //0x30
    {0, 1, 0, 0, 1, 0, 0, 0}, //0x48
    {0, 1, 0, 0, 0, 1, 0, 0}, //0x44
    {0, 0, 1, 0, 0, 0, 1, 0}, //0x22
    {0, 1, 0, 0, 0, 1, 0, 0}, //0x44
    {0, 1, 0, 0, 1, 0, 0, 0}, //0x48
    {0, 0, 1, 1, 0, 0, 0, 0}, //0x30
    {0, 0, 0, 0, 0, 0, 0, 0}  //0x00
}

something which is blurred and difficult to understand

(Comments)


Traps in PonyORM

website: http://ponyorm.com/ useage: http://doc.ponyorm.com/ tracks: http://stackoverflow.com/questions/16115713/how-pony-orm-does-its-tricks/16118756#16118756

优势及好玩的地方就不介绍了,说说可能遇到的陷阱

more test_pony.py

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from pony.orm import Database, Required, sql_debug
from pony.orm import select, commit

db = Database('sqlite', ':memory:')


class User(db.Entity):
    email = Required(unicode)
    password = Required(unicode)

db.generate_mapping(create_tables=True)
sql_debug(True)

for i in range(2):
    user = User(email='1', password='1')
    commit()
    users = list(select(u for u in User))
    print users
    print id(users)

users = list(select(u for u in User))
print users

python test_pony.py

OPTIMISTIC ROLLBACK

INSERT INTO "User" ("email", "password") VALUES (?, ?)
[u'1', u'1']

COMMIT

SELECT "u"."id", "u"."email", "u"."password"
FROM "User" "u"

[User[1]]
4453021024
OPTIMISTIC ROLLBACK

INSERT INTO "User" ("email", "password") VALUES (?, ?)
[u'1', u'1']

COMMIT

[User[1]]
4453021600
SELECT "u"."id", "u"."email", "u"."password"
FROM "User" "u"

[User[1], User[2]]

设置为 debug 模式,可以看到 for 循环中 select 查询只有一次,这不是我们期望的

此现象也出现在单进程的 tornado server 中, handler GET 获取所有结果,POST 添加新内容,但每次得到的仍然是第一次获取的

可以改用 User.select_by_sql 这种方式

update at 23:30 提交 BUG 两小时后,作者就 fix 了 https://github.com/ponyorm/pony/commit/42ec42ab444948c407b5566752b1a51ac8c075ac

(Comments)


Remote Control

BOARD

所需硬件:

树莓派一块

315mhz 模块 发射、接受模块一组

遥控灯头 一组

所需软件:

rcswitch-pi

wiringpi

电路连线如上图:

上图左边为 315 模块发射端,用于替代原遥控器,并可结合树莓派,进行远程控制

上图右边为 315 模块接收端,用于监测原遥控器的发射的地址码,当然可以直接去查看遥控器电路

如图:

BOARD

此处我们用的是灯的遥控器,对应的的地址码为:10FF0110,从右向左查看,上 1 下 0 置空 为 F

我们去掉 315Mhz 接收端,留下发送端即可

初始状态为关闭,如图

CLOSE

执行命令(sudo ./send.out 10FF0110 1)后,如图,灯亮了

OPEN

使用任何语言在树莓派上写个简单的 API 接口,即可提供给手机作远程控制

(Comments)


Biking on weekend

骑行线路如下:

TRAVELING-LINE

全程129公里 A(白河堡水库)至B(珍珠泉乡),全路程均为山路,且山路十八弯,水库至白河峡谷为上山路线,海拔约500米,这段路程骑的累死了,以最低速前进,在山顶拐角就是下坡,这段路程爽爆了,以最高速度前进,虽然只有5到10分钟,用两个小时的上山换5分钟的下山,值了。然后就是各种的上坡下坡,这个比前面的路程还要考验,无尽的上下坡,让你很崩溃,但也合理,你不能指望着全是下坡,否则就不守恒了;)

山里的夜晚很冷,分享完一天的趣事,就早早休息了

第二天,由珍珠泉乡出发前往延庆区,一马平川啊,但中间只有一个休息处,骑车已成机械式的了,顺利到达终点。

一路上,同事们说的最多的就是蛋都碎了,是啊,赞同;)

(Comments)