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
# Adds :callback option to to_json for Array, Hash and ActiveRecord::Base. Usage: | |
# user = User.find(:first) | |
# user.to_json(:callback => "foo") | |
# => foo({"user":{"name":"The Dude"}}) | |
# There's probably a much better way to do this - would love ideas / improvements! | |
class Array | |
alias orig_to_json to_json | |
def to_json(*a) | |
callback = nil |
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
# Will run optimize table on either just that class's MySQL InnDB table, or on ALL of that connection's tables. | |
# Works only with MySQL InnoDB tables, but could be used to run repair if you're using MyISAM. | |
class ActiveRecord::Base | |
def self.optimize_table | |
begin | |
self.connection.execute("optimize table #{self.table_name}") | |
rescue Exception => e | |
logger.error("#{self.class_name} - error optimizing #{self.table_name}: #{e}") | |
else |
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/bin/env ruby | |
# If you want to run it on a specific environment, set your RACK_ENV environment variable. | |
require 'rubygems' | |
require File.expand_path("../app",__FILE__) | |
# puts ARGV.options.inspect | |
if ARGV[0].length > 0 && ARGV[0].is_a?(String) | |
puts eval(ARGV[0]) |
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
# Add this to your ActiveRecord models for an easy "find me everything that happened on this day" named scope: | |
named_scope :by_date, lambda {|date| | |
if date.is_a?(String) | |
date = Time.parse(date) | |
end | |
date_start = date.midnight | |
date_end = date_start.advance(:hours => 24) | |
{ | |
:conditions => ["created_at between ? and ?",date_start,date_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
## Loader | |
# Does a pre-configured set of apache benchmark on an array of URLs passed in. | |
# Yes, it's silly, but it saved me a lot of time today. | |
# | |
# Usage: Loadr.test(['http://cnn.com','http://lwvr.net'],"news_and_me") | |
# - Created a log file for each URL, then fills it with the results of its ab runs. | |
# - Only works on OS's where ab is in the path. | |
class Loadr | |
@@run_sets = [ |
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 'base64' | |
require 'openssl' | |
require 'sha1' | |
# This will generate URLs for streaming private content from CloudFront... | |
# I followed these instructions for setting up the bucket and CloudFront: | |
## http://support.rightscale.com/index.php?title=12-Guides/01-RightScale_Dashboard_User_Guide/02-Clouds/01-EC2/11-CloudFront/Serving_Private_Content | |
# I have a global config hash for my private key for S3: | |
# The access_key is the CloudFront key id you set up. |
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
class BeanstalkdPlugin < Scout::Plugin | |
needs 'beanstalk-client' | |
OPTIONS=<<-EOS | |
connection_string: | |
default: localhost:11300 | |
name: Connection String | |
notes: The host and port to connect to. | |
EOS | |
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
class FileCheckPlugin < Scout::Plugin | |
OPTIONS=<<-EOS | |
file: | |
default: ~ | |
name: File | |
notes: The file to check to make sure it exists. | |
EOS | |
def build_report |
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
function paginateArray(arr,page_num,per_page) { | |
var i,r=[]; | |
if (arr.length < 1) { | |
return r; | |
} | |
if (per_page == undefined || per_page == null) { | |
per_page = 10; | |
} |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd"> | |
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> --> | |
<HTML> | |
<HEAD> | |
<META HTTP-EQUIV="Refresh" CONTENT="0.1"> | |
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> | |
<META HTTP-EQUIV="Expires" CONTENT="-1"> | |
<TITLE></TITLE> | |
</HEAD> |
OlderNewer