This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://snippets.dzone.com/posts/show/5364 | |
| Strftime to get the ISO 8601 (see RFC 3339) full date format for an hEvent Microformat. Doubtless usable in other situations. | |
| strftime('%Y-%m-%dT%H:%M:%S%z'); | |
| If you're in Ruby, you can access this the quick way with: | |
| $ irb | |
| >> require 'time' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Ability | |
| include CanCan::Ability | |
| def initialize(user) | |
| user ||= User.new # guest user | |
| if user.role? :admin | |
| can :manage, :all | |
| else | |
| can :read, :all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Autotest.add_hook :initialize do |at| | |
| at.add_exception %r%^\./tmp% | |
| at.add_exception "rerun.txt" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >> SignedRequest.sign({:dude => 12345}, "awesome") | |
| => "1G3Ir3a1zIf90c/XbajOYPzQXWQ=" | |
| >> SignedRequest.validate({:dude => 12345}, "awesome") | |
| => false | |
| >> SignedRequest.validate({:dude => 12345, :signature => "1G3Ir3a1zIf90c/XbajOYPzQXWQ="}, "awesome") | |
| => false | |
| >> SignedRequest.validate({:dude => 12345, "signature" => "1G3Ir3a1zIf90c/XbajOYPzQXWQ="}, "awesome") | |
| => true | |
| hash = params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://github.com/rails/rails/blob/136962322b8da0d6c09b4962194216cc4d248130/actionpack/lib/action_view/vendor/builder/xmlbase.rb | |
| # http://github.com/rails/rails/blob/8272630ce8af0546e7d1aa9211a9d91b80700cbd/activerecord/lib/active_record/serializers/xml_serializer.rb | |
| # http://github.com/rails/rails/blob/8272630ce8af0546e7d1aa9211a9d91b80700cbd/activerecord/lib/active_record/serialization.rb | |
| module Builder | |
| class XmlBase < BlankSlate | |
| def method_missing(sym, *args, &block) | |
| "fekja!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >> nil.singularize | |
| NoMethodError: undefined method `singularize' for nil:NilClass | |
| from /Users/awesome/.rvm/gems/ruby-1.8.6-p399/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:in `method_missing' | |
| from (irb):7 | |
| >> class NilClass | |
| >> def singularize | |
| >> return nil | |
| >> end | |
| >> end | |
| => nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 <% content_for :head do -%> | |
| 2 <!-- required stylesheet for TextboxList --> | |
| 3 <link rel="stylesheet" href="/widgets/textboxlist/TextboxList.css" type="text/css" media="screen" charset="utf-8" /> | |
| 4 | |
| 5 <!-- required stylesheet for TextboxList.Autocomplete --> | |
| 6 <link rel="stylesheet" href="/widgets/textboxlist/TextboxList.Autocomplete.css" type="text/css" media="screen" charset="utf-8" /> | |
| 7 | |
| 8 <script src="/widgets/textboxlist/mootools-1.2.1-core-yc.js" type="text/javascript" charset="utf-8"></script> | |
| 9 | |
| 10 <!-- required for TextboxList --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # patch, microformat datetime iso8601 | |
| # http://github.com/rails/rails/blob/master/activesupport/lib/active_support/time_with_zone.rb | |
| # http://microformats.org/wiki/date-design-pattern | |
| module ActiveSupport | |
| class TimeWithZone | |
| # The full datetime-design-pattern has the format | |
| # YYYY-MM-DDTHH:MM:SS+ZZ:ZZ | |
| def mf | |
| offset = time.strftime("%z").sub(/(\d{2}$)/, ':\1') | |
| time.strftime("%Y-%m-%dT%H:%M:%S#{offset}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # patch, nokogiri skip_instruct & indent | |
| # http://github.com/tenderlove/nokogiri/blob/master/lib/nokogiri/xml/builder.rb | |
| require 'nokogiri' | |
| module Nokogiri | |
| module XML | |
| class Builder | |
| def to_xml(*args) | |
| dok = @doc.to_xml(*args) | |
| if args.last.is_a?(Hash) | |
| args.last.each do |k,v| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://ircarchive.info/rubyonrails/2007/4/13/30.html | |
| >> "DudeAwesome".underscore | |
| => "dude_awesome" |