Skip to content

Instantly share code, notes, and snippets.

@kroger
kroger / gist:1035934
Created June 20, 2011 16:26
Create github repo using the API
curl -F 'login=name' -F 'token=yourtoken' http://github.com/api/v2/yaml/repos/create/ -F 'name=reponame
@kroger
kroger / gist:1035937
Created June 20, 2011 16:27
Remove html nodes with lxml
for node in nodes:
node.getparent().remove(node)
@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 / gist:1035962
Created June 20, 2011 16:39
Remove html elemment
import lxml.html
page = lxml.html.parse("final.html").getroot()
images = page.xpath("//img")
for node in images:
node.getparent().remove(node)
with open("out.html", 'w') as outhtml:
outhtml.write(lxml.html.tostring(page))
@kroger
kroger / convert.py
Created February 7, 2012 16:46
Rename wav files using frequency and pitch detection
#!/usr/bin/env python
import subprocess, os, glob
## Rename wav files using frequency and pitch detection:
## GTR_08.wav ---> automated pitch detection & file renaming ---> C - 130.81 Hz - GTR_08.wav
WAV_DIR = r"C:/Conversion"
AUBIO_DIR = r"C:/Conversion"
@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)
@kroger
kroger / gist:1813329
Created February 13, 2012 03:34
Download web page in Python with authentication
import urllib2, urllib
"""
secret = json.load(open(os.path.expanduser('~/.secret')))
opener = authenticate('http://mixergy.com/wp-login.php',
secret['mixergy']['username'],
mixergy['password'])
@kroger
kroger / setup-python.sh
Created February 13, 2012 23:28
Install Python 2.7 on Mac OS
#!/bin/sh
#set -e
PYTHON_VERSION=$(brew info python | grep -o "stable 2\.7\.\d" | awk '{print $2}')
function install_python {
brew install readline sqlite gdbm
brew install python --universal --framework
}
@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 / 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