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
| This is purely for testing. |
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
| def self.factory(plugin, &block) | |
| candidates = self.plugin_paths.map do |path| | |
| Dir["#{path}/#{plugin.to_s.downcase}.rb"][0] | |
| end | |
| candidate = candidates.detect(&:any?) | |
| if candidate | |
| require candidate | |
| Plugin.const_get(plugin.to_s.capitalize.to_sym).new(&block) | |
| else | |
| raise YourSystem::PluginNotFound, "The #{plugin} plugin could not be loaded" |
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
| { | |
| "actor_attributes": { | |
| "name": "John Britton", | |
| "gravatar_id": "efc09baeb94ed440b185710062c8956d", | |
| "location": "New York", | |
| "blog": "http://www.johndbritton.com", | |
| "type": "User", | |
| "login": "johndbritton", | |
| "email": "[email protected]" | |
| }, |
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
| andy@adl91desktop:~/tmp$ ls -alh setuid.rb | |
| -rwsr-sr-x 1 root root 38 2011-01-06 14:39 setuid.rb | |
| andy@adl91desktop:~/tmp$ cat setuid.rb | |
| #!/usr/bin/env ruby | |
| puts Process.uid | |
| andy@adl91desktop:~/tmp$ ./setuid.rb | |
| 1000 |
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
| require 'rubygems' | |
| require 'nokogiri' | |
| require 'open-uri' | |
| class Ride4Ruby | |
| def find_distance_between_farthest | |
| farthest_west, farthest_east = find_farthest_west_and_east | |
| $stderr.puts "Farthest west: #{farthest_west}" | |
| $stderr.puts "Farthest east: #{farthest_east}" |
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 Foo | |
| def self.blah | |
| "foo" | |
| end | |
| end | |
| puts Foo.blah # "foo" | |
| Foo.define_singleton_method :blah, do | |
| "hijink" |
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 Model < ActiveRecord::Base | |
| # Just as an example, encode as JSON/XML | |
| # excluding the created_at attribute | |
| def serializable_hash(options = nil) | |
| options ||= {} | |
| (options[:except] ||= []) << :created_at | |
| super(options) | |
| end | |
| 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
| $(function() { | |
| // This happens when the DOM is ready | |
| $('#my_button').bind('click', function(e) { | |
| alert('omg it worked'); | |
| }); | |
| }); |
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
| # Set these appropriately | |
| monkey_a = 1 | |
| monkey_b = 1 | |
| problem = if monkey_a == monkey_b | |
| "problem" | |
| else | |
| "not a problem" | |
| 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
| def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil | |
| nil.some_method_nil_doesnt_know_about | |
| rescue Exception => ex | |
| puts ex.class | |
| end | |
| test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil |