Skip to content

Instantly share code, notes, and snippets.

View kevinold's full-sized avatar

Kevin Old kevinold

View GitHub Profile
require 'rss/2.0'
require 'open-uri'
module ApplicationHelper
class EmptyURL < RuntimeError
end
def rss_content(name)
content_object = StaticContent.find_by_name(name)
if content_object.nil? || (Time.now - content_object.updated_at) > 4.hours
@kevinold
kevinold / example_note_keeping_app.rb
Created February 16, 2010 17:39 — forked from pietern/example_note_keeping_app.rb
Notes app using Redis and Sinatra
require 'rubygems'
require 'sinatra'
require 'redis'
# To use, simply start your Redis server and boot this
# example app with:
# ruby example_note_keeping_app.rb
#
# Point your browser to http://localhost:4567 and enjoy!
#
@kevinold
kevinold / icalendar.rb
Created March 9, 2010 03:26 — forked from shanlalit/icalendar.rb
ruby google calendar class
require 'net/http'
require 'uri'
require 'time'
class Time
def self.gcalschema(tzid) # We may not be handling Time Zones in the best way...
tzid =~ /(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)Z/ ? # yyyymmddThhmmss
# Strange, sometimes it's 4 hours ahead, sometimes 4 hours behind. Need to figure out the timezone piece of ical.
# Time.xmlschema("#{$1}-#{$2}-#{$3}T#{$4}:#{$5}:#{$6}") - 4*60*60 :
Time.xmlschema("#{$1}-#{$2}-#{$3}T#{$4}:#{$5}:#{$6}") :
@kevinold
kevinold / application.html.erb
Created January 19, 2011 20:40 — forked from ryanb/application.html.erb
Example of very simple password authentication.
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
@kevinold
kevinold / deploy.rb
Created July 26, 2011 17:17 — forked from uhlenbrock/deploy.rb
Simple Capistrano recipe for Jekyll
set :application, 'foo'
set :repository, '_site'
set :scm, :none
set :deploy_via, :copy
set :copy_compression, :gzip
set :use_sudo, false
set :host, '127.0.0.1'
role :web, host
role :app, host
@kevinold
kevinold / deploy.rb
Created July 26, 2011 20:55 — forked from jeronimo/deploy.rb
Capistrano recipe to sync rails MongoDB and files
set :sync_directories, ["public/system/images"]
set :sync_backups, 3
set :db_file, "mongoid.yml"
set :db_drop, '--drop' # drop database (rewrites everything)
@kevinold
kevinold / deploy.rb
Created July 26, 2011 20:57 — forked from netzpirat/deploy.rb
Capistrano recipe to sync rails database and files within a multi stage environment
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3
@kevinold
kevinold / deploy.rb
Created July 26, 2011 20:58 — forked from LRDesign/deploy.rb
Capistrano recipe to sync rails database and files, using remote database.yml instead of local for remote credentials
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3
@kevinold
kevinold / trivial_file_upload_service.rb
Created August 8, 2011 15:58
Upload file in Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
# or just go to http://localhost:4567/user/filename with a browser
get '/:name/:filename' do
@kevinold
kevinold / friendly_urls.markdown
Created September 12, 2011 02:04 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.