Skip to content

Instantly share code, notes, and snippets.

View jmhobbs's full-sized avatar

John Hobbs jmhobbs

View GitHub Profile
@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 / deadline.coffee
Created November 12, 2011 07:36
Hubot script to track deadlines.
# Tracks when stuff is due.
#
# deadlines - List what you have due
# add deadline 2011-10-30 Thing - Add a deadline for October 10, 2011
# remove deadline Thing - Remove a deadline named "Thing"
# clear deadlines - Remove all the deadlines
#
# Written by @jmhobbs
module.exports = (robot) ->
@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
@jmhobbs
jmhobbs / application_classes_auth.php
Created November 7, 2011 22:37
Using PBKDF2 with Kohana 3 Auth Module
<?php
abstract class Auth extends Kohana_Auth {
public function hash ( $str ) {
if ( ! $this->_config['hash_key'] )
throw new Kohana_Exception( 'A valid hash key must be set in your auth config.' );
if ( 'pbkdf2' == $this->_config['hash_method'] ) {
@jmhobbs
jmhobbs / ios5_notify.sh
Created October 12, 2011 16:51 — forked from jerodsanto/ios5_notify.sh
Siri, tell me when iOS 5 is available. Nothing? Fine. Bash, you do it.
#!/bin/bash
:(){ echo "Checking for iOS 5: `date`"; curl -s -L http://phobos.apple.com/version | grep Restore | grep iPhone | grep 5.0 > /dev/null && say "I O S 5 IS NOW AVAILABLE. GO GET YOUR DOWNLOAD ON, KID" || echo "Nothing yet..." && sleep 30 && :; };:
@jmhobbs
jmhobbs / twitter.php
Created October 6, 2011 16:03
Kohana 3 - OAuth & Twitter Example
<?php
class Controller_Twitter extends Controller {
public function action_index () {
// Load a consumer from config file.
$consumer = OAuth_Consumer::factory( Kohana::config( 'oauth.twitter' ) );