Tuesday, August 2, 2011

Flex and Rails


Hi Peter
Thanks for visiting my blog

In my company we have quite an extensive use of the ruby - flex combination, and to my experience it has the best results for the fastest development time.

The key to communicate between rails and flex is to set up REST services that generate json/xml structures.

On the server side, all you have to do is have the controller render the result as json/xml using the following line:

render :json => {an object with the data you want to send}
or
render :xml => {an object with the data you want to send}

It works just as well in rails 3 as in 2.x

On the flex side, it gets a little more complicated, but in essence, you send an http request to the rails service and on the ResultEvent you encode the string you get to json/xml respectively

here is a code example:

protected function call(action:String,arg:Object,resFunc:Function, failFunc:Function,resultFromat:String="e4x"):void{
            var service:HTTPService;
          
                service = new HTTPService();
                service.url = server+"/"+action;
                service.method = "POST";
                service.contentType = "application/xml";
                service.resultFormat = resultFromat;
                service.useProxy = false;
                service.addEventListener(ResultEvent.RESULT,resFunc);
                service.addEventListener(FaultEvent.FAULT, failFunc);
               
          
            arg["account_id"] = accountId;
            arg["service_key"] = serviceKey;
           
            var req:Object = new Object();
            req["data"] = arg
           
            service.send(req);
           
        }



public function getDetails(result:Function,fault:Function):void{
            var o:Object = new Object();
            call("get_details",o,result,fault);
        }




private function detailsResult(e:ResultEvent):void{
                details= JSON.decode(String(e.result));   
            }

Monday, August 1, 2011

Thursday, April 21, 2011

Ruby rufus-scheduler on Rails

I've been playing around with the rufus-scheduler, trying to make it work in a rails environment.
The problem I was facing was that the new threads that were created by the scheduler for running the jobs were somehow detached from the the Active Record environment resulting in a failure to load my application models within their scope.

Every time I tried loading a model object from the database I would get an error that the copy of my job instance "has been removed from the module tree but is still active"

Pretty confusing

My cowboy programming solution for this was to activate a block as the job instance and in it invoke a controller. from the controller, I managed to access everything I needed in terms of active support.

The code as following:

scheduler.every "10s" , :timeout => "1m", :tags => "etl_job" do |job|
  url = "#{server_url}?tag=#{job.params[:tags]}"
  run(url)
end
The run is defined as:
def self.run(url)
    logger.debug "--- Initiating Job with:  #{url} "
    uri = URI.parse(url)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true if uri.scheme == 'https'
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
  end
The url hits a controller and from there everything acts normally for rails.

Independent on Sundays

Thursday, December 9, 2010

Israel 21c post on the tierx application

Prepare for a revolution in social media marketing 

By Jeremy Last

A groundbreaking product from an Israeli on-line marketing service is set to revolutionize the way social media is utilized by the corporate world.

Once the exclusive realm of a handful of computer geeks, over the last five years social media networks have been transformed into an Internet phenomenon with hundreds of millions of members.
Businesses across the globe are aware of the potential inherent in these networks to connect with customers, but few have been able to take full advantage of the ever-growing databases belonging to websites like Facebook and Twitter.
Now a groundbreaking product, developed by Israel's on-line marketing service provider Valueshine, is set to revolutionize the way social media is utilized by the corporate world.
Valueshine's Tier-x software enables companies to turn every customer into a business partner, generating their own profits through the power of social media networking.
These partners are able to bring in more customers, and earn money, through the simple marketing power of personal recommendations. Customers use social networks such as Facebook and Myspace as well as email accounts like YahooMail and GMail to invite friends to join their mini-network.
Taking the gaming world by storm
The gaming industry has been the first to jump in. Six months after Tier-x's January launch, Valueshine has already built a bespoke version for leading online poker site Noblepoker.com, owned by British-based Internet gaming conglomerate PartyGaming.
Called the Noble Partners Program, it is the first time ever that players are able to earn consistent dividends from online poker even when they're not playing. This innovation is taking the Internet gambling world by storm.
Valueshine's chief technical officer Gilad Manor was a key member of the team that developed Tier-x. He joined Valueshine in 2009 when it had been providing boutique on-line marketing services for high-tech companies, focusing on affiliate recruitment and management for six years.
"The obvious trend we saw was that the world is going social - in the gaming industry, entertainment world, in news, even in the way people shop, Manor tells ISRAEL21c. "The network is becoming global and local at the same time. People have friends from all around the globe while staying in close contact with the same group of people. The strength of community-based services is on the rise."
It was this realization which prompted the creation of Tier-x and encouraged Noble Poker to get involved. Previously, on-line poker sites generally attracted players through advertising and search engine optimization. But Noble Partners relies on a far more reliable source - word of mouth.
A new approach to business
Launched in mid-August, the product already boasts hundreds of members and Manor is excited by the potential impact the Partners Program could have on the entire on-line poker industry. "This new approach could change the way Internet poker companies do business. It's very exciting," says Manor.
Unlike other referral schemes, the Noble Partners Program pays players every month rather than giving them a one-off bonus, and the money earned is real cash. Once they become Noble Partners, players create their own networks and then earn a percentage whenever their friends play, with the cash paid directly into their Noble Poker account each month.
Manor has been "exhilarated" by the response to the launch of Tier-x and sees the success of Noble Partners as only the tip of the iceberg. "From the early, positive reactions we've been getting, I think it has already changed the way things work in on-line poker.
"I think the conventional ways of recruiting new players in the gaming industry, particularly in the poker industry, are worn out. The poker room companies are all using the same methods and nobody has any edge. The Noble Partners Program is an edge no one else has right now."
A major change in marketing practices
Valueshine is currently building similar products for other companies and industries. According to Manor: "The advantages of advertising through word-of-mouth marketing rather than the cumbersome traditional advertising methods can be applied to most businesses. We can see hotels and restaurants, credit card and insurance companies getting involved.
"People are tired of the traditional advertising they are subjected to day in, day out, on the Internet, on the television, on billboards. You naturally build a wall and defend yourself from that mass exposure to information. But in spite of that you always rely on a good word from a friend. If a friend recommends something and enjoys it you are more likely to use that and join that group yourself. That is what we are building on," he tells ISRAEL21c.
Manor is particularly enthused by Valueshine's placing itself on the cutting edge of what could be a major change in marketing practices. "The on-line social revolution is extremely exciting, and it's a great feeling to be part of this global change with a solution like Tier-x. The circle is widening and that's easy to understand when considering the massive scale Tier-x can reach."

Original post at Israel21c

 

Tuesday, November 30, 2010

Where is Zed?

Yesterday, I said goodbye to a dear friend.




















I will remember him for the joy, and for the good times.
love you, Shay!

Look over us.

Thursday, November 11, 2010

Rails Application variable II

Ah, it turns out that my heist and ignorance in Ruby and Rails I missed out on the Rails.cache options.
All you need is...


  def self.alive? (id)
    if Rails.cache.read(id)!=nil and (Time.now - Rails.cache.read(id))<10
      true
    else
      Rails.cache.delete(id)
      false
    end
   
  end
 
  def self.present(id)
    Rails.cache.write(id,Time.now)
  end

(...love)