Monday, 23 March 2015

Creating a startup is very similar to Frodo’s journey. You need a good co-founder like Samwise Gamgee, and good faith from the investors like The Fellowship.

It is a long and tiring journey, and the pressure is enormous. Too many people, the elves, dwarves, hobbits and men look up to you to do the right thing. You may want to give up several times. Infact, when you are so close to the finish line, you may feel like backing out. But in the end, the ones who persist, like Frodo did, end up being successful.

So next time you think you can have your own startup, ask yourself this, can you be Frodo?

Monday, 12 May 2014

Increase the Battery Life of your Android Phone

We all love a fancy android phone right? But the problem with all the phones is that since they do too much, they have a very short battery life. The problem has worsened with the arrival of apps like Google Now and Google Services which constantly ask your device for a location and keep it active all the time, even if your phone is locked away.

I am telling 4 ways in which you can increase the battery life, based on the level of hacking you have to do to get it done, please read the gotchas before proceeding. If you apply any particular step and find it useful, please share it in the comments. Would be happy to know the tricks are working.

Turning off useless syncs

Information

Google syncs your account information in the background and this increases data usage as well as eats your battery. Not all of the information is required to be synced in the background, you can turn off the non-essential syncs to gain battery life.

Steps

  1. Go to Settings > Accounts > Google
  2. Here you can see everything Google is keeping in sync burning your precious battery, turn off anything you are not using or do not require to be up to date

Gotchas

For example, for an average user, I think only Gmail, Calendar and Chrome matters the most, rest of the things like Google+, Google Photos, Google Playstand, Contacts, Music etc. can be turned off safely. Dont worry, they will get updated when you open those apps, its just that they won’t be running syncs in background.

Turning off Location services

Information

Google keeps a track of everywhere you go by something known as Location Services. It uses your WiFi and your mobile data connection to give you location based services, and it tracks your locations even if the mobile is asleep, giving google a step by step history of where have you been, how much you have travelled etc. To know how much Google knows about you, login to Google Location History and surprise yourselves. Apart from the privacy concerns, Location Services uses a lot of battery.

Steps

To turn off Location syncs, do the following steps:
  1. Go to Settings > Location
  2. Turn off Location access

Gotchas

The downside of disabling Location Services is that apps using Location access would not work now, Google Now would be crippled, apps like Facebook, Quizup etc. would not be able to get Location access. Please do not do this if you want to continue getting Location services in your apps at the expense of battery.

Installing Xposed Framework and revoking wake up permissions (requires root)

Information

Ok so this is a little complicated than the previous methods, and for this you will require a basic knowledge of how things work in Android.
 
When you lock the phone screen, Android goes into a sleep state, where it shuts off the processor to a very basic configuration required to just keep the phone on. Battery consumption in sleep state is almost minimal, but the problem is that, apps do not allow the phone to remain in the sleep state, and have a permission to wake up the phone - something known as a wakelock.

These wakelocks consume a lot of battery life, since they continue to eat mobile battery even when your mobile is asleep. So the solution is to disable all those wakelocks. Unfortunately, android does not simply allow you to do that, and for that you will have to root your phone to gain special permissions in order to do it.

Steps

Just google ‘how to root xxx’ where xxx = name of your device and you will get a step by step guide of how to root your phone.

Once it is rooted, follow the steps below:
  1. Download Xposed Installer
  2. Go to Installer > Install/Update and reboot your phone
  3. After the reboot, go to Xposed Installer > Downloads and search for Per App Hacking and install its latest version
  4. Once installed, go to Xposed Installer > Modules and enable the module
  5. Open the Per App Hacking module and search for Google Play Services and Google Search, tick the prevent wake lock option
What we are basically doing is that we are removing the ability of the apps to wake up your device. You can do this for all apps that you think are not required when your phone is in locked state. In normal usage, I think all apps except Instant Messaging, Email and Calendar apps can be turned off. This will save you a lot of battery.

Gotchas

Note that this method can void the warranty of your device and you have been warned. But you can safely restore the warranty by unrooting it, steps available by googling it.

Installing Cyanogenmod (requires a little hacking)

Information

Ok so this is the extreme step - installing another Operating System all together on your phone. This is for all those people who have been denied Kitkat update by their manufacturers and want to experience the fun of some android hacking.

When you buy a phone, your phone comes with some modified version of android. Depending upon the manufacturer (e.g. Samsung, HTC, Sony etc.) you may have a number of apps that are not required for the pure android experience the kind of given by Nexus devices. Even people with Nexus devices can install this for the level of customization offered by this OS.

Cyanogemod is an extension of Android Open Source Project (AOSP) and they are one the largest group of developers trying to bring the pure and latest android experience to the android community. There are many other operating systems available as per your device, but this is the most famous one and most widely used one with developer support.

Steps

You can follow the steps given on the official Cyanogenmod website on how to install cyanogenmod on your device.

Once installed, follow the below steps:
  1. Go to Settings > Privacy > Privacy Guard
  2. Click on Advanced at top right corner of the screen
  3. Select any app you want and disable the permissions: Keep Awake and Wake Up
  4. You can also remove other permissions like Location etc. based on your privacy concers
This method gives more flexibility than the Xposed framework as you can disable the individual permissions of the app that you think are not required for the normal functioning of the app. This also solves your privacy concerns.

Gotchas

Installing custom OS can void your warranty and can even brick your phone if not done carefully. That said, please proceed at your own risk. I will not be held responsible for anything that happens to your phone.

Also, installing a custom OS may stop some of the functions of the phone, please read very very carefully about the known issues before installing. Usually you can find the known issues on the developer pages.

Conclusion

Whoa!!!! That were a lot of steps. If you follow any steps and find the results interesting, or even have some better solutions, please share it in the comments.

The inspiration behind all this hacking was the announcement of Samsung that Kitkat won’t be coming to Samsung Galaxy S3. So I installed Cyanogenmod and kept discovering all this. Here is the screenshot of my battery life:


Previously I used to get to 50% in 13 hours with 2-3 hours of screen time. Now I can remain at 70% using the screen time since at the rest of the times, my device remains in the sleep mode and there is minimal battery consumption. Note that my wifi was on majority of the time and the phone was awake only when sceen was on. Proven results.

If you have any doubts, please feel free to comment. Happy Hacking !!!! Thanks a lot to Cyanogenmod community, XDA Developers Forum and Reddit.

Saturday, 16 November 2013





How Amazon enables businesses that cross multiple layers.
New startup economics: Why Amazon (web services) and Dropbox need each other
Om Malik, gigaom.com

Earlier this week, I stopped by at the offices of Dropbox, the San Francisco-based online storage and syncing service. It was quite amazing to walk through the company’s sprawling offices — the company now employs about 470 people. Five years ago,…

Wednesday, 1 May 2013

Trek of a Lifetime

On 26th April, I had my first trek in life. It was a trek from Katraj to Sinhagad night trek. It is roughly 20 km, and you have to cross a 7 mountains and a few hills.

We were 12 people and we started the trek by boarding the bus from Swargate to Katraj. We were all loaded, we had with us heavy bags filled with water bottles, bananas (because nothing gives energy like a banana), glucose packets, biscuits and torches. At roughly 9.45 PM, we reached Kartaj Old Tunnel, which is the starting point of the trek. We started the trek, and it was pretty amazing and easy at first, it was mostly a walk over the hilltops. And that is how this trek is, there is no tough trekking part, its just that it is a very long trek. One of us, Kaushik, had already done this trek before, and we estimated that we’d reach the Sinhagad fort by morning before sunrise.

We had chosen a full moon night so that we could see easily in the dark. We climbed the first small hill, and then we could see the red beacon, our target. In the whole trek, you can see the tower on Sinhagad fort with red beacon on the top, which is like the Pole Star of the trek, there is only the beacon to measure the direction and decide the path. There we took our first break, we sat for some time, and then continued going.

The trek is supposed to be fairly very easy, but it took a very dangerous turn for us, because we went on a wrong path. There was a path, from where we were supposed to go to the right side and climb the mountain in a straightforward and easy path, but in the fun and frolic and the mood of the trek, we took the wrong path. There was a narrow road circumventing the hill, and we started walking on the road. As we continued walking, the road got narrower, and at some point, the road came to a dead end. So instead of going back and finding a new route, we thought we should climb the mountain from there itself. So, we looked up, it was may be 500-600 meters ascend, and, from the look of it, looked pretty normal.

As we started to climb the mountain,  the climb got a bit trickier. It was a 60-70 degrees slope, and the toughest part about it was that, there was nothing to hold on to. We struggled a lot to climb, and at some point of time, the struggle to climb became the struggle to survive. There was mostly mud on the slope, which we cannot hold on to, so as we climbed up, there was a risk of slipping and falling down into the valley, and that would mean only death.

We climbed by holding on to anything we could get, sand, rock, trees and even thorns. It hurt a lot, I could see blood running from my hands when I tried to pull myself up grabbing a trunk of a small bush that had lot of thorns. But, I did not feel the pain, because if I did not climb up, there was no way we could climb down, the descend would be uncontrollable and we would slip down and fall into the valley. Some of us made to the top, including me, and then we realized the grim reality - some of us are still far down and, from the look of it, they were stuck.

We people at the top tried to help them by highlighting the paths with the torches, and then slowly people started climbing up. First 2, then 5, then 6, then 9. 9 people climbed the hill with nothing but sheer determination. And then we realized, Shafi had slipped down and just grabbed on to a tree and was sitting on a rock, he was in a state of shock and was just sitting there not speaking anything. And Vishal was just hanging with Kaushik holding him, he had no energy left in legs to push himself up, he was neither in a comfortable state where he could sit and gain his strength.

We were all in a state of shock, Tejas thought we should call the police and get us somewhere safe, let alone complete the trek. But in such a remote place, there was no cellphone signal, and even if we managed to get one, where should we tell the police to come? As the people at the top were thinking all this, we were surprised to see Shafi climbed up from another path and suddenly appeared on the top and cried for help, immediately I, Harshad and Tejas went there and pulled him up. He had done an amazing feat by climbing on a path, having torch in his mouth and not tiring until he reached the top.

Meanwhile, Vishal had reached a comfortable rock and he told us that someone will need to come down and grab him up, Kaushik had no stamina left to push him up. Our rockstar, Nikil (first one to climb the mountain, our own Rajnikanth), told that he would go down to help him. Nikil went down, half an hour later, we saw Vishal reaching the top, and Nikil following up. It was a sense of relief like nothing before, we had the feeling we had fought and conquered death itself.

All of us sat there, speaking nothing, just trying to swallow the feeling of how we had, for a moment, thought that this was the last day of our lives. As we were sitting there, looking at the clear sky, looking down at the slope every now and then to see what we had accomplished. We had spent 3 hours on the mountain, and we were behind schedule, it was now impossible to make it to the destination before sunrise.

Still, we had the option of turning back, go down the mountain another path and stop the trek, but we decided to continue what we came for. After 15 minutes, we all stood up, and continued the path. But from now on, we all decided to stick to the easy path, and take the help of markers which were laid down to help us decide if we were on the right path.

After that, it got pretty easy. We were climbing up and down mountains and hills, and enjoying the walk in the moonlight. At one point, everyone just stopped. Tejas had spotted something in the bushes, it was glowing in the torch light, and on a closer look, it seemed like a pair of eyes. We all had our fears up, it was some wild animal. All of us picked up stones in our hands, pointed torches and took steps together. To our surprise, it was just a cat, and ran away when we approached closer. We all had a hearty laughter.

As we continued moving further and crossing mountains, the red beacon stayed at its place, it did not appear to get closer. The more mountains we climbed, the more mountains we saw between us and the destination. We could not go back, infact, there was no going back. There was no human population there, nothing but plain lands and valleys below, there was only one path - going forward.

As we continued the trek, fatigue started to take a toll on us. We had started exhausting all our supplies, we were taking frequent breaks, and it was getting very tiring just to climb a small hill. And we knew that there would be sunrise and after that, it would be impossible to continue the trek in the heat. We moved on, but could not defeat the sun in the race. At one point of time, we saw that we had just one more mountain to climb. After we climbed that, we got another shock - we had two more to climb, and from the looks of it, they were big ones, and already sun was continuously coming on our heads and it was getting hotter every moment.

We wanted to rest, but time was short, because the more we rested, the hotter it would get. And we had no water, it was impossible to climb without water, we were dehydrated. We had crossed several mountains and hills and now every step we took produced pain the legs. But anyways we started to climb the first mountain, it was very difficult, but we did it. And then we saw, the last mountain, it was very high. It had a very steep slope. None of us had the stamina to go on. We saw a road below, and a small village. We were very excited to see it. After a lot of debate, we decided to climb down the mountain to the village, and return back without reaching Sinhagad.

We climbed down, it was a very long path, but we finally reached a well. One of the villagers fetched water from the well and we drank from it. It was the sweetest water anyone had in their life. We then asked the locals and, to our surprise, we could reach Sinhagad top by jeeps. We boarded one, and then reached to the top, and relaxed in a tapri (small roadside restaurant). We ate a lot, we ate bhakri and pithla, had the most amazing chaash (taak, is what they call) and dahi from the matki. It was re-vitalizing. Shafi had no stamina to eat and just threw his backpack and slept on the floor of the tapri, we had to wake him up with great effort.

Then we departed, some of us took a direct car to Swargate, and some of us took the jeep to a nearby village and from there took a bus to Swargate. The trek was over, and when we looked back, we were so proud, we had achieved an amazing feat. At one point, it got so scary we thought we’d die, and at one point, it was impossible to take even one step ahead in the scorching sun, but we fought, geared up our willpower, and we did it. It was an amazing trek, one that cannot be forgotten in a lifetime.

Sunday, 17 February 2013

Awesomeness at a startup

My life has been awesome since September ‘12 - when I got placed in Sokrati. Reading news articles about the startups at Silicon Valley or seeing The Social Network made me think it is not possible to have a company with such culture here in India, but when I stepped into Sokrati, my thoughts changed.

The first experience in a company comes from the interview process - which itself was very amazing and breathtaking. The level of the interview questions was amazing, and there were no stereotypical questions that you would see on thousands of interview websites. The questions were based on practical scenarios and fundamentals. It was an amazing experience, and I learned a lot even from the interviews.

Once I was inside the company, it was very nice to feel the startup culture all around me. The whole company sits in one office - and that amazed me because I was from Cognizant. As I spent more time in Sokrati - I came to understand one thing - unlike other places where office politics, stabbing in the back - such practices are common, people here had only one fundamental ideology - learn, code, help and enjoy. Everyone was full of energy, so ready to help others, so focused on work, and so full of life. This was so different from people in ties and formal shirts, this was the t-shirt culture. I had a feeling that my life was going to be awesome here.

That was my first impression about the company. As I’ve been around for 6 months now, I have observed many such awesome things here, and I would be talking about few which I love the most.

First and foremost, people believe in you. Any senior guy (not Team Lead, not Manager, more on that later) is always pushing you to take the leap of faith, whether its trying out a new technology, deployments on production, debugging a hard and frustrating piece of code, organizing an event, people put their faith in you. At first, I got scared when someone gave me a hard task, as I didn’t whether I was upto it, but then as I started doing things, it turned out that because they expect, I can deliver. Its that push that matters. Thats how you grow. Thats how I’ve grown, just in these 6 months.

Another thing, there is no corporate ladder, no team leads, no managers, only Leaders. Everyone matters. Even a fresher has a say in the architecture of a new product if he has something interesting to share. As you continue to be in Sokrati, as and when you can handle people along with code, you are put into a leadership position, but it is unlike other companies where Team Lead or Manager has very little to say in the Technical domain. Here at Sokrati, our leaders are awesome technocrats and even more awesome people managers. Thats how we define Leadership in Sokrati.

The last, but not the least thing, the openness and frankness within the company. Every month we have a Gupshup Meeting where everyone in the company gathers and discusses their project, findings, any fun things to share and brings out any concerns out in the public. This gives every employee a clear vision what is happening inside the company. Everything is transparent. Every quarter, the company goal is shared with everyone, so that everyone in the company knows what he/she has to work for. Personally, this gives me not only a short term goal but a long term vision of where I see myself with the company growing.

This is all I have to say about (briefly) my first impression of Sokrati. Life is awesome here, and I am enjoying the work. Proud to say - I am a Sokratian.

Wednesday, 10 October 2012

Javascript Jinx: Parsing 'Infinity' to get a number

Everyone would agree Javascript is an insane language. It is very easy to make a mistake in Javascript.One thing about Javascript that makes it harder to code in it is that it is a very forgiving language. It does not raise errors (except in extreme cases). So, there are high chances of the code behaving weirdly.

Here is one awesome trick in Javascript. We know that in Javascript, there is no divide-by-zero error. Instead, when you try to divide any number by zero, you get a special number called Infinity. And this trick is about parsing Infinity to get a number.

Try to run this code in Javascript:
var result = parseInt(1/0, 19);
console.log(result);
The result is most unexpected. The output would be: 18.

Wondering how? This is what happened:

1. 1/0 gave Infinity
2. The base here is 19, so Javascript tried to convert ‘Infinity’ to a number in base 19
3. In base 19, the letter I corresponds to digit 18 (like F to 15 in hexadecimal)
4. So, it converted I to 18, then ignored rest of the string since n is not a valid string, and thus we reached 18.

Amazing isn’t it? This is why we have to be very careful with Javascript. Another version of the same trick:
var result = parseInt(1/0, 24);
console.log(result);
This time, the base was 24. So, this string is parsed: Infini, its parsed upto t since is it not a valid number in base 24, and then Infini is converted to a number to get 151176378 as the output.

(Courtersy: Stack Overflow)
P.S: This trick is so famous, try to search 'parseInt(1’ in Google, you will get an instant result.

Tuesday, 2 October 2012

Java Jinx: Differentianting Java API classes from other classes

This article is about how to differentiate Java API classes from other (external API) classes. This will require a bit of history in why Java became so popular and some architectural background about it. Java was mainly designed to work across networks. Main advantage of Java is that once complied, it could run anywhere, so computers connected across networks can play around with the complied Java file and run them directly on their computer. This led to popularization of Java over networks.

But with networks, comes security. So, any Java code coming through the network ran in a Sandbox, and all the classes that were loaded during the execution of the code went through a security check. The classes are loaded using a Class Loader instance, which performs all the required checks before loading any malicious files. But, these checks take time. So, a Primordial Class Loader loads all classes that are part of the Java API to speed up the loading process. Hence all Java API classes are loaded using the Primordial Class Loader and do not have a Class Loader instance.

So the logic is this: take any classes and check its ClassLoader instance exists using the getClassLoader() method, if the value is null, it is a class from an in-built Java API, otherwise, it is a class from external API, not part of Java API bundle.

Here is the code snippet demonstrating the use:
import org.codehaus.jackson.map.ObjectMapper;

public class ClassSourceInfo {

public static void main(String[] args) {
Integer a = new Integer(10); //any Java API class
ObjectMapper mapper = new ObjectMapper(); //any external API class

determineClassSource(a.getClass());
determineClassSource(mapper.getClass());
}

private static void determineClassSource(Class clazz) {
if(clazz.getClassLoader()==null)
System.out.println("Class is part of Java API");
else
System.out.println("Class is not part of Java API");
}
}
Now the question comes, where is this useful. Well, that is for programmers to decide. For example, there can be a scenario where every class which belongs to an external API used in the Production Code be logged into a file, just for debugging purposes.