Skip to content

Instantly share code, notes, and snippets.

View wcaleb's full-sized avatar

W. Caleb McDaniel wcaleb

View GitHub Profile
@wcaleb
wcaleb / frederick-douglass.html
Created November 10, 2012 21:22
An example blog post in HTML
<html>
<head>
<title>Mode for Caleb: The lives of Douglass: Part II</title>
<style type="text/css">
body{margin:0px;padding:0px;background:#fff;color:#000000;font:1.5em "Trebuchet MS",Verdana,Arial,Sans-Serif;font-size:13px;}
a{text-decoration:none; color:#C4372D;}
a:hover{border-bottom:solid 1px;}
#logo{padding:0px;margin:0px;}
div#mainClm{float:right;width:60%;padding:30px 7% 10px 3%;border-left:dotted 1px #000;border-right:dotted 1px #000;text-align:left;border-bottom:dotted 1px #000;}
div#sideBar{width:200px;margin:20px;padding-top:20px;padding-left:5px;padding-right:5px;text-align:left;}
@wcaleb
wcaleb / ocrpdf.sh
Created November 6, 2013 14:41
Take a PDF, OCR it, and add OCR Text as background layer to original PDF to make it searchable
#!/bin/sh
# Take a PDF, OCR it, and add OCR Text as background layer to original PDF to make it searchable.
# Hacked together using tips from these websites:
# http://www.jlaundry.com/2012/ocr-a-scanned-pdf-with-tesseract/
# http://askubuntu.com/questions/27097/how-to-print-a-regular-file-to-pdf-from-command-line
# Dependencies: pdftk, tesseract, imagemagick, enscript, ps2pdf
# Would be nice to use hocr2pdf instead so that the text lines up with the PDF image.
# http://www.exactcode.com/site/open_source/exactimage/hocr2pdf/
@wcaleb
wcaleb / getbibs.py
Last active April 4, 2022 15:36
The Pandoc filter and shell script I use to make a bibliography file from my BibTeX note files. See http://wcm1.web.rice.edu/plain-text-citations.html
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Pandoc filter that grabs the BibTeX code block from each note file
# and then uses bibtexparser to add a "short title" entry in the "note" field,
# appending finished BibTeX entry to a bibliography file.
from pandocfilters import toJSONFilter, CodeBlock
# https://github.com/sciunto/python-bibtexparser
import bibtexparser
@wcaleb
wcaleb / wayback.py
Last active January 16, 2021 22:55
Pandoc filter to replace Link URLs with Wayback Machine URLs
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# Usage: pandoc --filter=wayback.py input
# Install pandocfilters and requests with pip before using
# Warning: may take a while to process input with lots of links
# Note: Links that can't be saved to WBM or already point to WBM are left as is
from pandocfilters import toJSONFilter, Link
import requests
@wcaleb
wcaleb / duesoon.sh
Created May 15, 2012 15:54
A shell script to remind me of tasks that are due soon, using this system: http://wcm1.web.rice.edu/plain-text-gtd.html
#!/bin/sh
TODAY=$(date +%m)
FILE=~/.duesoon
# This may be more complex than need be, but it permits months with or without leading zeroes
let THISMO=$TODAY-0
if [ $THISMO = 12 ]; then
let NEXTMO=01
else
@wcaleb
wcaleb / docvert.py
Created April 28, 2013 19:43
Wrapper script for sending documents to Docverter.com using standard python libraries.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
## docvert.py
## by W. Caleb McDaniel
## http://wcm1.web.rice.edu
## This is a wrapper script for sending documents to Docverter
## for conversion from markdown to PDF. It offers a python
## alternative to using cURL. For more information, see:
@wcaleb
wcaleb / iMDtoPDF.py
Last active December 29, 2020 07:52
iMDtoPDF
#! /usr/bin/env python
# -*- coding: utf-8 -*-
## iMDtoPDF.py
## by W. Caleb McDaniel
## http://wcm1.web.rice.edu
## This is a wrapper script for sending documents to Docverter
## for conversion from markdown to PDF using Pandoc. Typically
## Docverter calls are made with cURL; this script uses httplib.
@wcaleb
wcaleb / GrandmaPics.py
Last active December 29, 2020 07:48
GrandmaPics
# Clear console
import console
console.clear()
print "Tap a photo to fetch a new one!"
print "Finding cute grandkid photos ..."
from scene import *
import urllib2
import random
@wcaleb
wcaleb / inlinenotes.py
Last active December 29, 2020 06:59
Pandoc filter to convert all notes to inline notes in Pandoc Markdown output
#!/usr/bin/env python
from pandocfilters import toJSONFilter, RawInline, Space, Str, walk
"""
Pandoc filter for Markdown that converts most endnotes into
Pandoc's inline notes. If input notes had multiple paragraphs,
the paragraphs are joined by a space. But if an input note
had any blocks other than paragraphs, the note is left as is.
"""
@wcaleb
wcaleb / waybackup.py
Last active December 29, 2020 06:55
Quick script to save URL to Wayback Machine
#! /usr/bin/env python
import sys, requests
# Usage: Pass URL to script, get back URL to Wayback Machine snapshot
base_url = 'http://web.archive.org'
r = requests.get(base_url + '/save/' + sys.argv[1])
if r.status_code == requests.codes.ok: