Skip to content

Instantly share code, notes, and snippets.

View warmwaffles's full-sized avatar
🛠️
Code Wrestling

Matthew Johnston warmwaffles

🛠️
Code Wrestling
View GitHub Profile
@warmwaffles
warmwaffles / error_page.py
Created February 16, 2012 18:19
Add / Remove Rackpsace Loadbalancer Error Page
#!/usr/bin/python
#
# Just change the three variables below and you are all set!
# @author Matthew A. Johnston (WarmWaffles)
# your user name
API_USERNAME = "username"
# your api key
API_KEY = "api-key"
# Load balancer Region
@warmwaffles
warmwaffles / widget_controller.rb
Created March 25, 2012 19:16
Programming By Contract within a controller
class WidgetsController < ApplicationController
# ...
# other functions
#
def create
widget = Widget.new(params[:widget])
widget.foo = some_thing
widget.bar = some_other_thing
widget.save!
@warmwaffles
warmwaffles / functions.php
Created May 2, 2012 23:07
Doing a vimeo transient in PHP
<?php
#
# ... Other WP functions
#
function vimeo_transient_title($post) {
if( false === ($value = get_transient('vimeo_title_' . $post->ID) )) {
$vid_meta = get_post_meta($post->ID,'cmb_vimeo_id_field',true);
$url = 'http://vimeo.com/api/v2/video/' . $vid_meta . '.php';
@warmwaffles
warmwaffles / will_paginate.rb
Created June 22, 2012 15:14 — forked from isaacbowen/will_paginate.rb
extends will_paginate to play well with Twitter's Bootstrap
# config/initializers/will_paginate.rb
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
@warmwaffles
warmwaffles / widget.rb
Created June 23, 2012 17:00
Have you wanted to ever fuzzy search on your model without actually running Solr or Sphinx? Well this little function can help ease you in
class Widget < ActiveRecord::Base
#
# ..... extra crap here .....
#
scope :active, where(:status => [:active])
#
# This will fuzzy search the model for the provided query. It will split your
@warmwaffles
warmwaffles / nginx
Created July 11, 2012 19:53
Nginx /etc/init.d/nginx file
#! /bin/sh
#------------------------------------------------------------------------------
. /lib/lsb/init-functions
#------------------------------------------------------------------------------
# Consts
#------------------------------------------------------------------------------
PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
@warmwaffles
warmwaffles / user.rb
Created July 23, 2012 16:52
Omniaaaaaaaomg this is a mess
class User < ActiveRecord::Base
# ... Initialize Devise and other crap ....
def self.authorize_omniauth(options={}, signed_in_resource=nil)
auth = Authentication.authorize(options[:auth][:provider], options[:auth][:uid])
if auth
auth.set_omniauth_credentials(options[:auth])
@warmwaffles
warmwaffles / some_dumb_migration.rb
Created October 31, 2012 20:07
How I handle database rollbacks on complex migrations
class SomeDumbMigration < ActiveRecord::Migration
def up
### ....
end
def down
raise "WHAT IN DA FUQ ARE YOU DOING"
end
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC
"-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mac.bitlbee</string>
<key>ProgramArguments</key>
<array>
@warmwaffles
warmwaffles / athena.rb
Created February 7, 2013 04:22
My ruby prototype entity system
module Athena
class Entity
attr_reader :components
def initialize
@components = Hash.new
end
def add component
@components[component.class] = component