Skip to content

Instantly share code, notes, and snippets.

View crimeminister's full-sized avatar
💭
🔥 🐶🎩☕️🔥

Robert Medeiros crimeminister

💭
🔥 🐶🎩☕️🔥
View GitHub Profile
@crimeminister
crimeminister / wardscrape.py
Created October 24, 2011 06:10
Scrape ward population numbers from City of Toronto web pages.
# wardscrape.py
# encoding=utf-8
"""
Fetch a web page about each ward in the City of Toronto and extract
the population of that ward. Store the data in a tab-separated output
file.
"""
from BeautifulSoup import BeautifulSoup
@crimeminister
crimeminister / prepare-commit-msg.py
Created January 1, 2012 00:11
Git hook to insert word count into commit message.
#!/usr/bin/python3
#
# A hook script to prepare the commit log message.
#
# Called by git-commit with the name of the file that has the commit
# message, followed by the description of the commit message's source.
# The hook's purpose is to edit the commit message file. If the hook
# fails with a non-zero status, the commit is aborted.
import glob
@crimeminister
crimeminister / immutant.conf
Created October 10, 2012 00:24
An Upstart configuration file for Immutant
description "This is an upstart job file for Immutant"
pre-start script
bash << "EOF"
mkdir -p /var/log/immutant
chown -R immutant /var/log/immutant
EOF
end script
# Ubuntu doesn't yet emit the network-services event:
@crimeminister
crimeminister / new-earth-time.el
Created November 6, 2012 19:44
Use and display New Earth Time in Emacs
;;; new-earth-time.el --- "New Earth" date and time functions
;; Copyright (C) 2011 Robert Medeiros
;; Author: Robert Medeiros <robert.medeiros@alumni.utoronto.ca>
;; Keywords: calendar
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
@crimeminister
crimeminister / gist:4046630
Created November 9, 2012 16:21 — forked from AlexBaranosky/gist:3898489
Clojure joda DateTime instant reader
(ns groupon.joda-instant-reader
(:require [clojure.instant :as i])
(:import org.joda.time.DateTime))
(defmethod print-method org.joda.time.DateTime
[^org.joda.time.DateTime d ^java.io.Writer w]
(#'i/print-date (java.util.Date. (.getMillis d)) w))
(defmethod print-dup org.joda.time.DateTime

A little Clojure configuration reader

This is a handy bit of code I've written more than once. I thought I'd throw it in here so I can refer back to it later. Basically, it lets you read a config file to produce a Clojure map. The config files themselves can contain one or more forms, each of which can be either a map or a list. Maps are simply merged. Lists correspond to invocations of extension points, which in turn produces a map, which is merged along with everything else.

An Example

Consider the following files:

names.edn

;; Datomic example code
;; demonstrates various update scenarios, using a news database
;; that contains stories, users, and upvotes
;; grab an in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
...
# Fake a fuse install
RUN apt-get install libfuse2
RUN cd /tmp ; apt-get download fuse
RUN cd /tmp ; dpkg-deb -x fuse_* .
RUN cd /tmp ; dpkg-deb -e fuse_*
RUN cd /tmp ; rm fuse_*.deb
RUN cd /tmp ; echo -en '#!/bin/bash\nexit 0\n' > DEBIAN/postinst
RUN cd /tmp ; dpkg-deb -b . /fuse.deb
@crimeminister
crimeminister / security.js
Created March 20, 2014 19:58
Express middleware for IP-based access control
'use strict';
var _ = require('lodash');
var keystone = require('keystone');
var range_check = require('range_check');
var util = require('util');
/**
*
*/
@crimeminister
crimeminister / add2mvn.sh
Created July 18, 2014 19:04
add some JAR files to a local Maven repository (allowing use of unpublished JARs in a Clojure project)
#!/usr/bin/
for file in $(ls lib/*.jar); do
#mvn install:install-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -DlocalRepositoryPath=maven_repository
artifact_id=`basename $file | sed s/\.jar$// | sed -E s/-[0-9]\+\.[0-9]\+\.[0-9]\+//`
version=`basename $file | sed s/\.jar$// | sed -E s/[a-zA-Z\-]*//`
group_id=com.theplatform
local_repo=mvn
mvn deploy:deploy-file -DcreateChecksum=true -Dfile=$file -DartifactId=$artifact_id -Dversion=$version -DgroupId=$group_id -Dpackaging=jar -Durl=file:$loca
l_repo