Skip to content

Instantly share code, notes, and snippets.

@kroger
kroger / url2pdf.py
Created April 1, 2012 18:57
Download a webpage, clean it and generate a pdf using htmldoc
#!/usr/bin/env python
import os
import subprocess
from lxml import html
from lxml.html import builder as E
from lxml.html.clean import clean_html
url = "http://dangerousprototypes.com/docs/Bus_Blaster"
@kroger
kroger / layout.html
Created July 31, 2012 01:21
Layout for epub style for Sphinx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset={{ encoding }}"/>
{{ metatags }}
{%- block htmltitle %}
@kroger
kroger / epub2.py
Created July 31, 2012 02:05
Custom Epub builder for Sphinx
import os
import shutil
from sphinx.builders.epub import EpubBuilder
# We subclass EpubBuilder and re-define build_epub to call
# clean_html_file_for_ibooks. This function replaces all instances of
# the SPAN tag to SAMP. It's uglish but it works. A better way would
# be to change sphinx.writers.html to emmit the SAMP tag in the first
# place, but it seems even more difficult to do.
@kroger
kroger / gist:3258837
Created August 4, 2012 17:20
Include pdf pages in LaTeX document
\newcommand{\pdfinclude}[2]{
\foreach \i in {#2}{
\includegraphics[scale=.80,page=\i]{#1}\pagebreak\par
}
}
\pdfinclude{pdf_file}{1,2,3,4,5,6,7}
@kroger
kroger / gist:3856749
Created October 9, 2012 05:14
Show code examples in Sphinx
from __future__ import division
import os
import sys
import codecs
import textwrap
from StringIO import StringIO
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.directives.code import LiteralInclude
from sphinx.util.nodes import set_source_info
@kroger
kroger / gist:3856821
Created October 9, 2012 05:38
autoimage for Sphinx
import os
from docutils import nodes
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.images import Image
def find_image(path, filename):
fname = os.path.join(path, filename)
if os.path.exists(fname + '.pdf'):
return fname + '.pdf'
@kroger
kroger / gist:3856835
Created October 9, 2012 05:41
Example of Sphinx conf.py
# -*- coding: utf-8 -*-
import sys, os
sys.path.insert(0, os.path.abspath('extensions'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo',
'sphinx.ext.coverage', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig',
'epub2', 'mobi', 'autoimage', 'code_example']
@kroger
kroger / gist:3856845
Created October 9, 2012 05:45
The LaTeX style file used in Music for Geeks and Nerds
\usepackage{wasysym}
\usepackage{moresize}
\usepackage{multicol}
\usepackage[Sonny]{fncychap}
\usepackage[margin=1in, paperwidth=6.69in, paperheight=9.61in]{geometry}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Minion Pro}
\setmonofont[Mapping=tex-text,Scale=0.85]{Inconsolata}
%\setmonofont[Mapping=tex-text,Scale=0.75]{DejaVu Sans Mono}
@kroger
kroger / Makefile
Created October 9, 2012 05:48
Makefile for Sphinx
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build -E
PAPER =
BUILDDIR = build
LATEX-BW = $(BUILDDIR)/latex-bw
@kroger
kroger / mobi.py
Created June 26, 2013 11:37
Mobi builder based on Sphinx's epub builder.
# -*- coding: utf-8 -*-
"""
sphinx.builders.mobi
~~~~~~~~~~~~~~~~~~~~
Build mobi files.
Originally derived from epub.py.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.