Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
warmwaffles / error_page.py
Created Feb 16, 2012
Add / Remove Rackpsace Loadbalancer Error Page
View error_page.py
#!/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 Mar 25, 2012
Programming By Contract within a controller
View widget_controller.rb
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
Doing a vimeo transient in PHP
View functions.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 Jun 22, 2012 — forked from isaacbowen/will_paginate.rb
extends will_paginate to play well with Twitter's Bootstrap
View will_paginate.rb
# 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 Jun 23, 2012
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
View widget.rb
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 Jul 11, 2012
Nginx /etc/init.d/nginx file
View nginx
#! /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 Jul 23, 2012
Omniaaaaaaaomg this is a mess
View user.rb
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 Oct 31, 2012
How I handle database rollbacks on complex migrations
View some_dumb_migration.rb
class SomeDumbMigration < ActiveRecord::Migration
def up
### ....
end
def down
raise "WHAT IN DA FUQ ARE YOU DOING"
end
end
View homebrew.mxcl.bitlbee.plist
<?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 Feb 7, 2013
My ruby prototype entity system
View athena.rb
module Athena
class Entity
attr_reader :components
def initialize
@components = Hash.new
end
def add component
@components[component.class] = component
You can’t perform that action at this time.