Thursday, July 31, 2008

No such file to load -- ubygems (LoadError)

Whatever Ruby module I want to install under Cygwin I always get the same
error: ruby: No such file to load -- ubygems (LoadError)

I've tried install rubygem, rubyfcgi etc. After "ruby config.rb config" or
"ruby config.rb install" I get error: "ruby: No such file to load --
ubygems (LoadError)" It looks strange. I am using last cygwin installation
with ruby 1.8.2 ()ruby 1.8.2 (2004-12-25) [i386-cygwin])

----

True. Try to unset the RUBYOPT environment variable. Did the trick for me.

Monday, July 28, 2008

PycURL example

Here's a little sample of Python code demonstrating the use of PycURL, the Python interface to libcURL. It does the same thing as my cURL example. Refer to this page for a detailed list of libcurl options.


import pycurl, StringIO
# Constants
DOWNLOADED_FILE = r'C:\temp\downloaded_file.txt'
USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 6.0)'
LOGIN_URL = 'http://interesting.website.com/LogIn.asp'
LOGIN_POST_DATA = 'FormField=URL%20Encoded%20Value'
DOWNLOAD_URL = 'http://interesting.website.com/do_it.asp?do=0&something=0&interesting=0'
DOWNLOAD_REFERER = 'http://interesting.website.com/referer.asp'
FILE_MODE = 'wb'

# Set up objects
dev_null = StringIO.StringIO()
slurpp = pycurl.Curl()

# Request login page
slurpp.setopt(pycurl.USERAGENT, USER_AGENT)
slurpp.setopt(pycurl.FOLLOWLOCATION, 1)
#slurpp.setopt(pycurl.AUTOREFERER, 1) # not yet implemented in pycURL
slurpp.setopt(pycurl.WRITEFUNCTION, dev_null.write)
slurpp.setopt(pycurl.COOKIEFILE, '')
slurpp.setopt(pycurl.URL, LOGIN_URL)
slurpp.perform()

# Log in to site
slurpp.setopt(pycurl.POSTFIELDS, LOGIN_POST_DATA)
slurpp.setopt(pycurl.POST, 1)
slurpp.perform()

# Download relevant data
slurpp.setopt(pycurl.HTTPGET, 1)
slurpp.setopt(pycurl.URL, DOWNLOAD_URL)
slurpp.setopt(pycurl.REFERER, DOWNLOAD_REFERER)
outfile = file(DOWNLOADED_FILE, FILE_MODE)
slurpp.setopt(pycurl.WRITEFUNCTION, outfile.write)
slurpp.perform()

# Clean up and close out
outfile.close()
dev_null.close()
slurpp.close()

Sunday, July 27, 2008

不给移动一分钱!10个免费发短信的国外站点

如今国内的用户对于手机资费的抱怨还是一直存在的,且不说双向收费这样的老大难问题,单就通话或短信的资费来讲我们的标准也都存在普遍较高的问题,虽然国家已经多次召开资费标准听证会,而我们也确实见到了一些下调,不过进度仍旧是缓慢的,这时就有了一种省钱的新模式,那就是通过互联网来向手机端发送免费短信,虽然可能会有些麻烦,但它的实际意义还是有的,毕竟我们节省了自己的花费,下面我们就为大家介绍10个来自国外的优秀免费发送短信的站点,一起来看看吧!

  1. Bloove.com 可以将你的手机内的联系人上传到站里,登陆之后就可以直接准确的将短信息发送到他们的手机上,非常方便快捷。

  2. ClearSMS.com 一个专业级的商用信息收发以及大规模群发的站点,它可以为你的用户提供不同的受到讯息提示,另外也可以通过付费来享受到更多的信息定制服务。

  3. GizmoSMS.com GizmoSMS可以让你免费自如的像全世界超过50个国家的用户发送免费短信,只是它并不能发送彩信,和其他任何多媒体消息,当然免费的我们还有什么可以挑剔的呢。

  4. Group2Call.com 支持导入你的本地联系人名单,然后可以以你自己设定好的群组进行免费短信群发,另外值得高兴的是它支持将声音文件一同发出,这是许多免费服务所没有的。

  5. Jaxtr.com 这个有点像一个当今流行的桌面“微件”,虽然看起来小,但是他也同样能够满足我们的免费短信需要,支持超过38个国家间的免费短信发送。

  6. OhDontForget.com 这个站与其他的站功能基本相同,不过它的亮点在于可以设定信息发送的时间,用来有特定需要的发送。

  7. SMSGupShup.com 一个非常强大的信息发送站点,支持向最多5000人群发短信,不知道这里会不会成为垃圾短信的源头...当然我们一般人也很难有5000个联系人。

  8. Swaggle.mobi 目前支持iPhone做好的免费短信发送站,支持iPhone上的联系人名单,并可以按组群发。

  9. Yahoo Mobile Yahoo推出的免费信息发送服务,当然它也不单单有这一项业务,而且是免费于收费并存的模式,不过对于它功能的强大与否是我们完全可以放心的。

  10. Yellowpipe 基于网页的一个免费短信与网络电话相结合的站点,我们除了可以发送短信之外还可以拨打通信录上的电话,并且方便的进行免费回拨。

Saturday, July 26, 2008

Python HTML 分析

google上找了下,说 Beautiful Soup 还不错。顺便转一篇关于Python的资源文章。

Python基本安装

  • http://www.python.org/ 官方标准Python开发包和支持环境,同时也是Python的官方网站;

  • http://www.activestate.com/ 集成多个有用插件的强大非官方版本,特别是针对Windows环境有不少改进;


Python文档:

  • http://www.python.org/doc/current/lib/lib.html Python库参考手册。

  • http://www.byteofpython.info/ 可以代替Tutorial使用,有中文译版的入门书籍。

  • http://diveintopython.org/ 一本比较全面易懂的入门书,中文版翻译最近进步为很及时的5.4了。

  • http://www.python.org/peps/pep-0008.html 建议采用的Python编码风格。

  • http://doc.zoomquiet.org/ 包括Python内容的一个挺全面的文档集。


提高mysql随机查询的效率


  1. 基本使用:
    SELECT * FROM `table` ORDER BY RAND() LIMIT 0,10;
    但是在ORDER BY后面用到RAND(),查询速度非常慢.

  2. MAX()*RAND()提高效率
    SELECT * FROM `table`
    WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`)) + (SELECT MIN(id) FROM `table`)))
    ORDER BY id LIMIT 1;

  3. JOIN
    SELECT *
    FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2
    WHERE t1.id >= t2.id
    ORDER BY t1.id LIMIT 1;


Thursday, July 24, 2008

header include path

where exactly is clanlib on your system?

as for picking up headers in non-standard locations, the CFLAGS environment variable takes care of that (and setting compiler optimizations and such) so for example if the header is in /usr/local/include/ClanLib-0.7/ClanLib you could:

export CFLAGS="-I/usr/local/include/ClanLib-0.7/ClanLib"

and it should pick up that directory

for the libs in nonstandard directories LDFLAGS or LD_LIBRARY_PATH will do (I like the latter better)
so for example if clanlib was installed in /usr/local/lib/clanlib you could:

export LD_LIBRARY_PATH=/usr/local/lib/clanlib:$LD_LIBRARY_PATH

which will set /usr/local/lib/clanlib as the first directory searched by the linker.

Wednesday, July 23, 2008