Skip to content

Instantly share code, notes, and snippets.

class Song
def initialize
@bottles = 99
end
def sing
@bottles.downto(0) do |bottle|
if bottle > 1
puts "#{bottle} bottles of beer on the wall, #{bottle} bottles of beer."
puts "Take one down and pass it around, #{bottle - 1} bottles of beer on the wall.\n"
reg2=/^[\w!#\$%&'*+\/=?`{|}~^-]+ #only allow to start with these symbols
(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)* # the user name can contain dot
@ # @ symbol
(?:[a-zA-Z0-9-]+\.)+ # domain
[a-zA-Z]{2,6}$ # the last part of domain
/x # ignore spaces
reg=/(?<allow_char> [\w!#\$%&'*+\/=?`{|}~^-]+){0} #only allow to start with these symbols
(?<script_tag> script){0}
^\g<allow_char>+
reg2=/^[\w!#\$%&'*+\/=?`{|}~^-]+ #only allow to start with these symbols
(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)* # the user name can contain dot
@ # @ symbol
(?:[a-zA-Z0-9-]+\.)+ # domain
[a-zA-Z]{2,6}$ # the last part of domain
/x # ignore spaces
reg=/(?<allow_char> [\w!#\$%&'*+\/=?`{|}~^-]+){0} #only allow to start with these symbols
^(?<!\<script)(\g<allow_char>+)
(?:\.\g<allow_char>)* # the user name can contain dot
require 'rubygems'
require 'twitter'
config = File.exists?("#{ENV['HOME']}/.twitter") ? YAML::load(open("#{ENV['HOME']}/.twitter")) : Hash.new
if config.empty?
print "> what was the comsumer token twitter provided you with? "
config['token'] = gets.chomp
print "> what was the comsumer secret twitter provided you with? "
config['secret'] = gets.chomp
File.open( "#{ENV['HOME']}/.twitter", 'w' ) do |out|
require 'rubygems'
require 'gcal4ruby'
include GCal4Ruby
service = Service.new
service.authenticate("", "")
#2. Get Calendar List
# puts calendars = service.calendars
cals = Calendar.find(service, {:title => "RMU September Session 1"})
puts cals.first.to_xml
#event = Event.new(service, {:calendar => cal, :title => "Soccer Game", :start => Time.parse("12-06-2010 at 12:30 PM"), :where => "Merry Playfields"})
Sinatra is designed to need friends
no presets
pure ruby
rack-lover
Rack is the best friend
Rack::Session::Cookie
Rack::CommonLogger
Rack::MethodOverride
rack-contrib
The following lines are the output of following command:
cucumber features > ~/gstore_features_output.txt
Feature: object
As a google storeage api user
I want to create objects in a bucket
So that I can perform other operation on the objects
Scenario: create an object in an empty bucket # features/object.feature:6
@ruanwz
ruanwz / uml.txt
Created September 16, 2010 08:03
[IO]^[BasicSocket], [BasicSocket]^[Socket], [BasicSocket]^[UNIXSocket],
[BasicSocket]^[IPSocket]
[IPSocket]^[UDPSocket],[UDPSocket]^[UDPServer]
[IPSocket]^[TCPSocket],[TCPSocket]^[TCPServer]
[UNIXSocket]^[UNIXServer],
[StandardError]^[SocketError]
[FFI::Struct]^[AddrInfo]
[FFI::Struct]^[SockAddr_In]
[FFI::Struct]^[SockAddr_Un]
[FFI::Struct]^[Servent]

Socket

[Document on ruby-doc.org] [ruby_doc]

Introduction

Ruby provides a standard library Socket for networking programming in lower layer, such as TCP and UDP. There are also other libraries for application layers like HTTP, FTP and TELNET, they are not included in this tutorial.

What is Socket

require "socket"
echo_server = TCPServer.new('localhost', 2200)
loop do
Thread.start(echo_server.accept) do |client|
puts "#{client.peeraddr[2]}:#{client.peeraddr[1]} is connected"
loop do
data = client.recvfrom( 20 )[0].chomp
if data =="exit"
client.puts "bye!"
puts "#{client.peeraddr[2]}:#{client.peeraddr[1]} is disconnect"