Posts

Showing posts with the label Experiments

me, akka and scala

I've been learning Scala recently, including through a Coursera course. I'm gradually moving from writing Java-like Scala toward thinking in terms of transformations on data. What I like so far is being able to express operations on collections without spelling out every intermediate step. Shorter code helps when it makes the flow easier to follow, but it does not automatically make a program easier to maintain. Recently, I came across Akka. It lets us organize concurrent work as actors that communicate through messages. Each actor handles one message at a time and can keep its own state. This gives us a way to separate responsibilities without having several workers directly update the same state. We still need to design how those actors coordinate. I tried a word-count program using Akka and Scala. A mapper splits sentences into words, a reducer combines their counts, and an aggregator maintains the totals. The useful part of this exercise is seeing how work moves between ...

Getting cross domain Ajax to work!

Last week I was working on a project which required me to use ajax to fetch the results from 3 different servers and use the result together to have a comparison side-by-side. I had a little knowledge of Ajax, so I had to strive a bit for getting things to work. Here, I share my findings.   Problem: Using Ajax to fetch cross domain data. What does it mean? Suppose my current domain is blahblah.com and I want something from phewphew.com then I need to do a cross domain fetch with Ajax. By conventions Javascript doesn't allow to fetch such cross domain data. It involves security issues. Anyways, I didn't go much into that !! Quick solution 1 : One solution to this problem is to use a custom servlet ( or php, whatever you use, it will act as a proxy ) /JSP page that downloads the JSON ( or any other type ) and simply reproduces it.  In that case, you will put your Ajax calls to a page on same domain and that will work perfectly fine.   Solution 2 : Another solut...