This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "include.hpp" | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <vector> | |
using std::cout; | |
using std::endl; | |
using std::string; | |
using std::ifstream; | |
using std::ofstream; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scrapy | |
class CsxCourseSpider(scrapy.Spider): | |
name = "csx" | |
start_urls = ['https://www.scrumalliance.org/courses-events/course.aspx?pageCount=50&country=&state=&city=&zip=&type=Csd;&trainer=&language=&startdate=5/15/2017%2012:00:00%20AM&enddate=1/1/1900%2012:00:00%20AM&discount=False&page=1&orderby=StartDate&sortdir=asc&radius=0&view=map'] | |
# https://www.scrumalliance.org/courses-events/courses/csd/us/ohio/columbus/2017/may/201702145-csd | |
def parse(self, response): | |
# print '}}}}}}}}', response.url, response.xpath('*//tr') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scrapy | |
class BookSpider(scrapy.Spider): | |
name = "books" | |
start_urls = ['http://books.toscrape.com/'] | |
def parse(self, response): | |
for book in response.css('article.product_pod'): | |
name = book.xpath('./h3/a/@title').extract_first() | |
price = book.css('p.price_color::text').extract_first() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# -*- coding: UTF-8 -*- | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def predict(input_vec, f): | |
# print (input_vec, W) | |
return f(np.dot(input_vec, W)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def balance_recurse(chars, cnt=0): | |
if len(chars) == 0: return cnt == 0 | |
if chars[0] == '(': cnt += 1 | |
if chars[0] == ')': cnt -= 1 | |
return cnt >= 0 and balance(chars[1:], cnt) | |
PARENS = (('(', ')'), ('[', ']'),) | |
def balance_recurse_mul(chars, cnt=[0]*len(PARENS)): | |
if len(chars) == 0: return all(map(lambda b: b==0, cnt)) | |
for i, paren in enumerate(PARENS): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
TIMES = 10000 | |
def once(acc=0, days=0): | |
return days if acc >= 20 else once(acc + random.choice(xrange(1,7)), days + 1) | |
s1 = [once() for i in xrange(TIMES)] | |
s1.sort() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/python | |
# -*- coding: utf-8 -*- | |
import subprocess, time | |
# 程序执行终止时间为当前时刻延迟N秒 | |
stoptime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()+60)) | |
def main(command): | |
popen = subprocess.Popen( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://codingstyle.cn/topics/202 | |
def f(n, p=2): | |
if n < 2: return [] | |
if n % p == 0: return [p] + f(n/p, p) | |
return f(n, p+1) | |
assert [2,2,3,3,3,5,5,19] == f(2*2*3*3*3*5*5*19) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !encoding=utf8 | |
# primes = filterPrime [2..] | |
# where filterPrime (p:xs) = | |
# p : filterPrime [x | x <- xs, x `mod` p /= 0] | |
# Infinite List | |
from pipe import * | |
from pipe import itertools | |
def primes(xs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! encoding=utf8 | |
import unittest | |
def maxProfit(prices): | |
if not prices: | |
return 0 | |
currBuy = -prices[0] #表示当天最终未持股的情况下,当天结束后的累计最大利润 | |
currSell = 0 #表示当天最终持股的情况下,当天结束后的累计最大利润 |