14 May 2016

11 May 2016

The 3D hologram on the smartphone actually works!

A colleague of my classmate showed me an article & video of a hologram created on a smartphone, and I didn't quite believe it.



It did make me curious though. Holograms & VR are something I'd love to work on, so I actually tried it out.

Find a CD case or even transparent plastic or glass. Perhaps even a plastic bottle as one person did.


Cut out four pieces of a trapezium from it. Drawing a diamond shape as shown below is by far the most convenient and space-efficient way of doing it. Once you've cut it out on paper, stick it to the plastic with cello-tape and carefully cut the plastic.
 
You end up with this

Super-glue would be a better option for sticking it, but I just used cello-tape. Make sure the 1cm edge part is even, because that's the part you'll be keeping on your smartphone.

Now take your pick from the various videos available.


and watch it come alive!






Turns out there are far more impressive holographic illusions than the smartphone illusion. Play the one below and see.



And all this isn't modern technology. Such illusions have existed since the year 1584. There are plenty of examples scattered across history. More recently, holograms were used in Mr.Narendra Modi's election campaign!

It all began when an Italian scientist named Giambattista della Porta created the illusion of what later came to be known as Pepper's ghost.

This is how the illusion works:


Modern technology comes into play when you want to actually touch the hologram. As of today, that's made possible in a small way with lasers.




Beautiful!



How the smartphone hologram illusion works

In reality, the smartphone hologram is not a hologram at all. It's simply a reflection that can be viewed from all 4 sides. I remember when a person first showed me the video, my first question to him was "what happens if we remove one of the plastic panes?"

While the video is playing, try putting your finger into the middle of the plastic pyramid you created. You'll still be able to see the 'hologram' because your finger isn't blocking anything. In-fact, instead of creating four trapezium's, if you held just one pane of plastic or glass at that angle, facing you, you'd still be able to see the 'hologram'.

When you stand 2 feet in front of a mirror, your mirror image appears to be 2 feet behind the glass. That's the exact same illusion the plastic trapezium creates. At that angle, it just reflects the video, making you think the image is somewhere behind the plastic, in the air. The reflections from the other three panes aren't visible to you because they are at angles that don't reflect or refract the light in your direction. The only way having 4 trapeziums helps, is that you get to see the reflection suspended in the air, in the four directions you view it from. It also creates the illusion that an object that looks three dimensional, is contained within the pyramid shaped container you created. That's all there is to it.
Still...impressive!

Makes me wonder....could a rainbow be called a real hologram?


07 May 2016

More concepts of Apache Storm you need to know

As my mentor tells me -  
"To be able to program in Storm, you first need to think in Storm".


That's very true. Storm is designed in a way that allows you to structure your application design in a way that allows it to scale. But before you begin that journey, there are a few concepts you need to know, which aren't explained in the official documentation (or sometimes not explained clearly enough).




The Constructor concept
[Thanks to Matthias J. Sax on the Storm mailing list for explaining this]

When you create a Spout or a Bolt, Storm calls that class constructor only once. After that, the class gets serialized and from then on, whenever Storm needs to create a new instance of the Spout or Bolt, Storm uses the serialized instance to do so.

But for every new instance Storm creates, Storm will call the open() function for Spouts and the prepare() function for Bolts.
So open() and prepare() are like constructors.



Making your Spouts or Bolts do things at specified intervals

Use tick tuples.



The reason you should exit the nextTuple() function ASAP
[Thanks to Spico Florin on the Storm mailing list for explaining this]

I had created a while loop in nextTuple() of my Spout to emit multiple tuples, but I didn't receive any ack's at all.
Turns out that nextTuple() and the ack() method are called in the same thread by the framework. So if you have  heavy computation in the next tuple, your ack() method will never be called and the buffers that are responsible for receiving the ack messages will not be emptied. The nextTuple() acts as producer for the these buffers while ack() as a consumer.

So remember to emit a tuple and exit the nextTuple() function immediately.
For those who don't know about the ack() method, you can override it (and the fail() method) in your Spout like this:

    @Override
    public void ack(Object msgId) {
        System.out.println("Ack received for Spout"+msgId);
        tupleAck = true;
    }   
   
    @Override
    public void fail(Object msgId) {
        System.out.println("Failed tuple msgID: "+msgId);
        //---tuple replay logic should be here
    }


This helps you know whether your tuple was received and processed by the Bolt or whether the transmission or processing failed.



More creative topology structures
[Thanks to Matthias J. Sax on the Storm mailing list for the idea]

When learning Storm, we come across simple examples and are conditioned into thinking that way.



It doesn't have to be that way though. When you use streams and the various techniques of grouping, you'll find a whole new world open up.

Example:
If you want to create a topology where the spout notifies the end bolts that it has no more input, you can do it this way:

Just specify a separate stream in the spout and emit the notification tuples. When creating the topology, specify an allGrouping for the receiving bolts. What happens is that no matter how many instances of the bolt are created, the spout will send the tuple to all of them. It's like a broadcast.

So the topology would be created like this:

TopologyBuilder b = new TopologyBuilder();

b.setSpout("SpoutA_name", new SpoutA(), 1)
.setNumTasks(1);      
     
b.setBolt("boltA_name", new boltA(), 2)
.shuffleGrouping("SpoutA_name");

b.setBolt("boltB_name", new boltB(), 5)
.fieldsGrouping("boltA_name", new Fields(someID))
.allGrouping("SpoutA_name", "StreamName");



This is how the spout sends a stream to the bolts at the end:

@Override
public void declareOutputFields(OutputFieldsDeclarer ofd) {
    ofd.declare(new Fields("theNormalTuple"));
    ofd.declareStream("StreamName", new Fields("someID"));//this specifies the stream that reaches the end bolt B
}
   
@Override
public void nextTuple() {       

    if (nothingMoreToProcess) {
        collector.emit("StreamName", new Values(someID));//this emits the stream to bolts B
    }       
    else {
        collector.emit(new Values(someTuples), someTuples);//this emits to bolts A
    }
}     



...and this is how the bolt receives it:

@Override
public void execute(Tuple tuple) {
    
    if (("StreamName").equals(tuple.getSourceStreamId())) {//recognizes the stream from the spout
        //do whatever you do when there is nothing more to process
    }
    else {  
        //do your usual processing
    }
}


Don't stop here. There are plenty more ways to think of emitting streams and directing the flow. Remember that Storm is designed to be a Directed Acyclic Graph. You can design your topology as such.




In the code, which are the tasks and executors?

There's a confusion about tasks and executors, because in this case:

builder.setBolt("bolt1", new BoltA(), 3)
                .setNumTasks(2)

Storm creates 3 executors and 2 tasks.

but

In this case (if you don't specify setNumTasks)

builder.setBolt("bolt1", new BoltA(), 2) 

Storm creates 2 executors and 2 tasks.

Remember that a task is an instantiation of a serialized instance of BoltA class (see the constructor concept at the top of this page). An executor is just a thread which processes a task class. If an executor has to process two task classes, then the executor will process the first one and only then process the second one.





Additional links:

If you are looking for a simple tutorial or code sample for Storm, they are here:

Say thank you or donate

01 May 2016

Mass brainwashing

Do you know that diamonds are not a woman's best friend?
Well, allow me to introduce you to the diamond myth:

"...diamonds only came into popularity in the 20th century...But in 1870, a huge cache of diamonds was unearthed in South Africa...With a voluble increase in available diamonds, how could they be priced for their scarcity and rareness? Diamond mine financiers realized that they needed to protect their interests...And that’s how De Beers — which held a monopoly on diamond mining and pricing — was created...

In the 1930s...to promote diamond story lines, place engagement rings in films and get diamonds into the hands of burgeoning celebrities...in the 1940s, a series of lectures was promoted in high schools...

All the advertising, film and television placement and mass psychology worked. After 20 years on the campaign...the younger generation had successfully been implanted with the idea that diamonds were a de rigeur part of courtship. To this new generation a diamond ring is considered a necessity to engagements...

...De Beers sold the idea that a diamond was an expensive but necessary token of affection...Conversely, a woman who didn’t have an engagement ring –who wasn’t showered with diamonds throughout her relationship — was somehow “less loved” than her diamond-swathed counterparts....It’s a lie that started less than a 100 years ago, and it’s a lie the diamond industry has been banking on ever since."

I found this report very intriguing. Haven't we all been brainwashed in similar ways? Made to feel that doing certain things were an absolute necessity to be accepted in society?

Even before mass advertising took over the planet, there were Shaman's, Rainmakers, Soothsayers, Witch doctors, Oracles, Astrologers. After that came the need to drink Complan to gain height. To drink Bournvita to gain capability. To remember only Maggi for a quick snack. To drink only Coca Cola / beer when thirsty. To drink Boost / Glucon D for energy.
As though there were no other cheaper, healthier and much much better alternatives available!


Religion

Take religion for example. What exactly does your religion actually want you to do?

To help people. To respect and be kind to others. To live peacefully. To recognize and appreciate that a beautiful universe may have been created by a much wiser, powerful being.

Is this what some religious people actually do? It's very surprising that even grown adults don't realize that they would have been following the rituals of some other religion if they were born into that family. It isn't surprising though, that most people think they are being religious by simply following rituals. They forget what their religion actually wants them to do. Such is the power of mass brainwashing, fear and hysteria.


Social Customs

Same applies to other social customs. Going out for a movie and dinner is somehow considered cool. Having a party at a club, going out for a company-sponsored lunch, volunteering grandly for one hour...

These may be enjoyable sometimes. These may be enjoyable to some people. But do you really enjoy it?
Would you find it more enjoyable to read an interesting book? To go on a long drive? To explore places?


A comic by Zen Pencils captures this nicely: http://zenpencils.com/comic/nerdist/


We live in a society that sees someone doing something they love, see the happiness on their faces and somehow believe that if we do the same thing, we would be happy too. What would really make you happy is the removal of the pressure to imitate others. To realize your interests and to do what makes you happy, no matter what the brainwashed masses think of it. It is in that moment that we find true peace and joy.
- Navin


That's also when you realize the true meaning of "Be yourself".

Of course, it's also important to keep in mind the laws of the land, the practicalities of finance, your dependents and responsibilities of life.

Think for yourself, people. You own your mind, you have the right to know the truth and to live life the way you wish.