搭建了一个免费电子书下载搜索引擎

用Google自定义搜索搭建了一个免费电子书下载搜索,把以前常用的几个站点都放上去了。包括csdn下载频道这类非法电子书交换市场;也包括RapidShare这样的文件存储网站;还有一些大大小小的电子书共享网站。以后随时把自己用到的类似站点这样做垂直分类。

实际上早有人开始做这样的事了,而且更敬业一些。对自定义搜索引擎中搜索一下就可以找到他们了。

coopfreeebookdownload.png

超市用防盗磁扣的原理


今天在家乐福买了两大车的年货,结帐的时候非常不顺利。打印机的盖子总也扣不上,领班和收银员都忙出汗也搞不定。我顺手拿了一大瓶除臭剂压在上面,搞定了。收银员很感激,给我结帐时也特意加快速度,结果还是忘了把一套内衣上的磁扣摘下来。我们也是到了家才发现。想把这个磁扣取下来还是挺难的,最后只好暴力的用钢锯将底座被面的突起割开。同时也得以详细观察了磁扣的原理。

从外表看,完整的磁扣包括两部分,钢针和底座。打开了底座背后的突起,看到磁扣实际由以下几部分组成。
dsc01637.JPG

  • 钢针(注意钢针表面是有环形槽的)、底座。
  • 大小两个带孔的铁碗。它们是套在一起的。
  • 一根弹簧。
  • 四个小钢珠。

这几部分,在结构上围绕钢针组成的轴配合在一起。
dsc01639.JPG

  • 大铁碗开口方向和钢针针尖方向相同,嵌在底座里。
  • 四个钢珠放在大碗里。
  • 小碗坐在大碗里,顶住钢珠。
  • 弹簧和底座的突起部分将小碗向大碗内顶。
  • 底座突起部分和底座实际上是一体的,我用了钢锯才锯开。

因为大小碗的中心都有洞,所以钢针可以沿着两个碗的轴心从碗底方向穿过来。四个钢珠围绕着钢针的针杆。当弹簧顶着小碗,将钢珠顶向大碗的碗底,大碗的截面逐渐缩小,钢珠就会紧紧卡在钢针表面的槽上。这时候用力越向碗底的方向拔钢针,钢针就卡得越紧。这样就用机械限位的方式实现了一个自动锁结构。当针插向底座,钢珠阻碍了针的路线,针会将小碗顶开,钢珠活动空间增大,钢针就可以通过了。

dsc01638.JPG
正常情况下使用什么办法打开磁扣的呢?既然是“磁扣”,就要用到磁场。说白了,就是用一个强力磁铁,将小碗和钢珠向针尖方向吸过去,钢珠活动空间增大,针就拔出来了。磁场一定要用强力的,不然没法客服弹簧的弹力。

希望我的好奇能解决其他好奇朋友的疑惑,而不是仅仅给梁上君子上辅导课。


自动单元测试框架, PyUnit, tsqlunit, xUnit framework

Notes on Python自动单元测试框架

from widget import Widget
import unittest

class WidgetTestCase(unittest.TestCase):                   # 测试例(test case)
    def setUp(self):                                       # 测试前的初始化工作。
                                                           # 声明在unittest.TestCase中,自动调用。
        self.widget = Widget()
    def tearDown(self):                                    # 测试后的清理工作。
        self.widget = None

    def testSize(self):                                    # 自定义的测试方法。
        self.assertEqual(self.widget.getSize(), (40, 40))  # assertEqual是TestCase提供的工具。

    def testColor(self):                                   # 一个测试例中可以定义多个测试方法函数。
                                                           # 默认的测试方法函数名为runTest
        pass

def suite():                                               # 测试集(test suite)
    suite = unittest.TestSuite()                           # 函数返回TestSuite的测试集实例。
    suite.addTest(WidgetTestCase("testSize"))              # 测试集中加入测试方法。
                                                           # 多个测试方法组成一个测试集。
                                                           # 可以用unittest.makeSuite批量添加测试方法。
    return suite

if __name__ == "__main__":
    unittest.main(defaultTest = 'suite')                   # 执行测试
                                                           # 也可自定义执行测试的Runner
                                                           #     runner = unittest.TextTestRunner()
                                                           #     runner.run(suite)

自动生成测试例,批量测试

借鉴JUnit框架上的一个方案,用程序生成一个足够大的测试集。Write a suite( ) method that iterates through all of your
input data, creating a unique instance of your test case for each
unique input. The data is passed to the test cases through the
constructor, which stores the data in instance fields so it is
available to the test methods.

A similar solution,
pyUnit and dynamic test functions .

如果像我这样需要一个测试集,可以自动的无穷尽的pop出各种各样的,甚至是随机的测试例,或者是测试例的参数,而不是预先在测试集中(内存中)建立好所有的测试例,可以利用TestSuite的Iterator的特性实现。

TestRunner中的run方法,对TestSuite来说,仅仅是调用了其test方法。

class TextTestRunner:
    """ ... """
    def run(self, test):
        "Run the given test case or test suite."
        result = self._makeResult()
        startTime = time.time()
        test(result)
        stopTime = time.time()
        timeTaken = stopTime - startTime
        result.printErrors()
    """ ... """

所以可以重载TestSuite类,生成支持Iterator的测试集,自动生成测试例。代码如下

import unittest
class TheTestCase(unittest.TestCase):
    def __init__(self, n):
        unittest.TestCase.__init__(self)
        self.n = n
    def runTest(self):
        assert( self.n>3 )

class MyTestSuite(unittest.TestSuite):
    def __init__(self):
        unittest.TestSuite.__init__(self)
        self.i = 0
        self.N = 5
    def __iter__(self):
        return self

    def next(self):
        self.i += 1
        if self.i > self.N: raise StopIteration
        return TheTestCase(self.i)

    def run(self, result):
        for test in self:
            if result.shouldStop:
                break
            test(result)
        return result

def suite():
    return MyTestSuite()

if __name__=='__main__':
    unittest.main(defaultTest='suite')

xUnit Framework

结合这个tsqlunit框架 (不是很实用),可以粗略总结xUnit Framework构建的单元测试框架里的一些要点。

  • 集中格式化输出显示(PRINT)测试结果及报告。
  • 通过测试集、测试例组织管理测试代码,重用测试代码。
  • 自动加载测试例。
  • 统一测试例的接口(包括异常抛出),简化测试例编写。

SQL Server开源免费工具

Buck Woody 在MSDN Blog上列出了他最中意的开源 SQL Server 工具软件,这些开源软件都是在微软的开源软件平台,CodePlex 上进行维护的。他介绍了五个软件。

  1. Web版维护工具,SQLWebTools,http://www.codeplex.com/SQLWebTools。基于Web的SQL Server维护工具,可以用在远程主机上,代替企业管理器(企业管理器不是免费的)。还有一个Php版的工具phpMSAdmin,与之类似。
  2. DBA经常要做的一件事,就是用脚本备份整个数据库结构。ScriptDB就是这样一个工具,http://www.codeplex.com/ScriptDB。这是一个用C#写成的命令行工具,可以将数据库结构以企业管理器中的层次结构备份到文件夹中。可以定期对数据库结构及其中的程序(存储过程、视图、函数、触发器等)做这样的快照,之后进行文本比较或者添加到版本管理工具中。
  3. 数据库比较工具, DbDiff, http://www.codeplex.com/DbDiff。这种工具是非常有用的工具,可是在这之前我还没有找到过真正免费的。DbDiff只能比较数据库结构,不能比较数据。RedGate提供一系列的工具很强大,价格也公道。

  4. SQL Server Express 管理工具,ExpressMaint, http://www.codeplex.com/ExpressMaint。SQL Server Express是免费的数据库服务器,有了各类辅助工具,就很值得一用。

  5. Simple SQL Server Dependencies, http://www.codeplex.com/SSSDependencies, 顾名思义,就是对SQL Server中的Object之间的关系进行分析的工具。

另外,在Del.icio.us中用sqlserver opensource tool这三个Tag ,可以发现下面的这些工具。Enjoy yourself.

  1. SqlDump - MS SQL database backup program

    SqlDump is a program to backup a Microsoft SQL Server database as a text file. SqlDump generates SQL statements for tables, indexes, user-defined types, views, procedures, etc and also the table data.

  2. SourceForge.net: DB Designer Fork

    DB Designer Fork is a fork of the fabFORCE DBDesigner 4. DBDesigner is a visual database design system that integrates entity relationship design and database creation. DB Designer Fork generates SQL scripts for Oracle, SQL Server, MySQL and FireBird.

  3. SQuirreL SQL Client Home Page

    SQuirreL SQL Client is a graphical Java program that will allow you to view the structure of a JDBC compliant database, browse the data in tables, issue SQL commands etc, see Introduction. The minimum version of Java supported is 1.5.x as of SQuirreL vers

  4. Query Express

    “Simple Query Analyzer look-alike, especially useful for MSDE and SQL Express. Also connects to Oracle and other OLE-DB compliant databases. Packaged as a single 100KB executable, i.e. more than 300 times smaller than SQL Server Management Studio.”

  5. Data Dictionary Creator

    Data Dictionary Creator (DDC) is a simple application which helps you document SQL Server databases. It stores all the information in Extended Properties, so it’s easier to keep the documentation in sync with the database as it changes.

  6. Data Modelling Tools

  7. SQL Manager: Database Management Tools for MySQL, SQL Server, PostgreSQL, InterBase, Firebird

    Database maintenance tools for popular relational database servers.

  8. |QueryCommander the sql editor|

    QueryCommander is a free sql editor wrapped in a Visual Studio type of environment. QueryCommander supports:

  9. SqlBI.eu

  10. SqlBulkTool 1.0

    SqlBulkTool is a command line utility that is used to quickly create a mirror of a database. It reads its configuration from an XML file containing source and destination command strings and a list of all the tables to mirror and then handles the work of

  11. TSQLUnit testing framework

  12. SchemaSpy

    Graphical Database Schema Metadata Browser

一些厂商提供的数据仓库工具

200811

19:48

做一个最浅度的分析。孰优孰劣从软件的外观上可知一二。图都来自于厂商在线手册。

公 司 名 称

ETL工具

数据仓库管理工具

OLAP工具

数据挖掘工具

报 表 工 具

IBM

Warehouse Manager

Visual Warehouse

OLAP Server

Intelligent

Miner

Insight&Qucik view

Oracle

Oracle ETL Server

Enterprise Manager

Express Server

Darwin

Express Analyser

Sybase

Replication Server PowerStage

Warehouse Studio

Warehouse Analyzer

SAS

SPSS

InfoMaker

CA

InfoPump

PLATINUM ERWin

PLATINUM InfoPump

DecisionBase InfoBeacon

Neugent

Aion

Forest&Trees

InfoReports

SAS

第三方

Warehouse Administrator

SAS MDDB

Enterprise Miner

EIS ER

Microsoft

SSIS

SQL Server

SSAS

SSAS

SSRS

Pasted from <http://book.csdn.net/bookfiles/537/10053718137.shtml>

IBM DB2 Business Intelligence

Pasted from <http://publib.boulder.ibm.com/infocenter/db2v7luw/topic/com.ibm.db2v7.doc/db2tu/db2tuo10.htm>

Oracle Warehouse Builder

Pasted from <http://download.oracle.com/docs/cd/B28359_01/owb.111/b31278/concept_data_modeling.htm>

Sybase WarehouseArchitect

Pasted from <http://manuals.sybase.com/onlinebooks/group-wa/wag0320e/waug/@Generic__BookTextView/28735;pt=30045>

Dimension Structure tab of Dimension Designer.

Pasted from <http://msdn2.microsoft.com/en-us/library/ms169952.aspx>

用于数据统计的R语言及RPy

类似于Matlab的统计模块,R语言是一种用于数据统计的开源免费语言(软件)。它是从贝尔实验室在70年代开发的S语言演变而来的,是成熟、通用的统计计算用工具,同时具有很强的绘图功能。IBM DW上的这篇文章介绍得很好。

R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …). 所以,R语言在数据挖掘中也可以得到应用。

r demo
r demo

针对R语言定期发布的一系列通讯,编辑得很好,对理解统计技术及应是很有帮助的,值得去读。

R语言可以通过RPy嵌入到Python环境中。这使得整合复杂的开发环境和工具成为可能。

摘录一段例子,应用RPy进行最小二乘线性拟合以及绘图的过程。

from rpy import r
my_x = [5.05, 6.75, 3.21, 2.66]
my_y = [1.65, 26.5, -5.93, 7.96]
linear_model = r.lm(r("y ~ x"), data = r.data_frame(x=my_x, y=my_y))
gradient = linear_model['coefficients']['x']
yintercept= linear_model['coefficients']['(Intercept)']

r.png("scatter_regression.png", width=400, height=350)
r.plot(x=my_x, y=my_y, xlab="x", ylab="y", xlim=(0,7), ylim=(-16,27),
           main="Example Scatter with regression")
r.abline(a=yintercept, b=gradient, col="red")
r.dev_off()

一个PNG图片输出出来

Random posts

  • 吕布
  • 陈进欺骗了鉴定专家、上海交大、研究团队、地方政府和中央有关部委
  • Solution for Matlab 7.0 R14 on XP Pro Start up Corruption
  • 现在用的主机
  • 换个便宜的虚拟主机