Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
shihongzhi / grep98list.py
Created May 20, 2012 12:04
把cc98的中包含的网址抓取下来,保存在tempurl2.txt中
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
@shihongzhi
shihongzhi / grep98topdf.py
Created May 20, 2012 12:00
抓取cc98上面的帖子内容,然后保存为pdf。帖子列表由tempurl2.txt导入。使用到的库为urllib2和BeautifulSoup
#-*- 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
@shihongzhi
shihongzhi / radix_sort.c
Created April 4, 2012 13:09
基数排序
//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;
//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)
{
#include <stdio.h>
#include <string.h>
//排列,用的是非递归方法,即2进制方法
char letter[] = "abcdefg";
int main()
{
int number = 1<<7;
int index, cur;
#include <stdio.h>
int remove_multiple_spaces(char str[]){
char *result;
char *cur;
result = cur = str;
while (*cur) {
if (*cur==' ') {
*result++ = *cur++;
while (*cur == ' ') {
@shihongzhi
shihongzhi / BoundedPQueue.h
Created March 27, 2012 08:39
BoundedPQueue.h Bounded Priority Queue
#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{
@shihongzhi
shihongzhi / BoundedPQueue.h
Created March 27, 2012 08:39
BoundedPQueue.h Bounded Priority Queue
#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{
@shihongzhi
shihongzhi / Singleton.h
Created March 27, 2012 08:14
Singleton
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主要处理多重继承,及虚继承的情况地址的偏移量
@shihongzhi
shihongzhi / minQueue.h
Created March 27, 2012 07:44
minQueue.h
//通过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> >