Skip to content

Instantly share code, notes, and snippets.

View jmhobbs's full-sized avatar

John Hobbs jmhobbs

View GitHub Profile
@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)
@jmhobbs
jmhobbs / route.php
Created March 15, 2012 17:11
Make Kohana 3 Routes Case Insensitive (globally)
<?php
/* APPPATH/classes/route.php */
class Route extends Kohana_Route {
public static function compile ( $uri, array $regex = NULL ) {
if ( ! is_string( $uri ) ) { return; }
return parent::compile( $uri, $regex ) . 'i';
}
@jmhobbs
jmhobbs / build_index.py
Created January 24, 2012 23:48
Naive Search with JavaScript
#!/usr/bin/env python
import json
import re
def tokenize ( string ):
# Strip extra punctuation
string = re.sub( r'[^a-z0-9A-Z \'\-]', '', string.lower() )
return string.split( ' ' )
def main ():
@jmhobbs
jmhobbs / output.txt
Created January 3, 2012 17:55
This is a little bash script I use to quickly check the syntax on a directory of PHP files.
jmhobbs@Cordelia:/data/working/example$ (193m|master|?AM)$ phlint
= Checking 176 files with 4 processes...
(1) = 50
(2) = 100
(3) = 150
(1) Done
(0) Done
(3) Done
(2) Done
jmhobbs@Cordelia:/data/working/example$ (193m|master|?AM)$
@jmhobbs
jmhobbs / cloudfiles_directory_upload.py
Created November 30, 2011 19:34
The tools for Rackspace Cloud Files suck, so here is a non-overwrite recursive directory uploader in Python.
# SET THESE
USERNAME = ''
API_KEY = ''
CONTAINER_NAME = ''
LOCAL_DIRECTORY_NAME = ''
# FORGET THESE
import cloudfiles
import os
import sys
@jmhobbs
jmhobbs / git_no_missing_dirs.sh
Created November 30, 2011 03:13
New, empty framework shell? Don't want to loose empty folders when you "git add"? Run this first.
#!/bin/sh
for i in $(find . -type d -empty | grep -v .git);
do touch $i/.gitignore
git add $i/.gitignore
done
@jmhobbs
jmhobbs / fact.coffee
Created November 11, 2011 04:18
A Hubot script to say facts about, uh, anyone.
#
# Hubot Script!
# Random fact about someone else.
#
# Example
#
# Hubot: fact me John Hobbs
# Hubot: John Hobbs counted to infinity - twice.
#
# John Hobbs 2011 - Licensed under MIT