Skip to content

Instantly share code, notes, and snippets.

View Answeror's full-sized avatar

Cosmo Du Answeror

View GitHub Profile
@Answeror
Answeror / fseq.cpp
Created July 7, 2012 08:40
作业三(基本要求)
#include <fstream>
#include <algorithm>
#include <iterator>
namespace mine
{
typedef std::fstream* stream_ptr;
typedef std::size_t pos_type;
typedef std::ptrdiff_t difference_type;
typedef char value_type;
@Answeror
Answeror / settings.py
Created July 24, 2012 12:38
QSettings wrapper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: settings
:synopsis: Provide Settings class.
.. moduleauthor:: Answeror <[email protected]>
"""
@Answeror
Answeror / vector.css
Created August 31, 2012 12:27
Wikipedia custom CSS
body {
font-size: 1.2em;
}
#bodyContent, #firstHeading {
max-width: 800px;
margin: auto;
}
@Answeror
Answeror / fetch.py
Created September 16, 2012 05:22
程序员的爱情表白
# 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')
@Answeror
Answeror / gist:3741730
Created September 18, 2012 07:10
Make two image height equal
% 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%
@Answeror
Answeror / gist:3775675
Created September 24, 2012 12:19
deterministic testing with numpy.random.
from numpy import random
from numpy.random import rand
class TestRandomly(object):
def setUp(self):
self.state = random.get_state()
random.seed(0)
@Answeror
Answeror / gist:3832085
Created October 4, 2012 08:02
Activate virtualenv in blender
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'))
@Answeror
Answeror / decode.py
Created October 9, 2012 01:59
Python3 try decode.
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.')
@Answeror
Answeror / current_time.cpp
Created May 13, 2013 06:09
Get total seconds since 1970-01-01, millisecond precision.
#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;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.