Skip to content

Instantly share code, notes, and snippets.

View harto's full-sized avatar
🍕
🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕

Stuart Campbell harto

🍕
🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕
View GitHub Profile
@harto
harto / format_timedelta.py
Created April 1, 2010 05:48
A couple of functions for formatting timedeltas
"""
Functions for flexibly formatting Python timedelta objects.
The following field codes apply:
d - days
M - minutes
h - hours
s - seconds
m - milliseconds
u - microseconds
@harto
harto / less-compilation.el
Created October 30, 2010 04:24
Snippet from .emacs for LESS auto-compilation
(add-to-list 'auto-mode-alist '("\\.less$" . css-mode))
(setq-default compile-less nil)
(add-hook 'css-mode-hook
(lambda ()
(when (string-match "\\.less$" buffer-file-name)
(add-hook 'after-save-hook
(lambda ()
(when compile-less
(funcall compile-less)))))))
@harto
harto / .dir-locals.el
Created October 30, 2010 04:26
LESS compilation function that calls `cake' with the argument `css'
((css-mode . ((compile-less . (lambda () (call-process "cake" nil nil nil "css"))))))
@harto
harto / tasks.clj
Created October 30, 2010 04:31
LESS compilation task for Cake
(ns myproject.tasks
(:use [cake.core :only (deftask defile)])
(:import [java.io File]
[com.asual.lesscss LessEngine]))
(defn less->css
"Compiles the Less file at the given path into its CSS equivalent."
[less-path css-path]
(.compile (LessEngine.) (File. less-path) (File. css-path)))
@harto
harto / gist:713148
Created November 24, 2010 05:05
ideas for clojure-swing interop
(require '[clojure.string :as str])
(defn keyword->setter [kw]
(->> (str/split (name kw) #"-")
(map str/capitalize)
(apply str "set")
(symbol)))
(defmacro bean-set! [bean props]
`(doto ~bean
@harto
harto / export.sh
Created January 13, 2011 23:55
Exports Clojure projects for Coderloop submission
#!/bin/bash
project=$1
src_dir=$project
build_dir=/tmp/$project
mkdir "$build_dir"
for d in src lib; do
mkdir "${build_dir}/${d}"
@harto
harto / Makefile
Created August 2, 2011 13:29
JavaScript dependency resolver
ALL=$(wildcard src/*.js)
pacman.js: $(ALL)
cat `python tools/dependency-order.py $(ALL)` >pacman.js
.PHONY=clean
clean:
rm pacman.js
@harto
harto / nsify.py
Created August 13, 2013 00:13
Hack to convert PHP code from `Quasi_Namespaced_Style` to `Properly\Namespaced\Style`
#!/usr/bin/env python
import re
import sys
CLASSNAME = re.compile(r'^(?:(?:abstract )?class|interface) ([\w_]+)', re.MULTILINE)
CLASSES = re.compile(r'\b([A-Z][a-z]\w+([_\\][A-Z][a-z]\w)+)')
@harto
harto / engine.py
Created October 15, 2013 20:28
A multiplexing Thumbor engine that prefers OpenCV where possible, and falls back to Pillow for unsupported image types.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2013 arthens@gmail.com
import magic
from thumbor.engines import pil, opencv
@harto
harto / deploy-gh-pages.sh
Created February 22, 2014 08:10
A general-purpose deployment script for GitHub Pages
#!/usr/bin/env bash
set -x
set -e
# Deploys a directory (within a git repo) to github.io by jamming it into the
# `gh-pages` branch.
#
# Note: it's assumed that you don't care about tracking history for `gh-pages`,
# as this script clobbers the branch every time.