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
// 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(); |
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
# 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 %> | |
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
<!-- using --> | |
<%= syntax_debug @object %> | |
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
/** | |
* 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) | |
* |
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 | |
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 |
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
require 'sinatra_query_caching_demo' | |
run Demo |
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
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 |
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 |
OlderNewer