Skip to content

Instantly share code, notes, and snippets.

View jseanj's full-sized avatar
💭
I may be slow to respond.

Jseanj jseanj

💭
I may be slow to respond.
  • kwai
  • 中国 北京
View GitHub Profile
import urllib2
from BeautifulSoup import BeautifulSoup
import httplib
import urlparse
def httpExists(url):
host, path = urlparse.urlsplit(url)[1:3]
found = 0
try:
#coding:utf-8
'''
模拟登陆163邮箱并下载邮件内容
'''
import urllib
import urllib2
import cookielib
import re
import time
import json
@jseanj
jseanj / copyUI.py
Created September 2, 2013 10:19
会下载网页依赖的js, css, images,并将源html的路径修改为对应路径,依赖requests, 使用方法 python sitecopy.py http://www.baidu.com 如果想抓取需要登陆的页面,那么你可以先调用get_login_cookies, 这个函数的参数是一个dict, 这个dict不同的网站不同,你可以通过httpfox查看, 得到cookies后,将cookies传递给SiteCopy
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
copy the UI of site specified by user
"""
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# -*- coding: cp936 -*-
import urllib2
import md5
import base64
import json
import time
from urllib import quote_plus
def httpReady(url,data=None,cookie=None):
@jseanj
jseanj / careercup2.c
Created August 14, 2013 06:00
From http://www.careercup.com/question?id=4570783653298176 find the largest subarray with equal number of 0's and 1's. example 001010101 output:8
int maxSequenceCount( int a[], int n )
{
int count[2] = {0};
for( int i = 0; i < n; i++ )
{
count[ a[i] ]++;
}
int start = 0;
@jseanj
jseanj / 8_13_1.cpp
Created August 13, 2013 08:50
Given an array, with positive and negative integers, arrange it in such a way that, positive numbers occupy even positions and negative numbers occupy odd position. All the remaining extra positive or negative integers should be stored at the end of the array. Remember, the elements of the array should remain in the same order. EG: Input array {…
#include <iostream>
using namespace std;
void change(int*, int);
int main() {
cout << "hello" << endl;
int a[] = {1, -2, 3, -4, -5, -6, -7, 8, 9, 4, 10, 11, 12};
int len = sizeof(a)/sizeof(int);
@jseanj
jseanj / careercup1.cpp
Created August 13, 2013 03:22
From http://www.careercup.com/question?id=5172577290944512 Given an array write a function to print all triplets in the array which sum of 0. e.g: Input: Array = [-1, -3, 5, 4] output: -1, -3, 4
void printTriplet(const int a[], int n)
{
for( int x = 0; x < n ; x ++ )
{
for( int y = 0; y < n; y ++ )
{
result[x][y] = a[x] + a[y];
processed[x][y] = false;
}
@jseanj
jseanj / p1.c
Created August 12, 2013 10:06
A special type of tree is given, Where all leaf are marked with 0 and others are marked with 1. every node can have 0 or at most 2 nodes. Trees level order traversal is given give a algorithm to build tree from this traversal.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[]="0100111"; // string to be inserted
struct node { // tree to be formed
char c;
struct node *left,*right;
};
typedef struct node node;
void inorder(node *head)
the gist command test.
this is the first gist.