Skip to content

Instantly share code, notes, and snippets.

@darkfeline
darkfeline / ext_ctags.py
Last active December 20, 2015 01:08 — forked from shimizukawa/ext_ctags.py
Fixed for Python 3. Plop in sphinx/ext and enable the extension in the config.
# -*- coding: utf-8 -*-
import os
def doctree_resolved(app, doctree, docname):
filename = os.path.join(app.confdir, app.config.ctags_filename)
# load existent ctag
ctags = load_ctag(filename)
@darkfeline
darkfeline / vimwiki-diary-convert.py
Created October 11, 2013 17:24
Convert vimwiki diary format to Emacs Org-Journal format
import datetime
import os
time = datetime.time(tzinfo=datetime.timezone(datetime.timedelta(0)))
time = time.strftime("%H:%M:%S %z")
for entry in os.listdir():
if not entry.endswith(".py"):
date = datetime.date(int(entry[:4]), int(entry[4:6]), int(entry[6:]))
date = date.strftime("%Y-%m-%d %a")
@darkfeline
darkfeline / tclean
Last active August 29, 2015 14:00
Script to clean taskwarrior expired task templates
#!/usr/bin/env python
import subprocess
import os
FILE = os.environ['HOME'] + '/.task/pending.data'
x = subprocess.check_output([
'task', 'status:recurring', 'until.before:today', 'ids'])
x = x.decode().rstrip()
@darkfeline
darkfeline / convert.py
Created May 12, 2014 05:30
Half-hearted dokuwiki to kramdown converter
import os
import re
p_heading = re.compile(r'(=+) (.*?) =+')
p_code = re.compile(r'</?code>')
p_link = re.compile(r'\[\[([^|\]]+)\|([^\]]+)\]\]')
p_inlink = re.compile(r'\[\[([^|\]]+)\]\]')
files = [x for x in os.listdir() if x.endswith('.txt')]
for x in files:
@darkfeline
darkfeline / switch.py
Created June 1, 2014 03:46
Python switch-case
class SwitchCase:
"""
Simple implementation of switch-case statements in Pythonic style.
>>> switch = SwitchCase()
Adding case handlers:
>>> @switch.case('foo')
<br />
<h1>Heading one</h1>
<h2>Header two</h2>
<h3>Header three</h3>
<h4>Header four</h4>
<h5>Header five</h5>
<h6>Header six</h6>
<p>This is a copy of one of the sample pages from the <a href="http://www.wordpress.org" onclick="_gaq.push(['_trackEvent', 'outbound-article', 'http://www.wordpress.org', 'WordPress']);" >WordPress</a> theme development test content. I found it handy to keep a copy of this for building sites that aren’t using WordPress. 99% of the credit goes to them, I’m just hosting it in a handy place in case it’s useful to anyone other than me.</p>
<h2>Blockquote Tests</h2>
<p>Blockquote:</p>
@darkfeline
darkfeline / multimethods.py
Last active August 29, 2015 14:08
Python multimethods (Clojure style)
class MultiMethod:
def __init__(self, func):
self.func = func
self.methods = {}
def __call__(self, *args, **kwargs):
return self.methods[self.func(*args, **kwargs)](*args, **kwargs)
def method(self, case):
@darkfeline
darkfeline / use-package-delight.el
Last active August 29, 2015 14:17
Delight plugin for use-package.el
(use-package delight)
(add-to-list 'use-package-keywords :delight t)
(defun use-package-normalize/:delight (name-symbol keyword args)
"Normalize arguments to delight."
(cond
((and (= (length args) 1)
(symbolp (car args)))
(list (car args) nil name-symbol))
@darkfeline
darkfeline / star.py
Last active November 11, 2016 09:33
Print star (Python one line)
#!/usr/bin/env python3
(lambda sys:(lambda input:(lambda ilen:(lambda m,olen:(lambda star:(lambda f,g:None)(list(map(lambda i:(lambda b:list(map(lambda x,y: star[x].__setitem__(y,input[i]),[i,b,m,m,i,i,b,b],[m,m,i,b,i,b,i,b])))(olen-i-1),range(ilen))),print("\n".join("".join(char for char in row) for row in star))))([[" " for x in range(olen)] for x in range(olen)]))(ilen-1,2*ilen-1))(len(input)))(sys.argv[1]))(__import__('sys'))
@darkfeline
darkfeline / star.lisp
Created December 16, 2015 01:19
Print star
(defun star (input)
"Make star."
(let* ((l (length input))
(lo (- l 1))
(ll (- (* 2 l) 1))
(star (make-array (list ll ll) :initial-element #\Space)))
(dotimes (i l)
(let ((a (+ 0 i))
(b (- ll i 1)))
(map nil (lambda (x y) (setf (aref star x y) (aref input i)))