Skip to content

Instantly share code, notes, and snippets.

@mydreambei-ai
mydreambei-ai / search.py
Last active February 6, 2019 13:31
 via search engine or baidu engine spider
from __future__ import print_function
from bs4 import BeautifulSoup as bs
import requests
import logging
from itertools import count
import time
from blinker import signal
from lxml.html.clean import Cleaner
from lxml.html import tostring, fromstring, iterlinks
from selenium import webdriver
@mydreambei-ai
mydreambei-ai / check_prime.py
Last active June 30, 2017 07:38
check less n primes (good, better methods)
import math
def tri_prime(n):
primes = [2]
def is_prime(number):
if number % 2 == 0: return False
for i in range(3, math.floor(number / 2) + 1):
if number % i == 0:
@mydreambei-ai
mydreambei-ai / urlparse.py
Created June 22, 2017 07:29
Python url parser
import re
class UrlParser(object):
def __init__(self, url):
self.url = url
self.schem = self.zone = self.domain = self.port = self.path = self.query = self.params = None
def parse(self):
match = re.match(r"((\w*)://)?([^:/\?]*):?(\d+)?(.*)?", self.url)
if match:
self.schem = match.group(2)
@mydreambei-ai
mydreambei-ai / compare_files_lines.py
Last active June 7, 2017 08:17
Compare files line by line like linux command comm
import argparse
"""
usage:
python compare_files_lines.py -a inter <file1> <file2> == comm -12 <file1> <file2>
python compare_files_lines.py -a union <file1> <file2> == comm <file1> <file2> | sed 's/[\t ]*//g'
python compare_files_lines.py -a diff <file1> <file2> == comm -23 <file1> <file2>
python compare_files_lines.py -a rdiff <file1> <file2> == comm -13 <file1> <file2>
python compare_files_lines.py -a sydiff <file1> <file2> == comm -3 <file1> <file2> | sed 's/[\t ]*//g'
@mydreambei-ai
mydreambei-ai / compare_files_lines.py
Created June 7, 2017 08:03
Compare files line by line like linux command comm
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--action", dest="action", required=True,
choices=["inter", "union", "diff", "sydiff", "rdiff"])
parser.add_argument(
"A", type=argparse.FileType("r"), help="the base file")
parser.add_argument(
"B", type=argparse.FileType("r")
@mydreambei-ai
mydreambei-ai / compare_files_lines.py
Created June 7, 2017 08:03
Compare files line by line like linux command comm
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--action", dest="action", required=True,
choices=["inter", "union", "diff", "sydiff", "rdiff"])
parser.add_argument(
"A", type=argparse.FileType("r"), help="the base file")
parser.add_argument(
"B", type=argparse.FileType("r")
@mydreambei-ai
mydreambei-ai / pycurl_mul_example.py
Created May 31, 2017 07:22
epoll and pycurl multiple example
import pycurl
import select
URLS = ["https://www.douban.com/", "http://mail.163.com", "http://www.sina.com.cn", "http://google.com"]
SOCKETS = set()
TIMEOUT = 10
epoll = select.epoll()
def start_timeout(msecs):
@mydreambei-ai
mydreambei-ai / compile.md
Created May 15, 2017 07:26
linux kernel comiple
@mydreambei-ai
mydreambei-ai / compile.md
Created May 15, 2017 07:26
linux kernel comiple
@mydreambei-ai
mydreambei-ai / compile.md
Created May 15, 2017 07:26
linux kernel comiple