1957

无聊蛋疼的1957写的低端博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年5月14日

摘要: 果断使用BeautifulSoup!- -不想写了,挺简单的,贴个代码 1 import urllib2 2 import chardet 3 from BeautifulSoup import BeautifulSoup 4 import pymongo 5 import time 6 db = pymongo.Connection().notice #user notice 7 8 def load_work(): 9 return db.work.find()10 def work_insert(data):11 db.work.insert(data)12 def u... 阅读全文

posted @ 2013-05-14 22:07 1957 阅读(861) 评论(0) 推荐(0) 编辑

2013年5月3日

摘要: jsonp和ajax木有啥关系!实现方法完全不一样。ajax的核心是通过XmlHttpRequest获取非本页内容,而jsonp的核心则是动态添加<script>标签来调用服务器提供的js脚本。怎么说呢,因为jQuery的原因,我一直以为就是个ajax调用。 $(document).ready(function(){ $.ajax({ type: "GET", dataType: "JSONP", url: "http://contests.acmicpc.info/c... 阅读全文

posted @ 2013-05-03 15:09 1957 阅读(831) 评论(1) 推荐(0) 编辑

2013年4月9日

摘要: 这个是常识!在request header里面加个gzip!可以大大的节约带宽。感谢来神在群聊天的时候说到这个。详情参见 wiki把昨天写的解析中关村在线的代码改了下/* Date: 2013-04-08 Author: FangYuhao*/var http = require('http');var iconv = require('iconv-lite');var cheerio = require('cheerio');var zlib = require('zlib');url = 'http://detail. 阅读全文

posted @ 2013-04-09 21:43 1957 阅读(1240) 评论(0) 推荐(0) 编辑

2013年4月7日

摘要: node写爬虫真的很不错,node天生异步,把这写异步的都省了。前几天项目需要,求爬了点易迅网的评价。先在http://item.51buy.com/item-{id}.html上面获取物品名称,主要就是title然后获取评价的分布http://item.51buy.com/json.php?mod=review&act=getproperty&jsontype=str&pid=id最后在http://item.51buy.com/json.php?mod=review&act=getreviews&jsontype=str&type=allre 阅读全文

posted @ 2013-04-07 11:16 1957 阅读(2098) 评论(0) 推荐(1) 编辑

2013年4月6日

摘要: 之前看的谁出的面试题来着。不太记得了。不过今天水微软的编程之美第一题的时候我用了split,所以就实现了一个。当然可能还不满足那个面试题的要求,因为我只是用了istringstream而已。先写在这儿吧,过两天再来做那个面试题。std::vector<std::string>& split(const std::string& ori , char ch , std::vector<std::string>& ans){ std::istringstream iss(ori); std::string item; while(std::getli 阅读全文

posted @ 2013-04-06 16:18 1957 阅读(1808) 评论(0) 推荐(0) 编辑

2013年3月3日

摘要: 就是每个元素取还是不取!combinations :: Int -> [a] -> [[a]]combinations _ [] = [[]]combinations 0 _ = [[]]combinations k (x:xs) = x_start ++ others where x_start = [x:rest | rest <- combinations (k - 1) xs] others = if k <= length xs then combinations k xs else []*Main> combinations 3 "abced 阅读全文

posted @ 2013-03-03 16:11 1957 阅读(155) 评论(0) 推荐(0) 编辑

2013年2月21日

摘要: 今天又继续多年没看的haskell了想起之前看书时候提到的foldr可以用于无穷序列,而foldl不行。一般情况下foldl效率比foldr高。之前一直没怎么理解。myfoldl f z [] = zmyfoldl f z (x:xs) = myfoldl f (f z x) xsmyfoldr f z [] = zmyfoldr f z (x:xs) = f x (myfoldr f z xs)自己实现了一下,明显就可以看出myfoldl是一个尾递归,所以效率高myfoldr在某些运算,比如and 运算,在x为false就可以结束了。所以在某种情况下myfoldr可以用于无穷序列{- dat 阅读全文

posted @ 2013-02-21 21:54 1957 阅读(334) 评论(0) 推荐(0) 编辑

2013年1月24日

摘要: We often see the symbol extern "C" in C++ source files.Why use this?Because C++ has overload function property like:f(int i) //definesf__Fif(int i ,char* j)//definesf__FiPcWhen we link in other fileextern f(int); // refers to f__FIextern f(int,char*) // refers to f__FiPcBut the C programmi 阅读全文

posted @ 2013-01-24 21:29 1957 阅读(163) 评论(0) 推荐(0) 编辑

2013年1月22日

摘要: #include <iostream>class TT{ public: int a; TT(){a=0;} TT(int xa){a=xa;} TT(const TT& xa){a=xa.a;} operator int(){return a;} //hidden convert TT to int operator char(){return 48+a;} void operator()(){std::cout<<"xyz"<<std::endl;} //functor};int main(){ TT a; TT b(2); 阅读全文

posted @ 2013-01-22 20:27 1957 阅读(131) 评论(0) 推荐(0) 编辑

2013年1月18日

摘要: Union is a datatype in c/c++, but rarely used in practice, because I almost think the memory is enough now, don't need such trick. Recently I have read the source code of NFA , using union very beautiful.Wen construct a NFA , we have a pushdown stack , record the NFA fragment had been constructe 阅读全文

posted @ 2013-01-18 10:50 1957 阅读(186) 评论(0) 推荐(0) 编辑