05 Jan '14, 5am

An introduction to #eventmachine, and how to avoid callback spaghetti #ruby

require 'rubygems' require 'em-http' require 'json' class LanguageDetector URL = "http://www.google.com/uds/GlangDetect" include EM::Deferrable def initialize(text) request = EM::HttpRequest.new(URL).get({ :query => {:v => "1.0", :q => text} }) # This is called if the request completes successfully (whatever the code) request.callback { if request.response_header.status == 200 info = JSON.parse(request.response)["responseData"] if info['isReliable'] self.succeed(info['language']) else self.fail("Language could not be reliably determined") end else self.fail("Call to fetch language failed") end } # This is called if the request totally failed request.errback { self.fail("Error making API call") } end end EM.run { detector = LanguageDetector.new("Sgwn i os yw google yn deall Cymraeg?") detector.callback { |lang| puts "The language was #{lang}" } detector.errback { |error| pu...

Full article: http://rubylearning.com/blog/2010/10/01/an-introduction-t...

Tweets

AppNote: LTE- Advanced (3GPP Rel.11) Technology...

rohde-schwarz.com 05 Jan '14, 11am

The LTE technology as specified within 3GPP Release 8 was first commercially deployed by end 2009. Since then the number o...

Study forecasts impact on electricity demand an...

greencarcongress.com 05 Jan '14, 5pm

Study forecasts impact on electricity demand and emissions from introduction of EVs in state of São Paulo, Brazil 5 Januar...

Developer’s Introduction to Bitcoin: One of the...

bitcoinmagazine.com 01 Jan '14, 9pm

One of the major advantages of Bitcoin is just how easy it is to work with from a developer’s standpoint. Bitcoin has no t...