This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
from BeautifulSoup import BeautifulSoup | |
#判断是不是table,即是不是帖子目录了 | |
def isTable(url): | |
page = urllib2.urlopen(url) | |
soup = BeautifulSoup(page) | |
tdTags = soup('td', align='left', width='*') | |
if len(tdTags) <= 1: | |
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
import urllib2 | |
import time | |
import os | |
from BeautifulSoup import BeautifulSoup | |
from xhtml2pdf.default import DEFAULT_FONT | |
from xhtml2pdf.document import pisaDocument | |
from reportlab.pdfbase import pdfmetrics | |
from reportlab.pdfbase.ttfonts import TTFont |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//answer to <introduction to algorithms> 8.3-4 | |
//主要思想是进制设置为n,所以位数就为2 | |
int pow_int(int radix, int i) | |
{ | |
int result = 1; | |
if(i<0) | |
return -1; | |
while (i--) | |
{ | |
result *= radix; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//answer to google 2011 school interview at zju | |
int quick_partition(int array[], int start, int end) | |
{ | |
int x = array[end]; | |
int i = start - 1; | |
int tmp; | |
for (int j=start; j<end; ++j) | |
{ | |
if (array[j]<=x) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
//排列,用的是非递归方法,即2进制方法 | |
char letter[] = "abcdefg"; | |
int main() | |
{ | |
int number = 1<<7; | |
int index, cur; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int remove_multiple_spaces(char str[]){ | |
char *result; | |
char *cur; | |
result = cur = str; | |
while (*cur) { | |
if (*cur==' ') { | |
*result++ = *cur++; | |
while (*cur == ' ') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef BOUNDED_PRIORITY_QUEUE_H | |
#define BOUNDED_PRIORITY_QUEUE_H | |
#include <map> | |
#include <functional> | |
#include <limits> | |
#include <utility> | |
template<typename T, typename Comparator=std::less<T> > | |
class BoundedPQueue{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef BOUNDED_PRIORITY_QUEUE_H | |
#define BOUNDED_PRIORITY_QUEUE_H | |
#include <map> | |
#include <functional> | |
#include <limits> | |
#include <utility> | |
template<typename T, typename Comparator=std::less<T> > | |
class BoundedPQueue{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
class cSingleton | |
{ | |
static T* ms_Singleton; | |
public: | |
cSingleton( void ) | |
{ | |
assert( !ms_Singleton ); | |
int offset = (int)(T*)1 - (int)(cSingleton <T>*)(T*)1; //这里的offset主要处理多重继承,及虚继承的情况地址的偏移量 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//通过minStack.h来实现最小队列,使用两个minStack,来模拟minQueue | |
//当然可以直接实现minQueue,而非借助minStack | |
#ifndef MIN_QUEUE_H | |
#define MIN_QUEUE_H | |
#include "minStack.h" //see https://gist.github.com/2213736 | |
#include <functional> | |
//use two stack: new and old to simulate min_queue | |
template<typename T, typename Comparator=std::less<T> > |