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
/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)
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() {
# 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
def border(string)
length = (80 - string.length) / 2
border = '+' * length
"#{border} #{string} #{border}"
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")
@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
@coryschires
coryschires / todays_date.js
Created June 21, 2010 06:59
todays date javascript
var todays_date = function() {
var month_in_words = function(month_num) {
if (month_num === 0) { return "January" };
if (month_num === 1) { return "February" };
if (month_num === 2) { return "March" };
if (month_num === 3) { return "April" };
if (month_num === 4) { return "May" };
if (month_num === 5) { return "June" };
if (month_num === 6) { return "July" };
@coryschires
coryschires / perserve_linebreaks.js
Created June 21, 2010 05:29
preserve line breaks javascript
var perserve_linebreaks = function(text) {
var html = text.replace(/\r\n\r\n/g, "</p><p>"),
html = html.replace(/\r\n/g, "<br />"),
html = html.replace(/\n\n/g, "</p><p>"),
html = html.replace(/\n/g, "<br />"),
html = "<p>"+html+"</p>";
return html
};
@coryschires
coryschires / jquery.clear_form.js
Created June 17, 2010 04:26
plugin to clear form form data
// tiny plugin to clear form form data.
$.fn.clearForm = function() {
// iterate each matching form
return this.each(function() {
// iterate the elements within the form
$(':input', this).each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (type == 'text' || type == 'password' || tag == 'textarea')