This file contains 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 requests | |
from bs4 import BeautifulSoup as BS | |
import json | |
def gen(soup): | |
for tr in soup.select('tr'): | |
tds = tr.select('td.tdR4') | |
if len(tds) == 6: | |
yield tds[2].string, tds[3].string |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 <boost/date_time/posix_time/posix_time.hpp> | |
double current_time() | |
{ | |
using namespace boost::gregorian; | |
using namespace boost::posix_time; | |
const boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); | |
ptime time_t_epoch(date(1970,1,1)); | |
time_duration diff = now - time_t_epoch; |
This file contains 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 decode(bs, encodings=['utf-8', 'cp936', 'gbk', 'gb18030', 'big5', 'latin1']): | |
for en in encodings: | |
try: | |
return bs.decode(en) | |
except: | |
pass | |
raise RuntimeError('Decoding failed.') |
This file contains 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 activate_virtualenv(name): | |
"""Activate given virtualenv. | |
Virtualenv home folder is given by environment variable ``WORKON_HOME`` or | |
``~/Envs`. | |
""" | |
if 'WORKON_HOME' in os.environ: | |
home = os.environ['WORKON_HOME'] | |
else: | |
home = os.path.expanduser(os.path.join('~', 'Envs')) |
This file contains 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
from numpy import random | |
from numpy.random import rand | |
class TestRandomly(object): | |
def setUp(self): | |
self.state = random.get_state() | |
random.seed(0) |
This file contains 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
% from http://tex.stackexchange.com/a/13039 | |
\documentclass{article} | |
\usepackage{graphicx} | |
\newsavebox\IBoxA \newsavebox\IBoxB \newlength\IHeight | |
\newcommand\TwoFig[6]{% Image1 Caption1 Label1 Image2 ... | |
\sbox\IBoxA{\includegraphics[width=0.45\textwidth]{#1}} | |
\sbox\IBoxB{\includegraphics[width=0.45\textwidth]{#4}}% | |
\ifdim\ht\IBoxA>\ht\IBoxB | |
\setlength\IHeight{\ht\IBoxB}\else\setlength\IHeight{\ht\IBoxA}\fi% |
This file contains 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
# fetch jpgs from tuita | |
import urllib3 | |
from pyquery import PyQuery as pq | |
http = urllib3.PoolManager() | |
url = 'http://yokicharlotte.tuita.com/blogpost/23832258' | |
r = http.request('GET', url) | |
d = pq(r.data.decode('utf-8')) | |
imgs = d('.photo_group')('p.pic')('img') |