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 / any.js
Created February 18, 2009 19:31
Allow strings to number_to_currency style comma seperate in javascript
// Allow strings to number_to_currency style comma seperate
String.prototype.commafy = function () {
return this.replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,");
});
}
// Convenience method for numbers
Number.prototype.commafy = function () {
return String(this).commafy();
@robhurring
robhurring / application.html.erb
Created March 16, 2009 13:21
Rails Metal theme switcher
# your applications main layout file (app/views/layouts/application.html.erb?)
# I put this after the normal stylesheet call, so our theme can override what we want instead of the entire stylesheet
<% if theme = request.env['rails.theme'] %>
<%= stylesheet_link_tag "themes/#{theme}", :media => :all %>
<% end %>
@robhurring
robhurring / any.html.erb
Created March 24, 2009 15:19
object debugging with syntax highlight
<!-- using -->
<%= syntax_debug @object %>
@robhurring
robhurring / shBrushRuby.js
Created July 17, 2009 01:04
GitHub style syntax highlighter theme
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/wiki/SyntaxHighlighter:Donate
*
* @version
* 2.0.320 (May 03 2009)
*
@robhurring
robhurring / fuzzy_date.php
Created February 11, 2010 15:01
PHP fuzzy date function
<?php
function fuzzy_date($timestamp)
{
$myDays = array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
if( preg_match("/[-\/:]/", $timestamp) )
$timestamp = strtotime($timestamp);
if($timestamp > time())
// All future dates
@robhurring
robhurring / config.ru
Created March 24, 2010 19:00
Sinatra using ActiveRecord's Query Caching ability across multiple Databases : http://proccli.com/active-record-query-caching-sinatra-multiple-databases
require 'sinatra_query_caching_demo'
run Demo
@robhurring
robhurring / diff.rb
Created March 26, 2010 20:20
Ruby Diff -- Ghetto style!
require 'tempfile'
# TODO: do some pre-comparison on a and b so we can skip creating temp files and all that jazz.
# NOTE: this is so ghetto ;)
module Diffable
def diff(b, options = {})
Diff.new(self, b, options).diff
end
end
@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