Skip to content

Instantly share code, notes, and snippets.

View ctcherry's full-sized avatar
🎯
Rusty Gopher

Chris Cherry ctcherry

🎯
Rusty Gopher
View GitHub Profile
@ctcherry
ctcherry / gist:236251
Created November 16, 2009 19:22
Regular expression to validate URLs
Regular expression to validate URLs
^https?\:\/\/[a-z0-9\-]+(\.[a-z0-9\-]+)+(\:\d{1,5})?(/|/[a-z0-9\_\-\/\?\=\.]*)?$
VALID
http://chrischerry.name
https://chrischerry.name
http://chrischerry.name/
http://chrischerry.name:1234/
@ctcherry
ctcherry / gist:221740
Created October 29, 2009 19:47
100 slowest requests from standard rails log
grep "Completed in [0-9]\{0,\}ms" log/production.log | sort -g -k3 | tail -100
module Rack
class Roll
def initialize(app)
@app = app
end
def call(env)
if roll?
return [302, {'Location' => 'http://www.youtube.com/watch?v=oHg5SJYRHA0'}, ["You've been rick rolled"]]
# application_controller.rb
before_filter :hijack_ie_default_format
def hijack_ie_default_format
if request.user_agent =~ /MSIE/ and params['format'].nil?
params['format'] = 'html'
end
end
@ctcherry
ctcherry / gist:48519
Created January 18, 2009 01:54 — forked from Lytol/gist:45845
# Rails template for a basic project assuming the following:
#
# - SQLite for DB
# - Git for version control
#
# Based on a similar template by: Brian Smith ([email protected])
# Basic housekeeping
#
run "rm public/index.html"
#!/bin/bash
if [ -d $1 ]; then
echo "Directory $1 already exists"
exit
else
echo "Creating Rails project in ./$1 using edge rails..."
echo "- Making directory $1"
mkdir $1
*if block:*
Pretty straightforward.
<% if @property.floorplans.size == 1 %>
<div>Show This if the property only has 1 floorplan</div>
<% else %>
<div>Show This if the property has any other number of floorplans</div>
<% end %>
github = GitHub.new
gist = github.create_application('gist')
gist.make_most_awesome_paste_site!