Skip to content

Instantly share code, notes, and snippets.

import mongoengine
from mongoengine.document import Document
from mongoengine.fields import StringField, ListField
import time
from contextlib import contextmanager
from random import sample, randint
def create_data():
words = unicode(open('/usr/share/dict/words').read(), 'utf8').split()
#!/usr/bin/env python
"""Script that I keep in a Git repository along with my dotfiles. In the
repository, the files don't have the dot prefix so I can see them more easily.
Running the script symlinks all the files to ~/.<filename>, checking allowing
you to cancel if the file exists.
"""
import os
import glob
// ==UserScript==
// @name GitHub Contributor Compare
// @description Adds a compare link to forked repo commit pages
// @match http://github.com/*/commit/*
// @match https://github.com/*/commit/*
// ==/UserScript==
var onLoad = function(callback) {
var script = document.createElement("script");
var src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
from mongoengine import *
from mongoengine.queryset import QuerySet
class PostQuerySet(QuerySet):
def delete(self, safe=False):
ids = [post.id for post in self]
Comment.objects(post__in=ids).delete(safe=safe)
super(PostQuerySet, self).delete(safe=safe)
@hmarr
hmarr / gist:1013596
Created June 8, 2011 01:22
post{,de}activate scripts for virtualenvwrapper
#!/bin/zsh
# Global virtualenvwrapper postactivate, lives in $WORKON_HOME/postactivate
# Remove virtual env from start of PS1 as it's in RPROMPT instead
PS1="$_OLD_VIRTUAL_PS1"
PROJECT_DIR="$HOME/projects/$(basename $VIRTUAL_ENV)"
if [ -d $PROJECT_DIR ]; then
# If we aren't already within the project dir, cd into it
@hmarr
hmarr / bbikes.sh
Created November 24, 2011 13:52
Determine Barclays Bike availability via the command line
function bbikes {
location=${1:-$DEFAULT_BBIKE_LOCATION}
if [ -z $location ]; then
echo "usage: bbikes <location>"
echo "(you can also set a default location with DEFAULT_BBIKE_LOCATION)"
return 1
fi
url='https://web.barclayscyclehire.tfl.gov.uk/maps'
user_agent='Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)'
data=$(curl -sA "$user_agent" "$url" | grep ShowInfoB | grep -i "$location")
@hmarr
hmarr / gist:1852852
Created February 17, 2012 11:35
brew-install-redis-error
~ ⚡ brew install redis
==> Downloading http://redis.googlecode.com/files/redis-2.4.7.tar.gz
######################################################################## 100.0%
==> make -C src
MAKE hiredis
CC ae.o
CC anet.o
CC redis-benchmark.o
clang: warning: argument unused during compilation: '-rdynamic'
clang: warning: argument unused during compilation: '-ggdb'
@hmarr
hmarr / gocardless.cs
Created September 17, 2012 13:08
GoCardless Client Libraries
GoCardless.AccountDetails = new AccountDetails {
AppId = "APP123",
AppSecret = "S3CR3T",
Token = "ACCESSTOKEN123 manage_merchant:MERCHANT123"
};
GoCardless.Connect.NewBillUrl(new BillRequest("MERCHANT123", 30m));
@hmarr
hmarr / gc-ruby-api-deprecation.md
Last active December 16, 2015 10:19
GoCardless Ruby Library API Deprecation

API Deprecation in gocardless-ruby

When initialising gocardless-ruby with your GoCardless account details, your merchant id must now be passed in explicitly. This means that including the manage_merchant scope in the token attribute is now deprecated.

Before

GoCardless.account_details = {
  :app_id     => 'APP_ID_XXXXXXXXXXXXXXXXXXXXX',
 :app_secret =&gt; 'APP_SECRET_XXXXXXXXXXXXXXXXX',

RabbitMQ Basics

As demonstrated by the tutorials on the website, RabbitMQ can be used for everything from queuing background work to building RPC systems. To use RabbitMQ effectively, it is important to understand the core concepts: queues, exchanges, bindings, and messages. The documentation on rabbitmq.com is excellent, so I won't go into much depth, but it's worth briefly mentioning the core ideas.

Basic Terminology

Exchanges are where messages are sent. Every time a message is pushed in to RabbitMQ, it goes through an exchange.