Skip to content

Instantly share code, notes, and snippets.

View coryschires's full-sized avatar
💭
Code King

Cory Schires coryschires

💭
Code King
View GitHub Profile
@coryschires
coryschires / layout_helper.rb
Created June 21, 2010 16:11
layout helper methods
module LayoutHelper
def title(page_title, show_title = true)
content_for(:title) { page_title.to_s }
@show_title = show_title
end
def show_title?
@show_title
end
def formatted_date_range(start_date, end_date = nil)
if start_date && end_date
same_month = start_date.month == end_date.month
same_year = start_date.year == end_date.year
date = "#{start_date.strftime("%B %e")} - #{end_date.strftime("%e, %Y")}" if same_month && same_year
date = "#{start_date.strftime("%B %e")} - #{end_date.strftime("%B %e, %Y")}" if !same_month && same_year
date = "#{start_date.strftime("%B %e, %Y")} - #{end_date.strftime("%B %e, %Y")}" if !same_year
else
date = start_date.strftime("%A, %B %e, %Y")
def border(string)
length = (80 - string.length) / 2
border = '+' * length
"#{border} #{string} #{border}"
end
# Regex to find/replace colons for converting css to sass with textmate
# For example, converts:
# body
# color: gray
# into:
# body
# :color gray
# find
# Regex to find/replace colons for converting css to sass with textmate
# For example, converts:
# body
# color: gray
# into:
# body
# :color gray
# find
var javascript_for = function(controller, action, anonymous_function) {
var correct_controller = APP.controller_name === controller,
correct_action = APP.action_name === action || 'all';
if (correct_controller && correct_action) {
anonymous_function();
};
};
javascript_for('events', 'index', function() {
/usr/lib64/ruby/site_ruby/1.8/rubygems.rb:233:in `activate': can't activate i18n (~> 0.5.0, runtime) for ["mail-2.2.11", "actionmailer-3.0.1", "rails-3.0.1"], already activated i18n-0.4.2 for ["activemodel-3.0.1", "actionpack-3.0.1", "rails-3.0.1"] (Gem::LoadError)
@coryschires
coryschires / test_dewey.rb
Created December 10, 2010 19:14
Get method returns nil when fetching a document
Dewey.authentication :client, :email => 'your-email', :password => 'your-pass'
id = Dewey.put(File.new('example.txt'), 'My Second Upload')
puts id # => in my case returned: document:1DDxIGsmK3wIJpdJC-qGK4y-R8onzDrBPm89y7BbO_Zg
original = Dewey.get(id)
puts original.inspect # => nil
@coryschires
coryschires / index.html
Created May 16, 2011 17:33
splatter example for BNC
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<style>
.contenta {margin-top: 25px;}
.contenta h1 {color: #333; font-weight: normal; border-bottom: 1px solid #bbb; margin: 25px 0px; padding-bottom: 7px;}
.contenta h2 {color: #777; font-weight: normal; margin: 20px 0px 0px 2px;}
</style>
@coryschires
coryschires / stub_role.rb
Created June 20, 2011 18:09
stub_role.rb
# in spec helper
class User
def role?(role)
true
end
end