Connecting to facebook using a ruby app

require "net/http"

http = Net::HTTP.new('www.facebook.com', 80)resp = nil

cookie = String.new

http.start do |http|  request = Net::HTTP::Post.new('/')  request['referer'] = 'http://www.example.com/'

  request['user-agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0'
  resp = http.request(request)
  cookie = resp['Set-Cookie']

end

puts resp

FSM for Three Moment Delay in Ruby

state = "q000"i = 0

inputstring = "00111000101"

while i < inputstring.length do

  symbol = inputstring[i].chr.to_i

  #state 000   if state == "q000" then

    if symbol == 0 then       state = "q000"    else       state = "q001"

    end

    puts state + ": 0"

  #state 001  elsif state == "q001" then

    if symbol == 0 then       state = "q010"     else       state = "q011"     end

    puts state + ": 0"

  #state 011  elsif state == "q011" then

    if symbol == 0 then       state = "q110"     else       state = "q111"

    end

    puts state + ": 0"

  #state 110  elsif state == "q110" then

    if symbol == 0 then       state = "q100"    else       state = "q101"     end

    puts state + ": 1"

  #state 101  elsif state == "q101" then

    if symbol == 0 then       state = "q010"     else       state = "q011"     end

    puts state + ": 1"

  #state 010  elsif state == "q010" then

    if symbol == 0 then       state = "q100"     else       state = "q101"     end

    puts state + ": 0"

  #state 100  elsif state == "q100" then

    if symbol == 0 then       state = "q000"    else       state = "q001"          end

    puts state + ": 1"

  #state 111  elsif state == "q111" then

    if symbol == 0 then       state = "q110"     else       state = "q111"

    end

    puts state + ": 1"  end

  i+=1

end

A Finite State Automation in Ruby

state = 0
i = 0

inputstring = "10011101100"

while i < inputstring.length do

  symbol = inputstring[i].chr.to_i

  if state == 0 then

    if symbol == 1 then state = 1 else state = 0 end

  elsif state == 1 then    if symbol == 1 then state = 2 else state = 1 end

  elsif state == 2 then    if symbol == 1 then state = 0 else state = 2 end

  end

  i+=1

  if state == 0 then puts "yes" else puts "no" end

end