code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
module Oos4ruby
class User < Bean::BeanClass
include Bean
define_el_reader({
OosNamespace => [:name, :surname, :no_mails, :only_contacts, :no_newsletter],
AtomNamespace => [:title, :updated, :content]
})
alias :nick :title
alias :about_me :content
attr_reader :slug
attr_writer :nick, :... | Ruby |
module Oos4ruby
=begin rdoc
This class wraps feed response. You must use its subclass, Oos4ruby::Sites, Oos4ruby::Contacts, Oos4ruby::Medias
API feed response is paginated, so, this class provides some methods to explore the feed.
=end
class Collection < Array
def initialize(feed, auth, slug = nil)
@... | Ruby |
module Oos4ruby
class Site < Bean::BeanClass
include Bean
define_el_reader(
{
OosNamespace => [:id, :user_address, :url, :locality, :subadministrativearea, :country, :telephone],
AppNamespace => [:edited],
AtomNamespace => [:title, :updated, :summary, :content]
}
)
define_attr_re... | Ruby |
require 'cgi'
module Oos4ruby
class Search
=begin rdoc
Method to search services/places into 11870. Returns a Sites collection
available parameters:
<tt>q</tt>:: string that represents a siple query.
<tt>bbox</tt>:: array of points that delimiters a rectangle, SW and NE.
<tt>as</tt>:: area specified by a ... | Ruby |
module Oos4ruby
class Contacts < Collection
end
end
| Ruby |
require 'rexml/document'
require 'rexml/xpath'
module Oos4ruby
class Entry
def initialize(node)
if node.class == String
@element = REXML::Document.new(node, { :raw => nil }).root
else
@element = node
end
end
def to_s
"<?xml version='1.0' ?>\n" + @element.to_s
end
def child... | Ruby |
require 'rexml/document'
require 'rexml/xpath'
module Oos4ruby
class Feed
attr_reader :previous, :next, :entries, :xml, :size, :total_size
def initialize(entries, xml)
@entries = entries
@xml = xml
@next = Feed.get_link('next', xml)
@previous = Feed.get_link 'previous', xml
@self = Feed.get... | Ruby |
require 'net/http'
module Oos4ruby
class HTTPInvoker
attr_reader :response, :headers, :entry, :body
def initialize(uri, authent)
@uri = (uri if uri.kind_of?URI) || URI.parse(uri)
@authent = authent
@headers = {}
@entry = nil
end
def set_header(name, val)
@headers[name.to_s.gs... | Ruby |
require 'rexml/document'
require 'rexml/xpath'
module Oos4ruby
class Oos
def auth_app(app_token, secret_key)
@auth = Auth.new(app_token, secret_key, :app)
end
def auth_user(email, api_token)
@auth = Auth.new(email, api_token, :wsse)
document_service
end
def user(slug ... | Ruby |
module Oos4ruby
class Medias < Collection
end
end
| Ruby |
require 'digest/md5'
require 'digest/sha1'
class Auth
def initialize(username, password, method)
@username = username
@password = password
@method = method
end
def add_to(req)
wsse(req) if method?:wsse
app(req) if method?:app
end
def method?(method)
@method == method
end
... | Ruby |
require File.dirname(__FILE__) + '/test_helper'
class TestSearch < Test::Unit::TestCase
VALID_PARAMS = {
:q => 'gloria',
:tags => ['madrid', 'barcelona'],
:as => '/es',
:bbox => ['23452345', '345325', '23434', '32453245'],
:tag_op => 'and',
:lon => '2345',
:lat => '234234',
:radius =... | Ruby |
require File.dirname(__FILE__) + '/test_helper.rb'
require 'rubygems'
require File.dirname(__FILE__) + '/../lib/oos4ruby.rb'
=begin
puts user.name
puts user.surname
puts user.no_mails
puts user.no_newsletter
puts user.only_contacts
user.no_mails = user.no_mails == 'true'?'false':'true'
user.no_newslette... | Ruby |
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/oos4ruby'
| Ruby |
require 'fileutils'
include FileUtils
require 'rubygems'
%w[rake hoe newgem rubigen].each do |req_gem|
begin
require req_gem
rescue LoadError
puts "This Rakefile requires the '#{req_gem}' RubyGem."
puts "Installation: gem install #{req_gem} -y"
exit
end
end
$:.unshift(File.join(File.dirname(__FI... | Ruby |
require 'oos4ruby/version'
AUTHOR = 'David Calavera' # can also be an array of Authors
EMAIL = "david.calavera@gmail.com"
DESCRIPTION = "oos4ruby is a ruby binding for the 11870 API"
GEM_NAME = 'oos4ruby' # what ppl will type to install your gem
RUBYFORGE_PROJECT = 'oos4r' # The unix name for your project
HOMEPATH = ... | Ruby |
#
# setup.rb
#
# Copyright (c) 2000-2005 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
#
unless Enumerable.method_defined?(:map) # Ruby 1.4.6
module Enumerable
alias map collect
end
end
un... | Ruby |
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration
Dir['tasks/**/*.rake'].each { |rake| load rake } | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
begin
require 'newgem'
rescue LoadError
puts "\n\nGenerating the website requires the newgem RubyGem"
puts "Install: gem install newgem\n\n"
exit(1)
end
require 'redcloth'
require 'syntax/convertors/html'
require 'erb'
require File.dirname(__FILE__) + '/../lib/oos4ruby/ve... | Ruby |
#!/usr/bin/env ruby
APP_ROOT = File.join(File.dirname(__FILE__), '..')
begin
require 'rubigen'
rescue LoadError
require 'rubygems'
require 'rubigen'
end
require 'rubigen/scripts/destroy'
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
Rub... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
begin
require 'newgem'
rescue LoadError
puts "\n\nGenerating the website requires the newgem RubyGem"
puts "Install: gem install newgem\n\n"
exit(1)
end
require 'redcloth'
require 'syntax/convertors/html'
require 'erb'
require File.dirname(__FILE__) + '/../lib/oos4ruby/ve... | Ruby |
#!/usr/bin/env ruby
APP_ROOT = File.join(File.dirname(__FILE__), '..')
begin
require 'rubigen'
rescue LoadError
require 'rubygems'
require 'rubigen'
end
require 'rubigen/scripts/generate'
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
Ru... | Ruby |
#!/usr/bin/env ruby
APP_ROOT = File.join(File.dirname(__FILE__), '..')
begin
require 'rubigen'
rescue LoadError
require 'rubygems'
require 'rubigen'
end
require 'rubigen/scripts/destroy'
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
Rub... | Ruby |
#!/usr/bin/env ruby
APP_ROOT = File.join(File.dirname(__FILE__), '..')
begin
require 'rubigen'
rescue LoadError
require 'rubygems'
require 'rubigen'
end
require 'rubigen/scripts/generate'
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
Ru... | Ruby |
desc 'Generate website files'
task :website_generate => :ruby_env do
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
end
end
desc 'Upload website files to rubyforge'
task :website_upload do
host = "#{rubyforge_usern... | Ruby |
task :ruby_env do
RUBY_APP = if RUBY_PLATFORM =~ /java/
"jruby"
else
"ruby"
end unless defined? RUBY_APP
end
| Ruby |
desc 'Release the website and new gem version'
task :deploy => [:check_version, :website, :release] do
puts "Remember to create SVN tag:"
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
put... | Ruby |
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module Oos4ruby
class UnknownUser < ArgumentError; end
AtomNamespace = 'http://www.w3.org/2005/Atom'
AppNamespace = 'http://www.w3.org/2007/app'
OosNamespace = 'http://118... | Ruby |
module Oos4ruby
class Category
include Bean
define_attr_reader({
AtomNamespace => [:term, :scheme],
OosNamespace => [:frecuency]
})
def initialize(term, scheme = nil)
unless term.instance_of?(REXML::Element)
@term = term
@scheme = scheme
@xml = REXML::Element.new 'category'
... | Ruby |
module Oos4ruby
module Bean #:nodoc:
def self.append_features(base)
super
base.extend(ClassMethods)
end
module ClassMethods #:nodoc:
def define_el_reader(opts = {})
if !opts.empty?
opts.each_pair { |key, value|
value.each { |field_name|
define_method(field_name) ... | Ruby |
module Oos4ruby
class Sites < Collection
end
end
| Ruby |
module Oos4ruby
class Media < Bean::BeanClass
include Bean
define_el_reader AtomNamespace => [:title, :updated, :content]
define_attr_reader AtomNamespace => {:content => :type, :content => :src}
attr_writer :title
def initialize(entry, auth, slug = nil)
@xml = entry
@au... | Ruby |
#
module Oos4ruby
class Service
attr_reader :xml
def initialize(xml)
@xml = xml
end
end
end
| Ruby |
module Oos4ruby
class Contact < Bean::BeanClass
include Bean
define_el_reader AtomNamespace => [:title, :updated]
attr_writer :trusted
alias :nick :title
def initialize(xml, auth, slug)
@xml = xml
@auth = auth
@slug = slug
end
=begin rdoc
find all user contacts
=end
def Co... | Ruby |
module Oos4ruby #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 2
TINY = 1
STRING = [MAJOR, MINOR, TINY].join('.')
end
end
| Ruby |
module Oos4ruby
class User < Bean::BeanClass
include Bean
define_el_reader({
OosNamespace => [:name, :surname, :no_mails, :only_contacts, :no_newsletter],
AtomNamespace => [:title, :updated, :content]
})
alias :nick :title
alias :about_me :content
attr_reader :slug
attr_writer :nick, :... | Ruby |
module Oos4ruby
=begin rdoc
This class wraps feed response. You must use its subclass, Oos4ruby::Sites, Oos4ruby::Contacts, Oos4ruby::Medias
API feed response is paginated, so, this class provides some methods to explore the feed.
=end
class Collection < Array
def initialize(feed, auth, slug = nil)
@... | Ruby |
module Oos4ruby
class Site < Bean::BeanClass
include Bean
define_el_reader(
{
OosNamespace => [:id, :user_address, :url, :locality, :subadministrativearea, :country, :telephone],
AppNamespace => [:edited],
AtomNamespace => [:title, :updated, :summary, :content]
}
)
define_attr_re... | Ruby |
require 'cgi'
module Oos4ruby
class Search
=begin rdoc
Method to search services/places into 11870. Returns a Sites collection
available parameters:
<tt>q</tt>:: string that represents a siple query.
<tt>bbox</tt>:: array of points that delimiters a rectangle, SW and NE.
<tt>as</tt>:: area specified by a ... | Ruby |
module Oos4ruby
class Contacts < Collection
end
end
| Ruby |
require 'rexml/document'
require 'rexml/xpath'
module Oos4ruby
class Entry
def initialize(node)
if node.class == String
@element = REXML::Document.new(node, { :raw => nil }).root
else
@element = node
end
end
def to_s
"<?xml version='1.0' ?>\n" + @element.to_s
end
def child... | Ruby |
require 'rexml/document'
require 'rexml/xpath'
module Oos4ruby
class Feed
attr_reader :previous, :next, :entries, :xml, :size, :total_size
def initialize(entries, xml)
@entries = entries
@xml = xml
@next = Feed.get_link('next', xml)
@previous = Feed.get_link 'previous', xml
@self = Feed.get... | Ruby |
require 'net/http'
module Oos4ruby
class HTTPInvoker
attr_reader :response, :headers, :entry, :body
def initialize(uri, authent)
@uri = (uri if uri.kind_of?URI) || URI.parse(uri)
@authent = authent
@headers = {}
@entry = nil
end
def set_header(name, val)
@headers[name.to_s.gs... | Ruby |
require 'rexml/document'
require 'rexml/xpath'
module Oos4ruby
class Oos
def auth_app(app_token, secret_key)
@auth = Auth.new(app_token, secret_key, :app)
end
def auth_user(email, api_token)
@auth = Auth.new(email, api_token, :wsse)
document_service
end
def user(slug ... | Ruby |
module Oos4ruby
class Medias < Collection
end
end
| Ruby |
require 'digest/md5'
require 'digest/sha1'
class Auth
def initialize(username, password, method)
@username = username
@password = password
@method = method
end
def add_to(req)
wsse(req) if method?:wsse
app(req) if method?:app
end
def method?(method)
@method == method
end
... | Ruby |
require File.dirname(__FILE__) + '/test_helper'
class TestSearch < Test::Unit::TestCase
VALID_PARAMS = {
:q => 'gloria',
:tags => ['madrid', 'barcelona'],
:as => '/es',
:bbox => ['23452345', '345325', '23434', '32453245'],
:tag_op => 'and',
:lon => '2345',
:lat => '234234',
:radius =... | Ruby |
require File.dirname(__FILE__) + '/test_helper.rb'
require 'rubygems'
require File.dirname(__FILE__) + '/../lib/oos4ruby.rb'
=begin
puts user.name
puts user.surname
puts user.no_mails
puts user.no_newsletter
puts user.only_contacts
user.no_mails = user.no_mails == 'true'?'false':'true'
user.no_newslette... | Ruby |
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/oos4ruby'
| Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'postgres'
puts "main__"
calls = [
["UK London", "+4455665566", "Holland Amsterdam",
"+3155665566", "17"],
["UK London", "+4455665566", "Sweden Stockholm",
"+3155665566", "7"],
["UK London", "+4455665566", "France Paris",... | Ruby |
#!/usr/bin/env ruby
=begin
rspec example
install rspec by gem install rspec --remote
=end
module Spec_helper
def print_spec(msg)
puts msg
end
end
class Customer
accessor_list = :name, :company
def initialize(name, company)
@name, @company = name, company
end
... | Ruby |
#!/usr/bin/env ruby
=begin
=end
line = %w{Python is a great scripting language, Why can't everyone learn Python and Why is Perl not used anymore}
class Logger
private_class_method :new
@@logger = nil
def Logger.create
new unless @@logger
end
end
class Customer
def initialize(na... | Ruby |
#
# To change this template, choose Tools | Templates
# and open the template in the editor.
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
spec = Gem::Specification.new do |s|
s.name = 'ec2client'
s.version = '0.0.1'
s.has... | Ruby |
require 'aws'
class EC2
include AWS
ENDPOINT_URI = URI.parse(ENV['EC2_URL'])
API_VERSION = '2008-08-08'
SIGNATURE_VERSION = 1
HTTP_METHOD = 'GET'
def describe_images(options={})
parameters = build_query_params(API_VERSION, SIGNATURE_VERSION,
{
'Action' => 'DescribeImages',
}, {
'ImageId' => op... | Ruby |
require 'openssl'
require 'digest/sha1'
require 'base64'
require 'cgi'
require 'net/https'
require 'time'
require 'uri'
require 'rexml/document'
$KCODE = 'u' # Enable Unicode support
module AWS
attr_accessor :aws_access_key, :aws_secret_key, :secure_http, :debug
attr_reader :time_offset
def initialize(debug=false... | Ruby |
# Simple AWS Test
#require 'rubygems'
#require 'aws'
#
#include AWS
#
#@debug = true
#@aws_secret_key = 'MySecretKey'
#
#uri = URI.parse('http://s3.amazonaws.com/mybucket/myfile?acl')
#puts generate_rest_signature('GET', uri, {})
# EC2 describe_images test
require 'ec2'
e = EC2.new(debug=false)
puts e.describe_images... | Ruby |
#!/usr/bin/env ruby
require 'yaml'
require 'yaml/syck'
config = YAML::load_file("config.yml")
puts config.values | Ruby |
#!/usr/bin/env ruby
require 'postgres'
def connect_db
begin
conn = PGconn.new("localhost", 5432, nil, nil , "CAT_STAGING", "nauman", "password")
rescue PGError => err
p "Exception:", err
end
return conn if conn
end
conn = connect_db
#arrIns = [%W{EntryId2 AppId2 AppOwner2 Appname2 AppM... | Ruby |
#!/usr/bin/env ruby
require 'dbi'
require 'singleton'
class Database
include Singleton
attr_reader :connection
def initialize()
@connection = nil;
end
def connect(connStr, usr, pwd)
@connection = DBI.connect(connStr, usr, pwd)
end
def disconnect
@... | Ruby |
#!/usr/bin/env ruby
require 'ldap'
require 'ldap/control'
require 'customer'
class Auth
def initialize(ldap_server, customer_dn)
@ldap_server = ldap_server
@customer_dn = customer_dn
end
def get_customer(username, password)
customer = nil
ldap = LDAP::Conn.new(@ldap_server)
login_dn = ... | Ruby |
#!/usr/bin/env ruby
=begin
Blocks are the most interesting and confusing feature of Ruby. Blocks are also known as closures and if you
are not familiar with Blocks or closures, think of them as anonymous method body.
As everything in Ruby is an object, a method is also a first class object. And since you c... | Ruby |
require 'rubygems'
require 'pp'
require 'date'
require 'FileUtils'
include ParseDate
source_directory=%q(E:\t)
file_type='session'
start_date=Date.new(2007,10,1)
end_date=Date.new(2007,10,15)
(start_date..end_date).each do |x|
file_path="#{source_directory}\\server.#{file_type}.log.#{x}"
if F... | Ruby |
#!/usr/bin/env ruby
require 'date'
=begin
=end
def shopping(*list)
list.each { |todo| puts todo }
end
#shopping "Milk", "Butter", "Meat"
puts Date::today()
| Ruby |
#!/usr/bin/env ruby
class Movie
attr_accessor :price, :type
def initialize(&block)
instance_eval(&block)
end
def justprint
puts "Type:#{self.type} and Price:#{self.price}"
end
def info
yield(self.type, self.price)
end
def infoo(&block)
ins... | Ruby |
#!/usr/bin/env ruby
class DefaultFilter
def process(data)
#printf(">>DefaultFilter:%s", data)
end
end
class MethodCallFilter < DefaultFilter
def initialize(expression, destination_file)
@match_expression = expression
end
def process(data)
if data =~ @match_express... | Ruby |
require 'rubygems'
module WithString
url = 'http://204.231.109.9/resources/compute/lamp/435'
url_regex = "/resources"
start_index = /#{url_regex}/ =~ url
puts url[start_index, url.length]
end
module WithRegex
url = 'http://204.231.109.9/resources/compute/lamp/435'
url_regex = %r{^http://[\d+\.]... | Ruby |
require 'rubygems'
require 'fit/column_fixture'
require 'fit/row_entry_fixture'
class CalculateDiv < Fit::ColumnFixture
attr_accessor :numerator,:denominator
def quotient()
numerator/denominator
end
end | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'active_record'
=begin
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:database => 'smsclient',
:user => 'nauman',
:password => 'password'
)
=end
ActiveRecord::Base.establish_connection(
:adapter => 'postg... | Ruby |
task :default => ["etlbuild:default"]
namespace :etlbuild do
desc "default task"
task :default do
puts "This is the default task"
end
desc "First task description"
task :firstTask do
puts "This is my first rake task"
end
desc "second task description"
... | Ruby |
#!/usr/bin/env ruby
=begin
For more information
http://rspec.rubyforge.org/documentation/mocks/mocks.html
=end
require 'postgres'
class Database
def initialize(host, port, database, user, pass)
@host, @port, @database, @user, @pass = host, port, database, user, pass
end
def connect()... | Ruby |
class CreateInstancesTable < ActiveRecord::Migration
def self.up
create_table :instances do |t|
t.column :instance_id, :string
t.column :event_date, :datetime
t.column :from_state, :string
t.column :to_state, :string
end
end
def self.down... | Ruby |
require 'rubygems'
require 'pp'
require 'activerecord'
config = YAML.load_file(File.join(File.dirname(__FILE__), 'database.yml'))
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => config[:development.to_s][:database.to_s])
class Instances < ActiveRecord::Base
end
class PrintFilter
def p... | Ruby |
require 'rubygems'
require 'activerecord'
if ARGV[0] =~ /VERSION=\d+/
version = ARGV[0].split('=')[1].to_i
else
version = nil
end
@logger = Logger.new $stderr
ActiveRecord::Base.logger = @logger
ActiveRecord::Base.colorize_logging = false
@config = YAML.load_file(File.join(File.dirname(__FILE__), 'database.y... | Ruby |
#!/usr/bin/env ruby
require 'test/unit'
class StringTest < Test::Unit::TestCase
def testStringLength
s = "Hello world"
assert_equal(11, s.length)
end
end
| Ruby |
#!/usr/bin/env ruby
begin
x = Math.sqrt(100)
raise ArgumentError.new("My own argument error")
rescue ArgumentError => err
p err
ensure
print "\nthis will always run."
# retry # to retry the begin block
end
| Ruby |
#!/usr/bin/env ruby
require 'dbi'
require 'singleton'
class Database
include Singleton
attr_reader :connection
def initialize()
@connection = nil;
end
def connect(connStr, usr, pwd)
@connection = DBI.connect(connStr, usr, pwd)
end
def disconnect
@... | Ruby |
#!/usr/bin/env ruby
class Customer < Struct.new(:name, :company)
end
c = Customer.new("John Doe", "MSFT")
puts %Q(#{c.name} - #{c.company})
house_data = Struct.new("Data", :houseno, :city, :country)
dt = house_data.new(32, "London", "UK")
print dt.inspect
| Ruby |
#!/usr/bin/env ruby
require 'yaml'
require 'yaml/syck'
config = YAML::load_file("config.yml")
puts config.values | Ruby |
#!/usr/bin/env ruby
str = "35 C"
temp, scale = str.split(" ")
if temp !~ /-?[0-9]+/
print temp, " is not valid.\n"
exit 1
end
temp = temp.to_f
case scale
when "C", "c"
f = 1.8*temp + 32
when "F", "f"
c = (5.0/9.0)*(temp-32)
else
print "Must specify C or F.\n"
... | Ruby |
#!/usr/bin/env ruby
require 'test/unit'
module DependencyInjection
IGNORED_SETTERS = ['==', '===']
# inject dependencies by matching getters on container with setters
# on object to recieve injection
def autowire_dependencies(instance)
container = self
instance.methods.each { |setter|
if sett... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'active_record'
=begin
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:database => 'smsclient',
:user => 'nauman',
:password => 'password'
)
=end
ActiveRecord::Base.establish_connection(
:adapter => 'postg... | Ruby |
#!/usr/bin/env ruby
class Movie
attr_accessor :price, :type
def initialize(&block)
instance_eval(&block)
end
def justprint
puts "Type:#{self.type} and Price:#{self.price}"
end
def info
yield(self.type, self.price)
end
def infoo(&block)
ins... | Ruby |
#!/usr/bin/env ruby
require 'logger'
require 'gserver'
class StatusMonitor < GServer
def initialize(host = "127.0.0.1", port=7654)
super(port, host)
@level_map = {
'w' => 'warn', 'e' => 'error', 'f' => 'fatal'
}
@logger = Logger.new(STDOUT)
end
def serve(cl... | Ruby |
#!/usr/bin/env ruby
=begin
Blocks are the most interesting and confusing feature of Ruby. Blocks are also known as closures and if you
are not familiar with Blocks or closures, think of them as anonymous method body.
As everything in Ruby is an object, a method is also a first class object. And since you c... | Ruby |
#!/usr/bin/env ruby
require 'test/unit'
class StringTest < Test::Unit::TestCase
def testStringLength
s = "Hello world"
assert_equal(11, s.length)
end
end
| Ruby |
#!/usr/bin/env ruby
require 'date'
=begin
=end
def shopping(*list)
list.each { |todo| puts todo }
end
#shopping "Milk", "Butter", "Meat"
puts Date::today()
| Ruby |
#!/usr/bin/env ruby
require 'dbi'
require 'database'
Database.instance.connect('DBI:Mysql:smsclient', 'ag3nt', 'password')
email = 'abc@hotmail.com'
sql = "select name, email, number, keyword, provision_date, expiration_date from customers where email = '#{email}' and enabled=true"
Database.instance.connection.selec... | Ruby |
#!/usr/bin/env ruby
require 'ldap'
require 'ldap/control'
require 'customer'
class Auth
def initialize(ldap_server, customer_dn)
@ldap_server = ldap_server
@customer_dn = customer_dn
end
def get_customer(username, password)
customer = nil
ldap = LDAP::Conn.new(@ldap_server)
login_dn = ... | Ruby |
#!/usr/bin/env ruby
require 'postgres'
def connect_db
begin
conn = PGconn.new("localhost", 5432, nil, nil , "CAT_STAGING", "nauman", "password")
rescue PGError => err
p "Exception:", err
end
return conn if conn
end
conn = connect_db
#arrIns = [%W{EntryId2 AppId2 AppOwner2 Appname2 AppM... | Ruby |
#!/usr/bin/env ruby
begin
x = Math.sqrt(100)
raise ArgumentError.new("My own argument error")
rescue ArgumentError => err
p err
ensure
print "\nthis will always run."
# retry # to retry the begin block
end
| Ruby |
#!/usr/bin/env ruby
=begin
=end
line = %w{Python is a great scripting language, Why can't everyone learn Python and Why is Perl not used anymore}
class Logger
private_class_method :new
@@logger = nil
def Logger.create
new unless @@logger
end
end
class Customer
def initialize(na... | Ruby |
#!/usr/bin/env ruby
class DefaultFilter
def process(data)
#printf(">>DefaultFilter:%s", data)
end
end
class MethodCallFilter < DefaultFilter
def initialize(expression, destination_file)
@match_expression = expression
end
def process(data)
if data =~ @match_express... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'postgres'
puts "main__"
calls = [
["UK London", "+4455665566", "Holland Amsterdam",
"+3155665566", "17"],
["UK London", "+4455665566", "Sweden Stockholm",
"+3155665566", "7"],
["UK London", "+4455665566", "France Paris",... | Ruby |
#!/usr/bin/env ruby
=begin
rspec example
install rspec by gem install rspec --remote
=end
module Spec_helper
def print_spec(msg)
puts msg
end
end
class Customer
accessor_list = :name, :company
def initialize(name, company)
@name, @company = name, company
end
... | Ruby |
#!/usr/bin/env ruby
require 'mysql'
require 'date'
class CustomerFinder
def initialize(connection)
@connection = connection;
end
def find(date)
sql = "select name, email, number, keyword, provision_date, expiration_date from customers
where expiration_date < '#{date}' and enab... | Ruby |
#!/usr/bin/env ruby
class String
def starts_with? aString
rindex(aString, 0) == 0
end
def ends_with? aString
index(aString) == self.length - aString.length
end
end
str = "Just another string"
puts str.starts_with?("Ju") # should be true
puts str.starts_with?("str") # should be false
puts str.ends_... | Ruby |
#!/usr/bin/env ruby
# line_num.rb
def get_lines(file_name)
return File.open(file_name, 'r').readlines
end
def get_format(lines)
return "%0#{lines.size.to_s.size}d"
end
def get_output(lines)
format = get_format(lines)
output = ''
lines.each_with_index do |line, i|
output += "#{sprintf(form... | Ruby |
#!/usr/bin/env ruby
=begin
For more information
http://rspec.rubyforge.org/documentation/mocks/mocks.html
=end
require 'postgres'
class Database
def initialize(host, port, database, user, pass)
@host, @port, @database, @user, @pass = host, port, database, user, pass
end
def connect()... | Ruby |
#!/usr/bin/env ruby
require 'logger'
require 'gserver'
class StatusMonitor < GServer
def initialize(host = "127.0.0.1", port=7654)
super(port, host)
@level_map = {
'w' => 'warn', 'e' => 'error', 'f' => 'fatal'
}
@logger = Logger.new(STDOUT)
end
def serve(cl... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error repor... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.