Skip to content

Instantly share code, notes, and snippets.

View dongguosheng's full-sized avatar

董国盛 dongguosheng

View GitHub Profile
@dongguosheng
dongguosheng / crawler.py
Last active August 2, 2017 09:21
A simple crawler based on requests and pyquery.
# -*- coding: utf-8 -*-
'''
1. Construct the url with num_iid, eg: http://a.m.tmall.com/i15110720150.htm, 15110720150 is the num_iid.
2. Get the html text.
3. Parse the img urls and insert the num_iid and img urls into sqlite.
'''
import requests
from pyquery import PyQuery as pq
@dongguosheng
dongguosheng / MyString.cpp
Last active December 31, 2015 06:19
A string class implemented to practice C++.
#include "MyString.h"
MyString::MyString(void) : capacity(INITIAL_CAPACITY), size(0)
{
s_ptr = new char[INITIAL_CAPACITY];
*s_ptr = '\0';
}
MyString::~MyString(void)
{
@dongguosheng
dongguosheng / quicksort.c
Last active December 29, 2015 15:29
A quicksort implementation collection in C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void qsort_last(int s[], int start_index, int end_index); //select the last element as the pivot
void qsort_first(int s[], int start_index, int end_index); //select the first element as the pivot
void qsort_mid(int s[], int start_index, int end_index); //select the middle element as the pivot
void qsort_rand(int s[], int start_index, int end_index); //select a random index's value as the pivot
void qsort_mot(int s[], int start_index, int end_index); //median of three partitioning + insertion sort
void qsort_clrs(int s[], int start_index, int end_index); //select the last element as the pivot, CLRS version
@dongguosheng
dongguosheng / test.py
Last active December 19, 2015 17:19
a simple threadpool in Python
import time
import threadpool
starttime = time.time()
def job(args):
print args[0]
print args[1]
def main():
@dongguosheng
dongguosheng / multi-threading_queue.py
Last active December 19, 2015 17:19
multi-threading with Queue in Python
import threading
import urllib
import Queue
import time
class Mythread(threading.Thread):
'''Download pictures.'''
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
@dongguosheng
dongguosheng / multi-threading_simple.py
Last active December 19, 2015 17:19
a simple multi-threading in Python
import threading
import urllib
import time
class Mythread(threading.Thread):
'''Download pictures.'''
def __init__(self, url):
threading.Thread.__init__(self)
self.url = url
print 'init thread.'