Skip to content

Instantly share code, notes, and snippets.

View jamesarosen's full-sized avatar

James A Rosen jamesarosen

View GitHub Profile
require 'pathname'
module Rack
class AbstractFormat
def initialize(app, default = nil)
@app, @default = app, default
end
def call(env)
context "on GET to :index, :format => 'ics' with events in the future" do
setup do
@next = Factory(:event, :title => 'Fun Times', :date => 2.days.from_now)
Event.stubs(:next).returns([@next])
get :index, :format => 'ics'
end
should_assign_to(:events) { [@next] }
should_respond_with :success
should 'render a valid iCal object' do
assert_nothing_raised do

###First instinct: hierarchical date URLs###

/people/:id                   - show person as-of latest
/people/:year/:id             - show person as-of Y
/people/:year/:month/:id      - show person as-of Y/M
/people/:year/:month/:day/:id - show person as-of Y/M/D
  • Pro: well-known URL pattern, common in blogs
  • Con: can't distinguish /people/2004 (list people as-of 2004) From /people/2004 (show latest of person 2004)
  • Con: /people/2004 really should be an list of months, not people
<!--
Example static page file for use with high_voltage.
Goes in RAILS_ROOT/app/views/pages/about.html.erb
-->
<!--
Set the title content.
Note the lack of an '=' at the front of this tag:
-->
<% content_for :title do %>
module Rack
class Lockdown
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if ["GET", "HEAD"].include?(request.request_method)

My application for the Ruby Mendicant University

My solution uses the command pattern to keep a history of all atomic edits. This makes add_text, remove_text, undo, and redo very fast since they are just additions to an Array or moving the "current-state-of-document" pointer along the Array of edits.

There is, however a downside to this approach. Since this implementation considers the edits Array to be the canonical representation of the document, the output version

$ rvm --debug package install readline
info: Fetching readline-5.2.tar.gz to /Users/me/.rvm/archives
debug: Fetching readline-5.2.tar.gz
debug: No archive or no MD5, downloading
curl: (5) Couldn't resolve proxy '[myproxy]'
# A proposal for a method to be added to Bundler::Dsl that will import
# dependencies from your gemspec. This is useful for Gems that use Bundler
# to manage their dependencies and want to keep the Gemfile and .gemspec
# sync'ed up.
#
# There already exists a method that goes the other way:
# `add_bundler_dependencies`. It works OK but is considered a failed
# experiment and is likely to be deprecated. Yehuda Katz's 'newgem-template'
# project (http://github.com/wycats/newgem-template) uses
# .gemspec -> Gemfile rather than Gemfile -> .gemspec for importing.
require 'action_view/helpers/form_helper'
# in config/initializers/label_tag_with_i18n
#
# Now when you use a label in a form builder,
# you get the internationalized version. (This is
# already done in Rails 3.)
#
# Example:
#
// ==UserScript==
// @name GitHub Badges
// @description Unread message counts for GitHub Fluid App
// @namespace http://github.com/jamesarosen
// @homepage http://gist.github.com/489842
// @author James A. Rosen
// @include http*://github.com/*
// @include http*://*.github.com/*
// ==/UserScript==