Skip to content

Instantly share code, notes, and snippets.

View robhurring's full-sized avatar
🍻
cheers

Rob Hurring robhurring

🍻
cheers
View GitHub Profile
@robhurring
robhurring / renderer.php
Created March 29, 2010 17:40
PHP Template Rendering
<?php
class MissingTemplateException extends Exception {}
function render_template($template_file, $vars = array())
{
if(file_exists($template_file))
{
ob_start();
extract($vars);
include($template_file);
namespace :filters do
desc 'List all filter permissions'
task :list => :environment do
controllers = Dir[Rails.root.to_s+'/app/controllers/**/*_controller.rb'].map{ |f| File.basename(f).gsub(/\.rb$/, '').classify }.sort
controllers.each do |controller|
filters = controller.constantize.filter_chain
puts controller
filters.each do |filter|
puts "\t#{filter.method}"
puts "\t\t" << filter.options.inspect unless filter.options.blank?
<?php
session_start();
// Check for the session[user_id] param to see if the user is logged in
if(!isset($_SESSION['user_id']))
header('location:login.php');
echo 'This is my secret page.'
// curl http://localhost/insecure.php
#!/usr/local/bin/ruby
require 'rubygems'
require 'action_mailer'
require 'optparse'
require 'fcntl'
require 'pp'
ActionMailer::Base.delivery_method = :sendmail
@robhurring
robhurring / plugin_loader.rb
Created May 18, 2010 15:42
Simple way to load Rails plugins in Sinatra
# Simple bootloader for Rails plugins in Sinatra
# This checkes the +plugin_folder+ for plugin-like bundles. For each folder it finds it will do:
# If the +lib+ folder exists: add it to our load path
# If a +init.rb+ file exists: require it
# Not very robust but it is lightweight for loading simple rails plugins
class PluginLoader
attr_reader :plugin_folder
def initialize(plugin_folder)
@plugin_folder = plugin_folder
<div id='sidebar'>
<%= section(:sidebar) || partial(:default_sidebar) %>
</div>
# You can use the model's ID (PK/Serial) to generate a token which can be reversed:
# Example:
# Url.find(7213).shortened #=> 5kd
# Url.find_by_shortened("5kd") #=> #<Url id: 7213...>
class Url < ActiveRecord::Base
Radix = 36
# convert ID into a shortened version
def shortened
id.to_s(Radix)
<script src='http://www.google.com/jsapi' type='text/javascript' charset='utf-8'></script>
<script type='text/javascript' charset='utf-8'>
google.load('prototype', '1.6');
google.load('scriptaculous', '1.8');
</script>
@robhurring
robhurring / push_path.sh
Created November 22, 2010 20:05
Add paths to $PATH from multiple places in .bashrc/etc. : http://proccli.com/easy-add-paths-path-bash
# Push a path to our $PATH variable
# Usage:
# push_path <path> [after]
# If after is specified it will appear at the end of $PATH, otherwise it is unshifted
push_path(){
if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
@robhurring
robhurring / entourage_email_script.rb
Created November 22, 2010 20:30
Ruby shell script to create Entourage emails from the command line - http://proccli.com/send-entourage-mails-command-line-ruby
#!/usr/local/bin/ruby
# Mail script for sending stuff from the command line through entourage
# which makes life super easy for sending files, or piping files to a mail body, etc.
#
# email -t bosses -c tracker -a ~/report.csv <SUBJECT HERE>
#
# Author:: Rob Hurring
# Date:: 2011-11-15
# Version:: 1.0a