Skip to content

Instantly share code, notes, and snippets.

@rubydubee
rubydubee / main.rb
Created June 30, 2011 19:48
Twitter Client in shoes
#Main file
require "Twitter.rb"
require 'json'
require 'uri'
Shoes.app :width=>300, :height=>400, :title=>"Rubydubee" do
@twitter = Twitter.new "consumer_key",
"consumer_secret"
@main_stack = stack do
@rubydubee
rubydubee / array_example1.rb
Created June 30, 2011 21:39
Array Example 1
a=[23,45,576,12]
a.each {|x| puts x}
@rubydubee
rubydubee / array_example2.rb
Created June 30, 2011 21:41
Array Example 2
b=a.collect {|x| x**2}
puts b
@rubydubee
rubydubee / array_example3.rb
Created June 30, 2011 21:43
Array Example 3
a.collect! {|x| x**2}
@rubydubee
rubydubee / array_indexes.rb
Created June 30, 2011 21:44
Array Indexes
['a','b','c'].each_with_index do |item,index|
puts "At Position #{index} : #{item}"
end
@rubydubee
rubydubee / array_example4.rb
Created June 30, 2011 21:48
Array Example 4
array = ['junk', 'junk', 'junk', 'val1', 'val2']
3.upto(array.length-1) { |i| puts "Value #{array[i]}" } #This is an example of Integer#upto
array = ['1', 'a', '2', 'b', '3', 'c']
0..array.length-1).step(2) do |i| # This is an example of Range#step
puts "Letter #{array[i]} is #{array[i+1]}"
end
@rubydubee
rubydubee / array_range.rb
Created June 30, 2011 21:58
Array Range Example
array=[1,2,3,4,5,6]
puts array[2..4]
@rubydubee
rubydubee / set_operations.rb
Created June 30, 2011 22:00
Set Operations on Arrays
#Union
[1,2,3] | [1,4,5] # => [1, 2, 3, 4, 5]
#Intersection
[1,2,3] & [1,4,5] # => [1]
#Difference
[1,2,3] - [1,4,5] # => [2, 3]
@rubydubee
rubydubee / sort1.rb
Created June 30, 2011 22:12
Sorting Example 1
[4,2,1].sort #[1,2,4]
["pradyumna","ruby","bee"].sort #["bee","pradyumna","ruby"]
@rubydubee
rubydubee / sort2.rb
Created June 30, 2011 22:13
Sorting Example 2
arrays = [[1,2,3], [100], [10,20]]
arrays.sort_by { |x| x.size } # => [[100], [10, 20], [1, 2, 3]]