Skip to content

Instantly share code, notes, and snippets.

@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:1035949
Created June 20, 2011 16:32
Baixa lattes
#!/bin/sh
initfile=~/.lattesrc
tmpdir=/tmp
function parse_init {
if [ -f $initfile ]
then
source $initfile
else
@kroger
kroger / autoimage
Last active February 4, 2016 17:38
.. autoimage:: notation3.png
:scale-html: 40
:scale-latex: 80
@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 / 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 / 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 / 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 / Makefile
Created February 18, 2012 05:35
Makefile for python projects
ENV = "full-dev"
.PHONY: tests coverage
tests:
. ${WORKON_HOME}/$(ENV)/bin/activate && autonose --console -x--with-color
coverage:
. ${WORKON_HOME}/$(ENV)/bin/activate && nosetests --with-coverage --cover-html
@kroger
kroger / test-contour.py
Created February 17, 2012 02:24
Test Contour on music21
notes1 = tinyNotation.TinyNotationStream("c4 d8 f g16 a g f#", "3/4")
notes2 = tinyNotation.TinyNotationStream("g4 a8 b c16 a b c#", "3/4")
c1 = contour.Contour(notes1)
c2 = contour.Contour(notes2)
c3 = contour.Contour([0, 3, 1, 2])
bach = corpus.parseWork('bach/bwv295')
soprano = bach.parts[0].flat.notes
c4 = contour.Contour(soprano)
@kroger
kroger / gist:1813260
Created February 13, 2012 03:20
Math and Music seminar
from itertools import combinations, product, permutations, chain
from math import factorial
import functools
import operator
def prod(seq):
"""Product of a sequence."""
return functools.reduce(operator.mul, seq, 1)