Skip to content

Instantly share code, notes, and snippets.

View jmhobbs's full-sized avatar

John Hobbs jmhobbs

View GitHub Profile
@jmhobbs
jmhobbs / points.coffee
Last active August 29, 2015 14:04
A Points Tracker for Hubot
# Description:
#
# A plugin to track points awarded for good jokes.
#
# Hubot takes transaction fees though.
#
#
# Dependencies:
# A Redis brain is recommended.
#
# -*- coding: utf-8 -*-
import socket
import os
print("Connecting...")
if os.path.exists("/tmp/python_unix_sockets_example"):
client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
client.connect("/tmp/python_unix_sockets_example")
print("Ready.")
print("Ctrl-C to quit.")
@jmhobbs
jmhobbs / brute_force_gift_exchange.py
Last active January 1, 2016 11:59
Problem: There are six cousins, three sets of siblings. They are drawing for a gift exchange, and none of them can get their sibling. How many combinations are possible. Math is hard, so I wrote a brute force, which I think is correct. This could be more generic. The nested loops are gross.
siblings = {1: 2, 2: 1, 3: 4, 4: 3, 5: 6, 6: 5}
cousins = set(siblings.keys())
# Start by getting all the possible pairings for each person.
possible_pairings = {1: set(), 2: set(), 3: set(), 4: set(), 5: set(), 6: set()}
for i in cousins:
for j in cousins - set((i, siblings[i])):
possible_pairings[i].add(j)
combinations = []
@jmhobbs
jmhobbs / coinbase_break_even_calculator.py
Created December 18, 2013 19:34
I wanted to know when I would break even (including fees) on some bitcoins I bought on coinbase. So I built a brute force calculator.
# -*- coding: utf-8 -*-
BANK_FEE = 0.15
COINBASE_PCT = 0.01
def calculate_sale_profit(coins, price, purchase_cost):
value = round(coins * price, 2)
fee = BANK_FEE + round(value * COINBASE_PCT)
return (value - fee) - purchase_cost
@jmhobbs
jmhobbs / as_working.py
Last active December 25, 2015 07:49
Issue with Flask 0.10.1 documentation as written.
# -*- coding: utf-8 -*-
import sys
from flask import Flask, url_for
app = Flask(__name__)
@app.route("/")
@jmhobbs
jmhobbs / README.md
Last active January 2, 2019 15:51
Delayed queues for RQ.

Example Run

RQ Worker

✪ rqworker --db 10 default high
16:06:30 RQ worker started, version 0.3.7
16:06:30 
16:06:30 *** Listening on default, high...
16:06:49 high: jobs.multiply(5, 2) (2df52ba2-bd32-4849-a8e1-c5241c78b542)
16:06:49 Job OK, result = 10
@jmhobbs
jmhobbs / composer.json
Created October 30, 2012 22:41
Swiftmailer AWS SES Composer Testing
{
"repositories": [
{
"type": "vcs",
"url": "git://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES.git"
}
],
"require": {
"jmhobbs/swiftmailer-transport-aws-ses": "dev-master"
}
@jmhobbs
jmhobbs / wordpress_consistent_default_avatars.php
Created October 10, 2012 21:42
Example of consistently selecting a default avatar from a set of available.
<?php
// This is how many different "random" avatars you have.
$default_avatar_count = 20;
foreach( $comments as $comment ) {
// Normalize the email address so user input differences doesn't change the avatar.
// This is technically against RFC 2821, but in practice it is ok.
$normalized_email_address = trim(strtolower($comment->comment_author_email));
@jmhobbs
jmhobbs / gosquared-dashboard.html
Created June 11, 2012 09:31
Toy Using GoSquared API
<!doctype html>
<html>
<head>
<title>GoSquared!</title>
</head>
<body>
<script src="jquery.min.js"></script>
<script>
jQuery(document).ready(function($) {
var API_KEY = 'demo',
@jmhobbs
jmhobbs / s3_clone_bucket.py
Created April 13, 2012 16:22
Clone An S3 Bucket Into Another Bucket
from boto.s3.connection import S3Connection
conn = S3Connection('YOUR-ACCESS-KEY', 'YOUR-SECRET-KEY')
bucket = conn.get_bucket('FROM-BUCKET-NAME')
for key in bucket.list():
print key.name
key.copy('TO-BUCKET-NAME', key.name)