Skip to content

Instantly share code, notes, and snippets.

View unders's full-sized avatar

Anders Törnqvist unders

  • Functionbox
  • Göteborg, Sweden
View GitHub Profile
@jimweirich
jimweirich / exceptions.rb
Created March 7, 2011 02:55
How to organize exceptions in your library
# Suppose you were designing a library named "Zippo".
# How would you organize the exceptions thrown by the library.
# Option 1
# All library errors inheriting from a common base
module Zippo
class ZippoError < StandardError; end
class ZippoArgumentError < ZippoError; end
class ZippoTypeError < ZippoError; end
@dbi
dbi / edit.html.mustache
Created May 4, 2011 09:31
Rails form helper for mustache spike/proof of concept
<!-- A scaffolded edit view converted to mustache -->
<h1>Editing post</h1>
{{#form}}
{{#errors?}}
<div id="error_explanation">
<h2>{{error_header}}</h2>
</div>
<ul>
@ryanb
ryanb / rails_3_1_rc4_changes.md
Created May 6, 2011 01:10
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 RC4

  • The new rake task assets:clean removes precompiled assets. [fxn]

  • Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]

  • Fixed database tasks for jdbc* adapters #jruby [Rashmi Yadav]

  • Template generation for jdbcpostgresql #jruby [Vishnu Atrai]

@Gregg
Gregg / gist:968534
Created May 12, 2011 13:54
Code School Screencasting Framework

Screencasting Framework

The following document is a written account of the Code School screencasting framework. It should be used as a reference of the accompanying screencast on the topic.

Why you should care about screencasting?

You're probably aren't going to take the time to read this document if you're not interested, but there are a lot of nice side effects caused by learning how to create quality screencasts.

  1. Communicating more effectively - At Envy Labs we produce screencasts for our clients all the time. Whether it's demoing a new feature or for a presentation for an invester, they're often much more effective and pleasent than a phone call or screen sharing.
@cdcarter
cdcarter / form_helper.rb
Created June 4, 2011 02:52
NS Form Helper Class
class FormHelper
attr_accessor :form
def initialize(nsform=nil)
@form = nsform
end
def length
form.numberOfRows
end
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@nevans
nevans / method_vs_constant_lookup.rb
Created August 19, 2011 15:50
demonstrating the difference between method and constant lookup
#!/usr/bin/env ruby
module TopLevel
CONST_D = :d_from_top_level
module MiddleLevel
class BottomLevel
CONST_A = :foo
CONST_B = :bar
CONST_C = :c_from_bottom_level
@reagent
reagent / credential.rb
Created September 28, 2011 19:01
Sample code from my Using OO to Manage Control Flow post
class Credential
include ActiveModel::Validations
attr_accessor :screen_name, :oauth_token, :oauth_secret, :token, :description
validates_presence_of :screen_name, :oauth_token, :oauth_secret, :message => 'required'
validate :user_exists, :unless => :errors?
def initialize(attributes = {})
attributes.each {|k, v| set_recognized_attribute(k, v) }
###
# This is a JSON building library. It allows you to build data structures
# to dump as JSON. Here is a sample of how to use it:
#
# def person_hash(person)
# {
# 'name' => person.name,
# 'age' => person.age,
# 'friends' => person.friends.map { |x| person_hash x }
# }
@unders
unders / gist:1427613
Created December 3, 2011 17:17 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end