Skip to content

Instantly share code, notes, and snippets.

View jondavidjohn's full-sized avatar

Jonathan D. Johnson jondavidjohn

View GitHub Profile
@jondavidjohn
jondavidjohn / social_debugger.php
Created November 21, 2012 20:36
Social Debugger WordPress Plugin
<?php
/*
Plugin Name: Social Debugger
Description: Plugin to print debugging information by appending ?social_debug=true to the url within the admin
Version: 0.1
Author: Crowd Favorite
Author URI: http://crowdfavorite.com/
*/
@jondavidjohn
jondavidjohn / gist:3107336
Created July 13, 2012 20:42
Rewrite Wordpress uploads to lorempixel (Nginx)
# if you're requesting anything within '/wp-content/uploads' or '/files'
location ~ (/wp-content/uploads|files) {
# and it doesn't exist
if (!-e $document_root$uri) {
# try and match the dimensions from the filename
rewrite (\d+)(?:x)(\d+)(?:\.(?:[^\.]+)$) http://lorempixel.com/$1/$2 break;
# otherwise just use a default size
rewrite .* http://lorempixel.com/800/600 break;
}
}
@jondavidjohn
jondavidjohn / pyshell.py
Created June 13, 2012 21:02
Python shell utility start
import argparse
argparser = argparse.ArgumentParser(description="This is a Description of the Utility")
argparser.add_argument('--foo', '-f', help='help text for --foo argument', default="World")
def main():
"""Script Entry Point"""
print "Hello %s!" % args.foo
@jondavidjohn
jondavidjohn / deploy.rb
Created March 8, 2012 18:00 — forked from ianmurrays/deploy.rb
Runs test locally before deploying on capistrano.
set :test_log, "logs/capistrano.test.log"
namespace :deploy do
before 'deploy:update_code' do
puts "--> Running tests, please wait ..."
unless system "bundle exec rake > #{test_log} 2>&1" #' > /dev/null'
puts "--> Tests failed. Run `cat #{test_log}` to see what went wrong."
exit
else
puts "--> Tests passed"
//
// Start Method Definitions
//
// match_selector(Node tree, Array selectors)
// - top of the node tree
// - array of decendant string selectors (think CSS)
//
var match_selector = function self(node, selectors) {
if ( node.values.indexOf(selectors[0]) !== -1 ) {
@jondavidjohn
jondavidjohn / AppDAL.js
Created February 29, 2012 04:30
A Simple AJAX DAL for use in a web app accessing a RESTful JSON API endpoints
var AppDAL = (function() {
var _BASE_URL = "http://"+ window.location.host +"/api/";
var _request = function(resource_uri, method, s_cback, e_cback, data) {
data = data || null;
var resource_url = _BASE_URL + resource_uri;
var xhr = new window.XMLHttpRequest();
xhr.onreadystatechange = function () {
@jondavidjohn
jondavidjohn / factor.py
Created February 20, 2012 15:54
Get Factors of a number
def _facs(num):
rv = [1, num]
for i in xrange(2, int(math.sqrt(num)) + 1):
if not num % i:
rv.extend([i,num/i])
return rv
@jondavidjohn
jondavidjohn / humanoid_shuffle.py
Created January 18, 2012 05:35
List Shuffle (humanoid)
@staticmethod
def humanoid_shuffle(items, num_shuffles=6):
# how many times items can be pulled from the same list consecutively
MAX_STREAK = 10
# divide list roughly in half
num_items = len(items)
end_range = int(num_items / 2 + random.randint(0, int(.1 * num_items)))
first_half = items[:end_range] # list up to 0 - end_range
second_half = items[end_range:] # list after end_range - len(items)
@jondavidjohn
jondavidjohn / block_map_works.php
Created October 21, 2011 17:24
Attempt at new block creation for moodle
<?php
class block_map_works extends block_base {
public function init()
{
$this->title = get_string('map_works', 'block_map_works');
}
public function instance_allow_config()
@jondavidjohn
jondavidjohn / gist:1223151
Created September 16, 2011 21:06
John Resig's Class instatiator
// makeClass - By John Resig (MIT Licensed)
function makeClass(){
return function(args){
if ( this instanceof arguments.callee ) {
if ( typeof this.init == "function" )
this.init.apply( this, args.callee ? args : arguments );
} else
return new arguments.callee( arguments );
};
}