Nov 29, 2008

校内相册批量下载

很爽的东西。。。



o(∩_∩)o...



使用:

1. 下载一个用户的所有相册(包括头像相册)




如图:

-e 邮箱

-p 密码

-u 你想下载那个家伙的 用户id

比如:http: //xiaonei.com/getuser.do?id=221427773,那么 -u 就是 221427773


2. 想在一个用户的某一个相册



其他参数和上面的一样,就是多了一个 -a

-a 指定这个用户的具体相册

比如:http://photo.xiaonei.com/getalbum.do?id=255545234&owner= 221427773,

那么 -a 就是 上面url id的值,255545234

Nov 28, 2008

Thanksgiving Day

sms
make an appointment
dinner
walk
ice cream
go home

比去年的感恩节快乐多了!

Nov 14, 2008

Python Mysql中文解决方案

1. 安装时设置Mysql字符集为utf8
1)查看字符集支持
show character set;
2)查看字符集相关变量
show variables like "character_set%";
3)设置默认字符集为utf8 (这在Ubuntu上做的, Windows改my.ini)
修改/etc/mysql/my.cnf, 在[client]和[mysqld]下加上: default-character-set=utf8
/etc/init.d/mysql
注: 设置连接mysql时使用utf8,可以在[mysqld]下加上: init_connect='SET NAMES utf8'

2. cmd中查询时,先 set names gbk; 然后就可以正常显示汉字了

这样做是由于Windows cmd中无法显示utf8编码的汉字;如果你在Linux shell中就不需要这条命令了

3. 用MySQLdb:
db = MySQLdb.connect(host = 'localhost',
user = 'wap',
passwd = 'wap',
db = 'wap',
charset = 'utf8')

4. 读取GBK编码的文件
line = f.readline().decode('GBK')
注: 函数 decode( char_set )可以实现 其它编码到 Unicode 的转换
函数 encode( char_set )实现 Unicode 到其它编码方式的转换

5. 程序中使用字符串时,前面加上 u,如:
s = u'hello'

Nov 12, 2008

Windows搭建Python Apache Django Mysql环境

软件: Python、 Apache、mod_python、Mysql、MySQL-python

按上面的顺序安装就可以了

然后配置下apache,在httpd.conf中
把DocumentRoot、相应的Directory设置成web根目录
加一行:LoadModule python_module modules/mod_python.so
在把下面的东西加到最后:
<Location "/">
SetHandler python-program
PythonPath "['F:\web\django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE wap.settings
PythonDebug On
</Location>

<Location "/includes/">
SetHandler None
</Location>

<LocationMatch "\.(jpg|gif|png)$">
SetHandler None
</LocationMatch>

Oct 21, 2008

C# 读取gb2312文本文件

StreamReader objReader = new StreamReader(strFilename,System.Text.Encoding.GetEncoding("gb2312"));

如果不加第二个参数,读出来的中文是乱码

Python 自动搜索可用ip并设置

Python设置IP Address,用的是 qujinlong123@gmail.com 的,详见:用Python 干实事(一)自动修改Windows的IP、网关和DNS设置


我添加了搜索功能

# -*- coding: GB2312 -*-

# FileName: modify_ip.py
# Author  : ox0spy
# Email   : ossteerer@gmail.com
# Date    : 2008-10-21

# 程序的前两个函数是qujinlong123@gmail.com实现的,这里借用下


import _winreg
from ctypes import *

def    ModifyIpAddress(ipAddress, subnetMask, gateway, dnsServer):
    netCfgInstanceID = None
   
    hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, \
                           r'System\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}')
   
    keyInfo = _winreg.QueryInfoKey(hkey)
   
    # 寻找网卡对应的适配器名称 netCfgInstanceID
    for index in range(keyInfo[0]):
        hSubKeyName = _winreg.EnumKey(hkey, index)
        hSubKey = _winreg.OpenKey(hkey, hSubKeyName)
   
        try:
            hNdiInfKey = _winreg.OpenKey(hSubKey, r'Ndi\Interfaces')
            lowerRange = _winreg.QueryValueEx(hNdiInfKey, 'LowerRange')
   
            # 检查是否是以太网
            if lowerRange[0] == 'ethernet':
                driverDesc = _winreg.QueryValueEx(hSubKey, 'DriverDesc')[0]
                # print 'DriverDesc: ', driverDesc
                netCfgInstanceID = _winreg.QueryValueEx(hSubKey, 'NetCfgInstanceID')[0]
                # print 'NetCfgInstanceID: ', netCfgInstanceID
                break
   
            _winreg.CloseKey(hNdiInfKey) # 关闭 RegKey
        except WindowsError, e:
                            pass
                # print r'Message: No Ndi\Interfaces Key'
           
        # 循环结束,目前只提供修改一个网卡IP的功能
        _winreg.CloseKey(hSubKey)
   
    _winreg.CloseKey(hkey)
   
    if netCfgInstanceID == None:
        print '修改IP失败 - 没有找到网络适配器'   
        exit()
   
    # print netCfgInstanceID
   
    # 通过修改注册表设置IP
    strKeyName = 'System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\' + netCfgInstanceID
   
    # print strKeyName
   
    hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, \
                           strKeyName, \
                           0, \
                           _winreg.KEY_WRITE)
   
    try:
        _winreg.SetValueEx(hkey, 'IPAddress', None, _winreg.REG_MULTI_SZ, ipAddress)
        _winreg.SetValueEx(hkey, 'SubnetMask', None, _winreg.REG_MULTI_SZ, subnetMask)
        _winreg.SetValueEx(hkey, 'DefaultGateway', None, _winreg.REG_MULTI_SZ, gateway)
        _winreg.SetValueEx(hkey, 'NameServer', None, _winreg.REG_SZ, ','.join(dnsServer))
    except WindowsError:
        print 'Set IP Error'
        exit()
   
    _winreg.CloseKey(hkey)
    return netCfgInstanceID
   
# 调用DhcpNotifyConfigChange函数通知IP被修改
def Notify(netCfgInstanceID, ipAddress, subnetMask):
    DhcpNotifyConfigChange = windll.dhcpcsvc.DhcpNotifyConfigChange

    inet_addr = windll.Ws2_32.inet_addr

    # DhcpNotifyConfigChange 函数参数列表:
    # LPWSTR lpwszServerName,  本地机器为None
    # LPWSTR lpwszAdapterName, 网络适配器名称
    # BOOL bNewIpAddress,      True表示修改IP
    # DWORD dwIpIndex,         表示修改第几个IP, 从0开始
    # DWORD dwIpAddress,       修改后的IP地址
    # DWORD dwSubNetMask,      修改后的子码掩码
    # int nDhcpAction          对DHCP的操作, 0 - 不修改, 1 - 启用, 2 - 禁用
    DhcpNotifyConfigChange(None, \
                       netCfgInstanceID, \
                       True, \
                       0, \
                       inet_addr(ipAddress[0]), \
                       inet_addr(subnetMask[0]), \
                       0)


def Pin(ip = '192.168.1.1'):
    """ ping -n 1 ip"""
   
    import os
    if os.system("ping -n 1 %s >nul" % ip) == 0:
        return True
   
    return False   
               
def GetConfInfo(filename = 'conf.ini'):
        import re, sys
        try:
                f = open(filename, 'r')
                lines = [line.split('#')[0].strip() for line in f.readlines()]
                f.close()

                if len(lines) >= 6:
                        # ip网段
                        network = lines[0]
                        pattern = '^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$'
                        if not re.search(pattern, network):
                                print '网段设置错误,请修改配置文件网段信息'
                                sys.exit(2)
                        network = network.split('.')
                        network.pop()
                        network = '.'.join(network)
                        # print 'network : ', network
                        # 开始ip
                        startIp = int(lines[1])
                        if (startIp < 1 or startIp > 254):
                                print '开始ip设置错误, ip :', startIp
                                sys.exit(3)
                        # 结束ip
                        endIp = int(lines[2])
                        if endIp < 2 or startIp > 255:
                                print '结束ip设置错误'
                                sys.exit(4)
                        # 子网掩码
                        subnetMask = lines[3]
                        # 默认网关
                        gateway = lines[4]
                        if not re.search(pattern, gateway):
                                print '默认网关设置错误'
                                sys.exit(5)
                        # dns
                        dnsServ = lines[5]
                        if not re.search(pattern, dnsServ):
                                print 'dns服务器设置错误'
                                sys.exit(6)
                else:
                        print '配置文件有误,请修正后重试'
                        sys.exit(1)
                     
        except IOError, e:
                print '确定配置文件名为 : %s' % filename
                sys.exit(7)

        return [network, startIp, endIp, subnetMask, gateway, dnsServ]

Info = GetConfInfo()
if not Info:
        sys.exit()

network, startIp, endIp, subnetMask, gateway, dnsServ = Info
if startIp == endIp:
        endIp += 1
       
ipAddress = ['%s.%s' % (network, i) for i in range(startIp, endIp)]
subnetMask = [subnetMask]
gateway = [gateway]
dnsServer = [dnsServ]
url = 'http://ox0spy.blogspot.com'

MessageBox = windll.user32.MessageBoxA

for ip in ipAddress:
    ip = [ip]
    # print 'IP Address : ', ip
    netCfgInstanceID = ModifyIpAddress(ip, subnetMask, gateway, dnsServer)
    Notify(netCfgInstanceID, ip, subnetMask)
    if Pin(url):
        # print '可用Ip地址 :', ip[0]
        msg = '可用Ip地址 : %s o(∩_∩)o...' % ip[0]
        MessageBox(0, msg, 'Good luck', 0)
        break;
else:
        msg = '没有可用ip,换个网段试试 ^_^'
        MessageBox(0, msg, 'sorry', 0)

ttylinux Tips

1. ttylinux 引导程序安装
环境:vmware平台上装ttylinux
以前用vmware装完redhat等其他linux后,安装程序会自动把引导程序装好的,但ttylinux不同,它的引导程序必须自己手动 安装。
其实,非常简单
#installer mbr /dev/hdc /dev/hda
注:我只虚拟出一个硬盘,没有任何分区。
更多可以参考:http://www.minimalinux.org/ttylinux/docs/user_multi/node16.html

2. ttylinux 联网
///这完全是我的机器配置,不同isp提供的很多东西都是不一样的
 
I、设置ip addr、netmask、BROADCAST (我用的是静态ip)
#cp /etc/network.d/sample  /etc/network.d/interface.eth0
#vi /etc/network.d/interface.eth0
内容如下:
# network interface configuration file sample
# change settings and rename to interface.devname, i.e. interface.eth0
# network device name
INTERFACE="eth0"
# set to "yes" to use DHCP instead of the settings below
DHCP="no"
# interface settings
# IP address
IPADDRESS="192.168.18.18"
# netmask
NETMASK="255.255.255.0"
# gate way
#GATEWAY=192.168.18.1
# broadcast address
BROADCAST="192.168.18.255"
 
II、添加默认网关
#route add default gw 192.168.18.1
 
III、设置DNS 
#vi etc/resolv.conf
内容如下:
nameserver      219.146.0.130
nameserver      61.233.154.33
search localdomain
 
IV、编辑/etc/hosts,便于和我的win 2003、redhat互联
 
V、ttylinux不支持ftp,不过文件传输可以使用scp,tftp
  
     scp命令格式:
     scp local_files username@hostname:path/to/file
     scp username@hostname:path/to/file local_file
     例如:
     scp ./*.html jhou@www.nctu.edu.tw:www/portfolio/2005/
     就是将本地目前所在目录中的所有 .html 文件拷贝到 athena 的个人网页空间的 portfolio/2005/ 次目录中。
     tftp命令格式:
     tftp -i ip put/get files
     注:put 上传;get 下载
          files就是你要传输的文件

Jul 8, 2008

Windows CE开发入门

from  ox0spy.blogspot.com
by     ossteerer@gmail.com
// 声明下:俺是初学者,有问题的地方还请高手斧正

网上有一些Windows CE开发入门的文章,但我看的头很晕,所以决定写篇自己的学习过程~

1. 简单介绍下Windows CE: (来源于百度百科)
      WindowsCE是微软公司嵌入式、移动计算平台的基础,它是一个开放的、可升级的32位嵌入式操作系统,是基于掌上型电脑类的电子设备操作系统,它 是精简的Windows 95,Windows CE的图形用户界面相当出色。
      其中CE中的C代表袖珍(Compact)、消费(Consumer)、通信能力(Connectivit)和伴侣(Companion);E代表电子 产品(Electronics)。与Windows 95/98、Windows NT不同的是,Windows CE是所有源代码全部由微软自行开发的嵌入式新型操作系统,其操作界面虽来源于Windows 95/98,但Windows CE是基于WIN32 API重新开发、新型的信息设备的平台。Windows CE具有模块化、结构化和基于Win32应用程序接口和与处理器无关等特点。Windows CE不仅继承了传统的Windows图形界面,并且在Windows CE平台上可以使用Windows 95/98上的编程工具(如Visual Basic、Visual C++等)、使用同样的函数、使用同样的界面风格,使绝大多数的应用软件只需简单的修改和移植就可以在Windows CE平台上继续使用。Windows CE并非是专为单一装置设计的,所以微软为旗下采用Windows CE作业系统的产品大致分为三条产品线,Pocket PC(掌上电脑)、Handheld PC(手持设备)及Auto PC。

2. 现在的问题就是我们怎么开始开发Windows CE应用程序——搭建开发环境
    2.1、选择开发工具
     我选择eVC4(eMbedded Visual C++ 4.0)做开发工具,因为eVC4和VC 6.0很像,容易上手,而且与vs 2005相比非常小巧。

     软件下载:
      eVC4:http://www.microsoft.com/downloa ... &displaylang=en
      eVC4 sp4:http://www.microsoft.com/downloa ... &displaylang=en
      Windows Mobile 5.0 Pocket PC SDK:http://www.microsoft.com/downloa ... &displaylang=en
     Localized Windows Mobile 5.0 Pocket PC Emulator Images:http://www.microsoft.com/downloa ... &displaylang=en

     下载完毕,按这个顺序装完这4个软件,开发环境就ok了,就可以写个Hello World测试下了.

3. 第一个测试程序
  3.1 创建工程   
      打开eVC4,File --> New ,新建一个 "WCE Application" 工程,填好Project name、Location并选择CPU类型.
我只在模拟器中运行这个程序,所以我只选择了Win32 (WCE X86)
注:不管选择哪种CPU,Win32 (WCE emulator)都是必须要选择的.

       点OK进入下一步,然后,选择"An empty project" 建一个空工程(没有任何附加代码)
       怎么样,和VC 6.0 中创建工程很像吧~

  3.2 编写程序
        File --> New, 新建个C/C++源文件(即:C/C++ source file),在File处填写该文件的文件名hello,然后在刚才建的hello.cpp文件中输入下面的代码:
// hello.cpp - A sample "Hello World " program.

#include <windows.h>

// Program entry point

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
    MessageBox(NULL, TEXT("Hello World!"), TEXT("hello"), MB_OK);

    return 0;
}


现在按 F7 编译该程序,如果没有错误,就可以按 Ctrl+F5执行程序。在模拟器中可以看到程序执行结果.如下图:
点击在新窗口查看全图 CTRL+鼠标滚轮放大或缩小

4. 总结
     本文简单的介绍了Windows CE,并教你如何搭建开发环境,最后写了一个Hello World程序。有了这些基础我们就可以开始学习Windows CE程序开发了。

    推荐一本我最近正在看的书: Programming Microsoft Windows CE .NET, Third Edition.pdf (1.09 MB)

Jun 20, 2008

Tips

1. 校内相册支持批量上传,一次最多可上传60张。该工具只支持IE,Firefox中不可用

2. Google的Picasa 相册可以批量下载,有两种方法,都需要先安装Picasa
    a. 查看网页源代码,搜索“下载相册”,然后把url  copy到地址栏 回车
    b. 用Picasa Webalbums Assistant:可以通过指定Picasa用户名或图片地址来批量下载位于Google Picasa上某一相册中的图片
        官方网址:http://picasawebalbumsassistant.googlepages.com/ [需翻墙]
        下载地址:下载地址1 | 下载地址2 | 大小:806K

        Google 真是个好东西啊,太强大了。。。

May 23, 2008

使用Ubuntu Live CD 安装 grub

   一机器光驱不好用了,而且硬盘上没有任何系统。现在要在上面安装rhel5,一共五张盘,害怕装到第n(n < 5)张时光驱罢工
   手头上有没有空闲光驱,拆机器上的太麻烦
   故,选择硬盘安装
   但总要有个程序先把系统引导起来,如wingrub、grub4dos等,没有安装windows,wingrub显然就pass了
   正好手边有张Ubuntu Live CD,就用它了。
   用Live CD将系统引导起来,进入ubuntu。
   $ sudo grub
   grub> root (hd0,0)
   grub> setup (hd0,0)

    Checking if "/boot/grub/stage1" exists... no
    Checking if "/grub/stage1" exists... no

   Error 15: File not found

   grub>quit

   $ grub --version  // 查看grub版本
     grub (GNU GRUB 0.97)

    我把另一个系统中的/boot/grub 拷贝到 hda1中,现在就可以用上面的 root,setup命令将grub安装到这个系统上了。
    然后,只需把rhel的5个iso文件和vmlinuz、initrd.img拷贝到hda1中,重启机器,开始安装rhel5