mebeh's lab

国产的腾讯  

2014-01-02 01:58:56

死活启动不了adb,更新了SDK也不行,然后就发现疼讯个狗日的把这玩意随QQ2013一起装进来了,文件修改时间和qq的一样。
启动参数:adb fork-server server

在组策略的软件限制策略里面添加一条路径规则:
%userprofile%\AppData\Roaming\Tencent\*

反正不需要它的自动升级功能安装后门。


扩展名是xml,但是内容不是
又发现它貌似保存了一些设备信息,那天发文件开过一次QQ,发完就关掉了。




Happy New Year!  

2014-01-01 00:00:00

Happy New Year!




树莓派+HC-SR04超声波测距  

2013-10-10 23:32:46

入了一只树莓派,B板,顺便又在淘宝入了几只传感器玩玩。收到货第二天才发现当初最想买的温度湿度传感器由于网络问题没放到购物车!

超声波测距的那只简单好玩,就先拿它练练。

型号:HC-SR04 如图:

HC-SR04正面 HC-SR04背面

VCC:+5v
Trig:开关,高电平开始测距
Echo:从发射超声波开始为高电平,收到回声为低电平
GND:接地

环境是 Raspbian,开箱即用。

按照 RPi Low-level peripherals 的接口定义这样接的线:

VCC   --- P1-02
Trig  --- P1-16 (GPIO23)
Echo  --- P1-18 (GPIO24)
GND   --- P1-06

树莓派+HC-SR04

思路很简单,设置Trig为高电平,检查Echo电平变化情况,记录高电平持续时间,这个时间就是超声波来回所用时间,距离=声速×时间/2,声速就不考虑温湿度气压的影响了取340m/s

下面上代码

#!/usr/bin/python 
#coding: utf-8
# 使用 HC-SR04 超声波测距模块测距
# VCC : P1-02
# GND : P1-06
# Trig: GPIO23 -    P1-16
# Echo: GPIO24 -    P1-18

import RPi.GPIO as GPIO
import time

# config
GPIO_PORT_TRIG = 23
GPIO_PORT_ECHO = 24

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_PORT_TRIG,GPIO.OUT)
GPIO.setup(GPIO_PORT_ECHO,GPIO.IN)

isExit = False
# 完成测距标志

def my_callback(channel):
    # GPIO_PORT_ECHO 变高电平的时候,该函数被调用
    global isExit
    e= 0                #声波返回时间
    s= time.time()  #声波出发时间
    while True:
        # 循环等待 GPIO_PORT_ECHO 变为低电平(声波返回)
        x = GPIO.input(GPIO_PORT_ECHO)
        if x==GPIO.LOW:
            e= time.time()
            break
    print '%sm' % round((e-s)*340/2,2)
    isExit= True    # 可退出程序


GPIO.add_event_detect(GPIO_PORT_ECHO, GPIO.RISING , callback=my_callback)
# 设置 GPIO_PORT_ECHO 变为高电平的时候调用 my_callback

GPIO.output(GPIO_PORT_TRIG,GPIO.HIGH)
# 设置 GPIO_PORT_TRIG 高电平,启动测距传感器
time.sleep(0.1)
GPIO.output(GPIO_PORT_TRIG,GPIO.LOW)
# 恢复低电平


# 程序保持运行最多5s或直到测速完成 isExit == True
k=time.time()
while not isExit:
    time.sleep(0.05)
    if time.time()-k>5:
        break

需要用 Superuser 权限来运行这段程序,GPIO.setup需要 root 权限。

pi@raspberrypi ~/program $ python test_range.py
Traceback (most recent call last):
  File "test_range.py", line 13, in 
    GPIO.setup(GPIO_PORT_TRIG,GPIO.OUT)
RuntimeError: No access to /dev/mem.  Try running as root!

运行结果:

pi@raspberrypi ~/program $ sudo python test_range.py
0.17m
pi@raspberrypi ~/program $ sudo python test_range.py
0.2m
pi@raspberrypi ~/program $ sudo python test_range.py
37.65m




Baby Blue  

2013-10-04 01:52:15

Breaking Bad 中老白在告别地球时候的背景歌曲。

歌名:Baby Blue

歌手:Badfinger

专辑:Straight Up

相关:Wikipedia

歌词:

Guess I got what I deserved

Kept you waiting there too long, my love

All that time without a word

Didn't know you'd think that I'd forget

Or I'd regret

The special love I had for you

My baby blue

All the days became so long

Did you really think I'd do you wrong

Dixie, when I let you go

Thought you'd realize that I would know

I would show

The special love I have for you

My baby blue

What can I do, what can I say

'Cept I want you by my side

How can I show you, show me a way

Don't you know the times I've tried

Guess that's all I have to say

'Cept the feeling just grows stronger every day

Just one thing before I go

Take good care, baby, let me know

Let it grow

The special love you have for me

My dixie dear




往Live邮箱导入联系人  

2013-09-12 21:14:46

买了Lumia 720,从老手机上导出了.csv格式的电话薄,考虑到不同厂商的.csv格式肯定不同,先导如Outlook 2013先,对应好字段,导入一切正常。然后再导出.csv格式文件,正宗的M$的格式哦,满怀欣喜的往mail.live.com的人脉里面导入,然后提示上传的数据为空。纳尼?但是打卡 csv 文件,里面满满的联系人!

再试试 Outlook 数据文件(.pst),三百多个联系人而已,pst的有2.19MB,估计是把图像加进来了,但是我没用图像,那就是把默认的占位图也装进去了……

拥有 512Kbps 上传带宽的高速光纤在10分钟后完成上传,M$看了好久然后平静的说“数据文件大于500KB”,!@#$%&$*@$%.


好吧,吐槽完了还是得想法导入电话薄。

先得找找看mail.live.com要求的字段是哪些,搜索半天有论坛发了“模板”,但是都要注册才能下附件,算球,自己想办法吧。

先随意添个联系人,把需要用到的字段都填上,然后直接从mail.live.com导出csv格式的电话薄,用记事本打开就看到全部字段了,如下:

为了方便查看加了换行

"Title",
"First Name",
"Middle Name",
"Last Name",
"Suffix",
"Company",
"Department",
"Job Title",
"Business Street",
"Business City",
"Business State",
"Business Postal Code",
"Business Country",
"Home Street",
"Home City",
"Home State",
"Home Postal Code",
"Home Country",
"Business Fax",
"Business Phone",
"Business Phone 2",
"Callback",
"Car Phone",
"Company Main Phone",
"Home Fax",
"Home Phone",
"Home Phone 2",
"ISDN",
"Mobile Phone",
"Other Fax",
"Other Phone",
"Pager",
"Primary Phone",
"Radio Phone",
"TTY/TDD Phone",
"Telex",
"Account",
"Anniversary",
"Assistant's Name",
"Billing Information",
"Birthday",
"Business Address PO Box",
"Categories",
"Children",
"Company Yomi",
"Directory Server",
"E-mail Address",
"E-mail Type",
"E-mail Display Name",
"E-mail 2 Address",
"E-mail 2 Type",
"E-mail 2 Display Name",
"E-mail 3 Address",
"E-mail 3 Type",
"E-mail 3 Display Name",
"Gender",
"Given Yomi",
"Government ID Number",
"Hobby",
"Home Address PO Box",
"Initials",
"Internet Free Busy",
"Keywords",
"Language",
"Location",
"Manager's Name",
"Mileage",
"Notes",
"Office Location",
"Organizational ID Number",
"Other Address PO Box",
"Priority",
"Private",
"Profession",
"Referred By",
"Sensitivity",
"Spouse",
"Surname Yomi",
"User 1",
"User 2",
"Web Page"

根据刚才随意添加的那个联系人看到一般只有一个号码的联系人只用到了 First Name,Middle Name,Last Name,Mobile Phone, E-mail Address这几个字段,手机号还有Home Phone,Home Phone 2,Mobile Phone,Other Phone几个字段可用。

然后就简单了,对应的改一下导出的那个csv文件的字段名

"First Name","Middle Name","Last Name","Mobile Phone"
"嘉",,"郭","13800138000"
"八朝",,"王","13800138001"

然后mail.live.com终于导入成功了。

修改csv文件的时候最好用支持显示格式化csv格式的文本编辑器,比较直观,可以列对齐。如果是用Excel注意不要让它把电话号码改成科学计数法的数字了,超长的号码可能会丢失最后几位,首位为0的号码也会弄丢。


WP还有很多基础基本的bug或不足,而且就是不改,所以说

M$倒掉了我一点都不感到奇怪

老鲍说不定还是高级马呢

诺基亚已经是你的了,搞倒他的那些技俩也可以拿掉了。




GAE 使用webapp2框架的custom template filter  

2013-08-21 00:29:40

想在用 gae 的 webapp2 框架下用 markdown,折腾了半天终于搞定了,以后是忘不了了,但还是记下来吧

1.下载安装 markdown

2.把安装好的 markdown 目录整个复制到项目目录

3.目录结构

- common
    __init__.py
    yourfilter.py
+ markdown
  main.py
  app.yaml

4.文件内容

yourfilter.py

import markdown
from google.appengine.ext.webapp import template
register = template.create_template_register()
def createmd(value):
    return markdown.markdown(value)
register.filter(createmd)

main.py

from google.appengine.ext.webapp import template
template.register_template_library('common.yourfilter')
......其他代码

5.然后在模板中就可以用 {{ post.content|createmd }} 得到 markdown 后的 html 了。