Skip to content

Instantly share code, notes, and snippets.

@zlalanne
zlalanne / PDFMerge.py
Last active October 26, 2020 03:21
Python script to merge a folder of pdfs, can define order in list.txt contained within the directory
#!/usr/bin/env python
"""
Simple Python script that combines a folder of pdfs into a single
pdf. By default the pdfs are merged in alphabetical order and
only appear once. To change this create a "list.txt" file in the
directory with the pdfs to merge and list the order of the pdfs
to merge.
Ex list.txt:
doc2.pdf
@zlalanne
zlalanne / link.py
Created February 12, 2013 02:54
Python script to link files once deluge finishes downloading
@zlalanne
zlalanne / resume.tex
Last active July 9, 2021 03:48
My LaTeX Resume that uses moderncv
%% start of file `template.tex'.
%% Copyright 2006-2013 Xavier Danaux (xdanaux@gmail.com).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License version 1.3c,
% available at http://www.latex-project.org/lppl/.
\documentclass[11pt,a4paper,sans]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman')
\usepackage{tabularx}
@zlalanne
zlalanne / Python-AddingSpaces.py
Created May 31, 2013 15:21
Regex for adding spaces after '.' in long string
text = re.sub(r'\.([a-zA-z])', r'. \1', text)
@zlalanne
zlalanne / indent.py
Created June 4, 2013 23:29
Indents XML node in python
def indent(elem, level=0):
"""Add whitespace to xml document to increase readability
elem - root element to start the indention at
level - start level of indention
"""
i = "\n" + level*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
@zlalanne
zlalanne / Python-CDATA.py
Created June 5, 2013 05:48
Adds CDATA support to Python ElementTree
import xml.etree.ElementTree as ET
def CDATA(text=None):
element = ET.Element('![CDATA[')
element.text = text
return element
ET._original_serialize_xml = ET._serialize_xml
@zlalanne
zlalanne / HeadphonesID3Tags.py
Created July 27, 2013 21:59
Renames an existing directory of MP3s to the format accepted by the music application Headphones
from sys import argv
from sys import exit
from mutagen.easyid3 import EasyID3
import os
import shutil
def main():
@zlalanne
zlalanne / load_json.py
Last active December 25, 2015 07:29
Quick function to load json from a file in python
def load_json_data(json_filename):
"""
Load a *.json file into a Python dictionary
@param json_filename: path to the json file
@return: a dictionary containing the data
"""
json_file = open(json_filename)
json_data = json_file.read()
test_data = json.loads(json_data)
@zlalanne
zlalanne / dlfile.py
Last active December 25, 2015 13:09
Download a file using urllib2
def dl_file(url, directory=os.path.dirname(__file__), user=None, password=None, filename=None):
"""
Download a file from a url to a directory
@param url: url of a file
@param directory: directory to save the file into
@return: True if file was downloaded successfully, False otherwise
"""
# Disable the proxy
@zlalanne
zlalanne / node_text.py
Created December 10, 2013 18:58
Get the text of a node and all child nodes into a string
def get_node_text(root):
text = ""
if root.text:
text = root.text.strip()
for child in root:
text += get_node_text(child)
if root.tail: