Skip to content

Instantly share code, notes, and snippets.

View xiaom's full-sized avatar
:octocat:

Xiao Meng xiaom

:octocat:
  • Goldsky
  • Canada
  • 09:43 (UTC -07:00)
View GitHub Profile
@xiaom
xiaom / BFS.py
Created November 28, 2011 17:18
BFS
"""BFS.py
Breadth First Search. See also LexBFS.py.
D. Eppstein, May 2007.
"""
try:
set
except NameError:
@xiaom
xiaom / access.cc
Created February 12, 2012 06:41
check if a file exists
#include <unistd.h>
// Check whether file exist
// http://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c-cross-platform
if( access( fname, F_OK ) != -1 ) {
// file exists
} else {
// file doesn't exist
}
@xiaom
xiaom / call_command.py
Created February 13, 2012 08:09
call command from python
import subprocess
def call_command(command):
process = subprocess.Popen(command.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return process.communicate()
# An example
if __name__ == "__main__":
@xiaom
xiaom / is_number.py
Created February 23, 2012 04:01
check if a string is number
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
@xiaom
xiaom / NoFloatException.cpp
Created February 23, 2012 23:53
float point exception
// see http://www.johndcook.com/IEEE_exceptions_in_cpp.html for details
bool IsNumber(double x)
{
// This looks like it should always be true,
// but it's false if x is a NaN.
return (x == x);
}
#include <float.h>
@xiaom
xiaom / graphics.tex
Created February 28, 2012 19:24
include graphics
\begin{figure}[htbp]
\begin{minipage}[b]{0.5\linewidth}
\label{SzvsT}
\centering
\includegraphics[width=\textwidth]{fig/SzvsT.pdf}
\caption{initial node set size $|V_Q|$ versus runing time}
\end{minipage}
\vspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\label{RvsTime}
@xiaom
xiaom / myfullpage.sty
Created May 14, 2012 19:16
page style of latex
\marginparwidth 0pt
\oddsidemargin 0pt
\evensidemargin 0pt
\marginparsep 0pt
\parindent 0pt
\parskip 5pt
\topmargin 0pt
@xiaom
xiaom / gist:2722102
Created May 17, 2012 22:44
make file for pandoc to latex
draft:
pandoc -N --latex-engine=xelatex --template=template.tex def.markdown -o def.pdf --biblio def.bib
final:
pandoc -N --latex-engine=xelatex --template=template.tex def.markdown -o def.tex --biblio def.bib
bibtex def
xelatex def.tex
xelatex def.tex
@xiaom
xiaom / setfont.tex
Created May 21, 2012 23:34
set font in latex
\usetheme{default}
\usepackage{mathpazo}
\usepackage{fontspec}
\setbeamertemplate{background canvas}{\includegraphics [width=\paperwidth]{blackboard_bk.pdf}}
\newfontfamily\chalkd{Chalkduster.ttf}
\newfontfamily\chalkb{Chalkboard.ttc}
\setbeamerfont*{normal text}{family = \chalkd}
\setbeamerfont{alerted text}{family = \chalkd}
\setbeamerfont{structure}{family = \chalkd}
@xiaom
xiaom / alg.tex
Created June 2, 2012 17:31
algorithm2e template
\begin{figure}
% Manual: http://bit.ly/N5qECH
\begin{algorithm}[H]
\caption{$\textsc{AlgName}$}
\label{alg:foobar}
\SetAlFnt{\tiny \sf}
\SetCommentSty{textrm}
\SetKwComment{Comment}{~$\triangleright$~}{}