Skip to content

Instantly share code, notes, and snippets.

View patmaddox's full-sized avatar
🤔
Trying to figure out how to look up comments I've left

Pat Maddox patmaddox

🤔
Trying to figure out how to look up comments I've left
View GitHub Profile
@patmaddox
patmaddox / gist:1270808
Created October 7, 2011 17:06
test file
If you can see this, I can embed gists on google plus. sweet!
stubDate = (date) ->
@oldDate = Date
Date = -> date
resetStubDate = ->
Date = @oldDate if @oldDate
@patmaddox
patmaddox / application_helper.rb
Created September 20, 2011 21:42
conditionally link to precompiled assets in rails 3 asset pipeline
module ApplicationHelper
def controller_asset_javascript
javascript_include_tag(controller_name) if Rails.configuration.assets.precompile.include?("#{controller_name}.js") || !Rails.env.production?
end
def controller_asset_stylesheet
stylesheet_link_tag(controller_name) if Rails.configuration.assets.precompile.include?("#{controller_name}.css") || !Rails.env.production?
end
end
@patmaddox
patmaddox / render_with_comments.rb
Created August 30, 2011 16:38
HTML comments to tell you what partial is rendering
# Throw a comment in before and after every render call on html based templates
module ActionView # :nodoc: all
class Base
alias_method :render_file_without_comments, :render
attr_accessor :render_stack
def render(options = {}, local_assigns = {}, &block)
self.render_stack ||= []
if options[:partial]
@patmaddox
patmaddox / blackjack.coffee
Created August 15, 2011 23:24
My first coffeescript program
# Run this with "coffee blackjack.coffee"
_ = require('underscore')
Array::remove = (e) -> this.splice(this.indexOf(e), 1)
Array::clone = ->
cloned = []
for i in this
cloned.push i
cloned
| stream |
stream := WriteStream on: String new.
SBApp fileOutOn: stream moveSource: false toFile: nil.
stream contents.
@patmaddox
patmaddox / shoulda_just_wrote_the_code_spec.rb
Created July 14, 2011 20:31
A goofy bit of code that takes your shoulda-style macro validations and generates a model class from it
# A goofy bit of code that takes your shoulda-style macro validations and generates a model class from it
require 'rspec'
require 'active_model'
module ActiveRecordTranslator
def it_should_validate_presence_of(field)
klass = Class.new do
include ActiveModel::Validations
@patmaddox
patmaddox / replace_site_paths.rb
Created June 1, 2011 17:50
A script that will rename files and update hrefs based on a meta tag
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'fileutils'
site_root = File.expand_path('~/Sites/v42')
Dir[site_root + '/**/*'].each do |full_path|
next unless File.file?(full_path)
old_name, extension = File.basename(full_path).split(".")
doc = Nokogiri.parse(File.read(full_path))
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css"><!--
body, table { background-color: #FFF; color:#333; font-family: arial, sans-serif; font-weight: 100; font-size: 12px; line-height: 150%; }
.page_header { padding: 0px; }
.page_title { font-size: 1.2em; font-weight: bold; padding: 5px; border-bottom: 1px dashed #999; }
.feed_date { color: #777; font-size: 0.9em; font-weight: bold; }
class Hash
def to_cgi_params
map {|pair| [pair.first, CGI.escape(pair.last)].join('=')}.join('&')
end
end