This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MissingTemplateException extends Exception {} | |
function render_template($template_file, $vars = array()) | |
{ | |
if(file_exists($template_file)) | |
{ | |
ob_start(); | |
extract($vars); | |
include($template_file); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
require 'rubygems' | |
require 'action_mailer' | |
require 'optparse' | |
require 'fcntl' | |
require 'pp' | |
ActionMailer::Base.delivery_method = :sendmail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id='sidebar'> | |
<%= section(:sidebar) || partial(:default_sidebar) %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |