Monthly Archive for July, 2008

No such file to load — ubygems (LoadError)

1
2
Whatever Ruby module I want to install under Cygwin I always get the same
error: <span style="color: #007700;">ruby: <span style="color: #d2691e;">No such file to load -- ubygems (LoadError)</span></span>

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.
Continue reading ‘No such file to load — ubygems (LoadError)’

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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&amp;something=0&amp;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()

不给移动一分钱!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 基于网页的一个免费短信与网络电话相结合的站点,我们除了可以发送短信之外还可以拨打通信录上的电话,并且方便的进行免费回拨。

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内容的一个挺全面的文档集。

Continue reading ‘Python HTML 分析’

提高mysql随机查询的效率

  1. 基本使用:
    1
    SELECT * FROM `table` ORDER BY RAND() LIMIT 0,10;

    但是在ORDER BY后面用到RAND(),查询速度非常慢.

  2. MAX()*RAND()提高效率
    1
    2
    3
    SELECT * FROM `table`
    WHERE id &gt;= (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
    1
    2
    3
    4
    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 &gt;= t2.id
    ORDER BY t1.id LIMIT 1;

Continue reading ‘提高mysql随机查询的效率’

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:

1
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:

1
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.

几个Python爬虫库

PHP配合Squid缓存动态页面Header写法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function nocache_headers() {
       // @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
       // @ header('Expires: Wed, 11 Jan 2009 05:00:00 GMT');  
       @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
       if(PAGEME=="bookinfo"){
                @ header('Expires: ' . gmdate ("D, d M Y H:i:s", time() + 3600*24). " GMT");
       }else{
                @ header('Expires: ' . gmdate ("D, d M Y H:i:s", time() + 3600). " GMT");      
       }
       
       // @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
       // @ header('Pragma: no-cache');
               
       // @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
       // @ header('Pragma: no-cache');
}

Kernel 2.6.26 Resume Bug

刚升级到 2.6.26 就遇到了一个 Intel 显卡下的,系统休眠不可用的BUG,找了很久,开始还以为是编译内核的时候参数搞错,但是编译了3次之后问题依然…… 就要想回退到 2.6.25 的时候,想到可能是一个BUG,结果真的找到了。应用这个补丁即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
index 36af01f..130711f 100644
--- a/arch/x86/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep.c
@@ -23,6 +23,15 @@ static unsigned long acpi_realmode;
 static char temp_stack[10240];
 #endif
 
+/* XXX: this macro should move to asm-x86/segment.h and be shared with the
+   boot code... */
+#define GDT_ENTRY(flags, base, limit)      \
+   (((u64)(base & 0xff000000) << 32) | \
+    ((u64)flags << 40) |           \
+    ((u64)(limit & 0x00ff0000) << 32) |    \
+    ((u64)(base & 0x00ffffff) << 16) | \
+    ((u64)(limit & 0x0000ffff)))
+
 /**
  * acpi_save_state_mem - save kernel state
  *
@@ -58,11 +67,11 @@ int acpi_save_state_mem(void)
            ((char *)&header->wakeup_gdt - (char *)acpi_realmode))
                << 16);
    /* GDT[1]: real-mode-like code segment */
-   header->wakeup_gdt[1] = (0x009bULL << 40) +
-       ((u64)acpi_wakeup_address << 16) + 0xffff;
+   header->wakeup_gdt[1] =
+       GDT_ENTRY(0x809b, acpi_wakeup_address, 0xfffff);
    /* GDT[2]: real-mode-like data segment */
-   header->wakeup_gdt[2] = (0x0093ULL << 40) +
-       ((u64)acpi_wakeup_address << 16) + 0xffff;
+   header->wakeup_gdt[2] =
+       GDT_ENTRY(0x8093, acpi_wakeup_address, 0xfffff);
 
 #ifndef CONFIG_64BIT
    store_gdt((struct desc_ptr *)&header->pmode_gdt);

upgrade to kernel 2.6.26

Linux 2.6.26 内核

Linux 2.6.26 内核

升级到了最新的内核版本,据说内核版本号规则要换了……