Skip to content

Instantly share code, notes, and snippets.

@correl
correl / rpc.py
Created April 29, 2013 21:18
Caching decorator (AOP?!)
def cached(key_formatstr):
def decorator(fn):
def wrapped(self, *args, **kwargs):
cache_key = key_formatstr.format(*args, **kwargs)
log.debug('Fetching cached value for {0}'.format(cache_key))
value = self.mc_get(cache_key)
if not value:
value = fn(self, *args, **kwargs)
log.debug('Storing cached value for {0}'.format(cache_key))
self.mc_set(cache_key, value)
@correl
correl / filter.php
Created November 13, 2013 13:53
Manipulating multidimensional data structures in PHP
<?php
class KeyError extends Exception {};
function filter_tree($tree, $fields) {
if (empty($fields))
{
return $tree;
}
$result = array();
@correl
correl / logerrors.py
Created March 28, 2014 14:58
Aggregate similar log file entries matching a search pattern
import sys
import argparse
from itertools import ifilter
from fuzzywuzzy import fuzz
MATCH_THRESHOLD = 90
def parse_file(filename, predicate=None):
with open(filename) as f:
return aggregate_errors(f, predicate)
@correl
correl / taffybar.hs
Last active October 3, 2016 18:53
Xmonad Configuration
import System.Taffybar
import System.Taffybar.Systray
import System.Taffybar.TaffyPager
import System.Taffybar.SimpleClock
import System.Taffybar.Widgets.PollingGraph
import System.Taffybar.Widgets.PollingBar
import System.Taffybar.Weather
import System.Taffybar.FreedesktopNotifications
import System.Taffybar.Battery
import System.Information.CPU
@correl
correl / org-capture.el
Created March 2, 2015 16:38
Org-Capture templates
(setq org-capture-templates
'(("j" "Journal Entry" plain
(file+datetree "~/org/journal.org")
"%U\n\n%?" :empty-lines-before 1)
("b" "Bookmark" entry
(file+headline "~/org/bookmarks.org" "Unsorted")
"* %^{Title}\n\n Source: %u, %c\n\n %i")
("w" "Log Work Task" entry
(file+datetree "~/org/coredial/worklog.org")
"* TODO %^{Description} %^g\n%?\n\nAdded: %U"
;;; ox-confluence-en.el --- Enhanced Confluence Wiki Back-End for Org Export Engine
;; Copyright (C) 2015, Correl Roush
;; Author: Correl Roush <[email protected]>
;; Keywords: outlines, confluence, wiki
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
@correl
correl / recursiveitemgetter.py
Last active April 12, 2017 14:59
Recursively accessing dictionaries and sorting a list of nested data structures
from functools import partial
def recursiveitemgetter(keys):
"""Returns a function that recursively fetches a value from a
dictionary, where keys is a list of keys to traverse."""
def recursive_get(keys, dictionary):
"""Recursively fetches a value from a dictionary, where keys is a
list of keys to traverse."""
@correl
correl / journal.org.txt
Created June 11, 2018 18:16
Graphing gender expression in my org-mode journal
* Graphs
** Gender Expression
#+name: mtf
#+BEGIN_SRC emacs-lisp :exports none :results silent
(->>
(org-map-entries
(lambda ()
(list (car (s-split " " (org-no-properties (org-get-heading t t t t))))
(--if-let (org-entry-get (point) "MTF")
(string-to-number it))
@correl
correl / months.org.txt
Last active June 18, 2018 15:28
Month difference in an org table
#+BEGIN_SRC emacs-lisp
(defun months-diff (a b)
(let* ((date-a (mapcar #'string-to-number (split-string a "-")))
(date-b (mapcar #'string-to-number (split-string b "-")))
(months-a (+ (* 12 (car date-a)) (cadr date-a)))
(months-b (+ (* 12 (car date-a)) (cadr date-b))))
(+
(- months-a months-b)
(if (< (caddr date-a) (caddr date-b)) -1 0))))
#!/usr/bin/env python2.7
""" Outputs JIRA issue information for each issue id
"""
from urllib import urlencode
import argparse
import base64
import json
import os