Skip to content

Instantly share code, notes, and snippets.

@swshan
swshan / lg.java
Created March 6, 2017 09:38
算法4书本练习 1.1.14
import java.util.*;
// 给一个N的正帧数 返回不大于Log2N的最大整数
public class Log {
public static int lg(int N) {
double log2n = N / 2; // base is 2
int result = 1;
while ( result < log2n) {
@swshan
swshan / Rectangle.java
Created February 15, 2017 09:00
Java 练习
package Rectangle;
class myRectangle {
double width = 1.0;
double height = 1.0;
myRectangle() {
}
#coding: utf-8
__author__ = "swsend"
import json
import hashlib
import datetime
from flask import Flask, request, jsonify, Response, render_template
@swshan
swshan / flask.url
Created August 17, 2016 08:56
flask 实现子域名
# -*- coding: utf-8 -*-
from flask import Flask, Blueprint, request
app = Flask(__name__)
app.config.DEBUG = True
#app.url_map.default_subdomain = 'www'
app.config['SERVER_NAME'] = 'example.com'
@swshan
swshan / exerices.000.py
Created August 16, 2016 08:31
实现一个装饰器
def simple_decorator(f):
def wrapper():
print "Entering Function"
f()
print "Exit"
return wrapper
#!/usr/bin/env python
# encoding: utf-8
import os
import time
import logging
import hashlib
from sqlalchemy import create_engine, ForeignKey, Column, Integer, String, Text, DateTime,\
#coding=utf-8
import urllib2
from bs4 import BeautifulSoup
def get(url):
req=urllib2.Request(url)
req.add_header("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
req.add_header("Referer",url)
req.add_header("Cookie","jyean=flVZbRitNuOM44i3VjCPjP93MgxEj24GZ8yvM6fZ9HM4MfiQXQP6_eTlsA1lvSOqypz4l1Dj8OV4X-1xEwkoKZ6P1SyGgiNtNxi3n50-q6H_cTMs3jTa8oHBA47MLuyU0; JYE_FP2=58f1a56e5f3cea7fd10be747461acba5; CNZZDATA2018550=cnzz_eid%3D562178188-1448873225-http%253A%252F%252Fwww.jyeoo.com%252F%26ntime%3D1448873225")
import requests
import random
def getproxy():
foo = ['124.200.33.146:8118', '112.90.72.83:80']
rand = random.choice((foo))
''' Get a dict format proxy randomly '''
proxy= rand
@swshan
swshan / crawler.r10.py
Last active January 13, 2016 04:41
my task data crawler reversion 10, add reds
# -*- coding:utf-8 -*-
"""
Date 16-Jan-3q lastest progres
"""
#from __future__ import print_function
import gevent
from gevent import monkey
# -*- coding:utf-8 -*-
"""
Date 16-Jan-3q lastest progres
"""
#from __future__ import print_function
import gevent
from gevent import monkey