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 MarsRover | |
def initialize(current_direction) | |
@direction = current_direction | |
end | |
def turn_left | |
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
require 'mysql2' | |
# Change the host and password | |
client = Mysql::Client.new(:host => "localhost", :username => "root") | |
# Fetch running processes | |
processes = client.query("SHOW FULL PROCESSLIST") | |
processes.each do |process| | |
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
puts "Testing gists in Twitter" |
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 Template < ActiveRecord::Base | |
validates_uniqueness_of :name | |
# Set default values in this hash | |
DEFAULT_VALUES = {:community => "Ruby on Rails"} | |
# Find template by its name | |
# @template = Template.where(:name => "welcome_message").first | |
# Template has the following message attribute |
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' | |
# Add/Remove required letters - some letters might not be the starting letter for any company name | |
# alphabet = ["A","B","C","D","E","F","G","H","J","I","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] | |
# To choose all letters | |
alphabet = ('A'..'Z').to_a | |
categories = alphabet << "[0-9]" | |
["A","B","S","T","TS","Z"].each do |letter1| |
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 'uri' | |
require 'json' | |
require 'net/http' | |
uri = URI.parse("http://services.digg.com/2.0/story.getTopNews.json") | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request.initialize_http_header({"User-Agent" => "Agent/1.0"}) | |
response = http.request(request) | |
data = JSON.parse(response.body) |
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 attribute_present?(attribute) | |
value = read_attribute(attribute) | |
!value.blank? | |
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 dup | |
obj = super | |
obj.instance_variable_set('@attributes', @attributes.dup) | |
obj | |
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
# Custom directories with classes and modules you want to be autoloadable. | |
# config.autoload_paths += %W(#{config.root}/extras) |
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 add_association_callbacks(association_name, options) | |
callbacks = %w(before_add after_add before_remove after_remove) | |
callbacks.each do |callback_name| | |
full_callback_name = "#{callback_name}_for_#{association_name}" | |
defined_callbacks = options[callback_name.to_sym] | |
if options.has_key?(callback_name.to_sym) | |
class_inheritable_reader full_callback_name.to_sym | |
write_inheritable_attribute(full_callback_name.to_sym, [defined_callbacks].flatten) | |
else | |
write_inheritable_attribute(full_callback_name.to_sym, []) |