Skip to content

Instantly share code, notes, and snippets.

@waylan
waylan / foo.sh
Created November 15, 2012 18:39
Simple bash subcommands. Each subcommand is implemented as a function. For example, `sub_funcname` is called for `funcname` subcommand.
#!/bin/sh
ProgName=$(basename $0)
sub_help(){
echo "Usage: $ProgName <subcommand> [options]\n"
echo "Subcommands:"
echo " bar Do bar"
echo " baz Run baz"
echo ""
@waylan
waylan / bat_python_and_errors.bat
Created November 28, 2012 18:10
How to stop cmd window from closing when running a script from a bat file. This way, you can read any errors and simple hit [enter] when you are done and the window will close then.
C:\Python27\python.exe myscript.py
set /p variable= "Hit enter to continue"
@waylan
waylan / creating-project-pages-using-git-subtree.md
Last active March 8, 2022 09:30
Use subtree to merge commits from a project subdir (i.e., 'docs/') to gh-pages branch.

Creatings Project Pages using git-subtree

Many projects maintain their documentation within a subfolder of their repository (for example docs/). That way, as new features are added or existing features are modified, the documentation can be updated in the same commit. The git-subtree command can be an effective tool to merge those changes from the documentation subdirectory of your project to the root of the gh-pages branch.

Setup

According to the author of git-subtree, the command is included with git 1.7.11 and higher. However, it's in the "contrib" subtree for now, so it's not installed by default. Search for "git-subtree" in your system's package manager and install the package if it exists. If not, or if you are using an older version of git, the easiest way is to install git-subtree from the author's repo.

$ git clone https://github.com/apenwarr/git-subtree.git
@waylan
waylan / mdx_rss.py
Created February 12, 2013 21:03
An extension to Python-Markdown that outputs a markdown document as RSS.
"""
RSS Extension
=============
Summary
-------
An extension to Python-Markdown that outputs a markdown document as RSS.
Each item in the RSS document is the content following a heading (`<h1-6>`)
with the "title" being the heading itself.
from xml.etree import ElementTree as etree
class _ElementInterface(etree._ElementInterface):
""" Add a 'parent' property to ElementTree Elements. Defaults to None. """
parent = None
etree._ElementInterface = _ElementInterface
def SubElement(parent, tag, attrib={}, **extra):
""" Replace SubElement factory func with one that also sets an Element's parent. """
@waylan
waylan / html_tidy.py
Created March 13, 2013 14:28
Archive of the Python-Markdown HTML Tidy Extension.
# HTML Tidy Extension for Python-Markdown
# =======================================
#
# Runs [HTML Tidy][] on the output of Python-Markdown using the [uTidylib][]
# Python wrapper. Both libtidy and uTidylib must be installed on your system.
#
# [HTML Tidy]: http://tidy.sourceforge.net/
# [uTidylib]: http://utidylib.berlios.de/
#
# Note than any Tidy [options][] can be passed in as [extension configs][]. So,
@waylan
waylan / knockback-relations.html
Created April 29, 2013 16:52
An attempt at backbone-relational with knockback. Not sure why this isn't working. What am I missing?
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Sample</title>
<link rel="stylesheet" href="base.css">
</head>
<body>
@waylan
waylan / .vimrc
Created August 13, 2013 16:12
A very basic .vimrc file
" whitespace
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set softtabstop=4
set autoindent
" Search settings
set incsearch
@waylan
waylan / sqlite_pivot_tables.md
Last active November 17, 2022 08:43
Sqlite pivot tables.

Given the following table:

CREATE TABLE "venue" 
(
    "id" INTEGER NOT NULL PRIMARY KEY, 
    "name" VARCHAR(255) NOT NULL
);

INSERT INTO "venue" ("name") VALUES ('V1');
@waylan
waylan / foo.py
Created December 12, 2014 14:14
Class in which only one instance of each subclass can exist in a set. Not sure if there is a better way to do this, but it works. Although I don't like that overriding `__eg__` breaks other things.
class Foo(object):
def __hash__(self):
return hash('.'.join([self.__class__.__module__, self.__class__.__name__]))
def __eq__(a, b):
return a.__hash__() == b.__hash__()
class Bar(Foo):