Skip to content

Instantly share code, notes, and snippets.

View using body tag class to set state for css rendering
module ApplicationHelper
def body_tag_class(more_class = "")
"#{params[:controller]}_cont #{params[:action]}_action #{'logged_in' if logged_in?} #{more_class}"
%body{:class => open_body_tag}
View css that plays off of state in the body tag
.user_controls { display:none; }
body.logged_in .user_controls { display:block; }
View lark_template.rb
# download and git methods swiped from
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
puts "Can't get #{from} - Internet down?"
View gist:158766
<% if page.page_type == LinkContent && page.open_link_in_new %>
<%= link_to, page.link_url, :class => "nav_link", :target => '_blank' %>
<% elsif page.page_type == LinkContent %>
<%= link_to, page.link_url, :class => "nav_link" %>
<% else %>
<%= link_to, page_path(page), :class => "nav_link#{ ' dd_hidden_page' if page.hidden }#{ ' dd_has_sub_pages' if page.has_sub_pages }" %>
<% end %>
View twitter stream parser
require 'rubygems'
require 'yajl'
require 'yajl/http_stream'
require 'uri'
require 'observer'
module Twroute
class Tweeter
include Observable
bhauman / just the host and scheme from a uri
Created Dec 2, 2009
sometimes you you ask for a hostname and you want to offer your user the option of entering the 'http://' or not
View just the host and scheme from a uri
def scheme_host(url)
p_uri = URI.parse(url)
p_uri.scheme = 'http'
return nil if == 'http' = url if !, :host).join('://')
rescue URI::InvalidURIError
rescue URI::InvalidComponentError
View ruby time format
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%C - Century (20 in 2009)
%d - Day of the month (01..31)
%D - Date (%m/%d/%y)
%e - Day of the month, blank-padded ( 1..31)
%F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
View layout_wrapper.rb
require 'rack'
# sudo gem install tilt --source
require 'tilt'
# A simple Rack middleware which makes it super easy
# have a shared layout rendering system used across
# different rails applications.
# Examples:
View fix_for_chrome_frame_rails_ajax.rb
This is quick fix for getting Rails to recognize Chrome Frame XmlHttpRequests as
Ajax Requests so that the following code will work.
respond_to do |format|
format.js { render :text => "chrome frame won't normally see this" }
View no_www.rb
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
def call(env)
You can’t perform that action at this time.