Skip to content

Instantly share code, notes, and snippets.

Rob Hurring robhurring

Block or report user

Report or block robhurring

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@robhurring
robhurring / any.js
Created Feb 18, 2009
Allow strings to number_to_currency style comma seperate in javascript
View any.js
// 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 Mar 16, 2009
Rails Metal theme switcher
View application.html.erb
# 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 Mar 24, 2009
object debugging with syntax highlight
View any.html.erb
<!-- using -->
<%= syntax_debug @object %>
@robhurring
robhurring / shBrushRuby.js
Created Jul 17, 2009
GitHub style syntax highlighter theme
View shBrushRuby.js
/**
* 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 Feb 11, 2010
PHP fuzzy date function
View fuzzy_date.php
<?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 Mar 24, 2010
Sinatra using ActiveRecord's Query Caching ability across multiple Databases : http://proccli.com/active-record-query-caching-sinatra-multiple-databases
View config.ru
require 'sinatra_query_caching_demo'
run Demo
@robhurring
robhurring / diff.rb
Created Mar 26, 2010
Ruby Diff -- Ghetto style!
View diff.rb
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 Mar 29, 2010
PHP Template Rendering
View renderer.php
<?php
class MissingTemplateException extends Exception {}
function render_template($template_file, $vars = array())
{
if(file_exists($template_file))
{
ob_start();
extract($vars);
include($template_file);
View filters.rake
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?
View insecure.php
<?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
You can’t perform that action at this time.