Skip to content

Instantly share code, notes, and snippets.

View xwmx's full-sized avatar

William Melody xwmx

View GitHub Profile
# http://fightingforalostcause.net/misc/2006/compare-email-regex.php
# email validation
/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD
@xwmx
xwmx / db.rake
Created November 23, 2008 12:31
namespace :db do
desc "Drop then recreate the dev database, migrate up, and load fixtures"
task :remigrate => :environment do
return unless %w[development test staging demo].include? Rails.env
ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.drop_table t }
Rake::Task["db:migrate"].invoke
ENV['FIXTURES_PATH'] = "db/data/#{RAILS_ENV}" unless (ENV['FIXTURES_PATH'] || Rails.env.test?)
Rake::Task["db:fixtures:load"].invoke
end
namespace :sass do
desc 'Updates stylesheets if necessary from their Sass templates.'
task :update => :environment do
Sass::Plugin.update_stylesheets
end
end
@xwmx
xwmx / gist:28119
Created November 23, 2008 14:05
undefined
javascript:window.location=%22http://localhost/links/new?url=%22+encodeURIComponent(document.location)+%22&title=%22+encodeURIComponent(document.title)
@xwmx
xwmx / gist:45282
Created January 9, 2009 21:08
ActiveRecord Monkeypatching
class << ActiveRecord::Base
def paged_find_tagged_with(tags, args = {})
tags.nil? ? paginate(args) : paginate_tagged_with(tags, args)
end
def concerned_with(*concerns)
concerns.each do |concern|
require_dependency "#{name.underscore}/#{concern}"
end
@xwmx
xwmx / gist:45283
Created January 9, 2009 21:11
ActionMailer Monkeypatching
class ActionMailer::Base
helper ActionView::Helpers::UrlHelper
def generic_mailer(options)
@recipients = options[:recipients] || (Settings.mailer_to_address if Settings.table_exists?)
@from = options[:from] || (Settings.mailer_from_address if Settings.table_exists?)
@cc = options[:cc] || ""
@bcc = options[:bcc] || ""
@subject = options[:subject] || ""
def assert_layout(expected=nil, message=nil)
clean_backtrace do
layout = @response.layout ? @response.layout.split('/').last : false
msg = build_message(message, "expecting <?> but rendering with <?>", expected, layout)
assert_block(msg) do
if expected.nil?
@response.layout
else
expected == layout
end
def log_test
if Rails::logger
# When I run tests in rake or autotest I see the same log message multiple times per test for some reason.
# This guard prevents that.
unless @already_logged_this_test
Rails::logger.info "\n\nStarting #{@method_name}\n#{'-' * (9 + @method_name.length)}\n"
end
@already_logged_this_test = true
end
end
##
# Calendar helper with proper events
# http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
#
# (C) 2009 James S Urquhart (jamesu at gmail dot com)
# Derived from calendar_helper
# (C) Jeremy Voorhis, Geoffrey Grosenbach, Jarkko Laine, Tom Armitage, Bryan Larsen
# Licensed under MIT. http://www.opensource.org/licenses/mit-license.php
##
# syntax_helper.rb
module SyntaxHelper
WhiteListHelper.tags.merge(UV_SYNTAX_TAGS)
def colorize_code(body, options = {})
options = {:line_numbers => false, :theme => DEFAULT_SYNTAX_STYLE}.merge(options)
r = RedCloth.new(body || '')
output = r.gsub(/<code[\.|\:]([\w\-]+)>(.*?)<\/code[\.|\:]?\1?>/m) do
lang, text = $1, $2
html = "<notextile>" + code((text || ''), {:syntax => (lang if UV_SYNTAXES.include?(lang))}.merge(options)) + "</notextile>"