Comments in the code explain “why,” the code itself shows “how”.
Wednesday, October 30, 2013
Friday, September 6, 2013
Heart is an amazing organ, very little in size buy very big and important when it comes to the functions. Khan academy has bunch of videos about heart titled Meet the Heart. I highly recommend it. Our body has lot of pairs like left & right hands, eyes, ears & so on. It gets confusing when we start naming them in Latin. Here are some tricks to remember them.
Systole & Diastole
Systole: Wikipedia defines it as “contraction of the heart”.
How to remember it? These two words represent contraction and expansion of the heart in a heartbeat. Remember the word dilation[expansion] when you hear diastole.
Artery & Vein
The other two confusing pair. Vein takes the blood to heart & Artery takes the blood away from heart.
Vein: In, Brings in blood to the heart.
Artery: Away. Takes blood away from the heart.
Atrium & Ventricle
Heart has four chambers, they can be referred as upper & lower chambers or right and left chambers.
Right side chambers collects impure blood and left side chambers pumps away the pure blood. Remember the phrase, Righty tighty, lefty loosey.
Right side collects the impure blood
Left side drains the blood.
Up & down
Upper two chamber are called atriums and lower chambers are called ventricles. Upper chambers usually collects the blood or blood flows into upper chambers. Lower chambers flushes blood away from heart.
Atrium is the word that refers a larger open space within a building usually with a glass roof according to Wiki.
Venter is the origin word for ventricle which means belly. Chambers that are closer to belly are ventricles.
Atrium: Upper two chambers.
Ventricle: Lower two chambers or chambers by belly[venter].
Pulmonic & Aortic valves
These two valves are lower chamber or ventricle valves. They two control the outflow of blood from heart. Pulmo or pulmon is the root word for pulmonic which means lung. It controls the flow of the blood from right ventricle to lungs. That’s why its called Pulmonic Valve. Aortic Valve controls the flow of oxygenated/pure blood to the rest of body through “Aorta”.
Tricuspid & Mitral Valve
These two valves are upper chamber valves and they control the inflow of blood to heart. Among all the four valves, Mitral valve is the only valve that has two cusps. It is also called bicuspid valve.
Friday, July 26, 2013
Lately I have been playing with Android animations. Animations are not easy thing to share. There are few options to show off the animation, Video or GIFs. For a few seconds animation Videos feel like heavy duty tool. GIFs are near perfect tool for the job.
GifCam is a free Windows tool that captures any part of your screen, in any size and saves as GIF file. It is no nonsense tool. Single executable file. No installation. Just copy it and it just works. Sadly this is just on Windows. No apps or no cameras.
If you want to capture something and express it as GIF, there are several apps out there. They use phone’s camera or existing pictures and make GIF out of it. This method is as good as your stable hands.
If you want to capture something in Android and don’t want to use an GIF maker app, then you should check out Genymotion. Genymotion is an Android Virtual Machine unlike Android Emulator, it is pretty fast, runs well & free. If you are an Android developer, dump the emulator and switch to Genymotion. It is freaking fast.
After downloading the Genymotion, download a prebuilt virtual machine and start it. Bring up the GifCam on top of the Virtual Machine window, record & save. That simple. Here is a sample I made.
Tuesday, July 23, 2013
Few decades ago, humans were walking inside of computers, now we are carrying them with us in our packets. In the near future, they will be inside our body and will be doing what we did to them few decades ago. Monitoring our vital signs and fixing broken parts in our body. One step towards that future is “Activity Trackers”. Activity trackers track your physical activities such as walking and climbing stairs and how well you sleep.
There are several companies selling trackers. Nike sells Fuel, Jawbone sells UP, Fitbit sells Flex and One, Withings sells Pulse, BodyMedia has Wireless LINK Armband and iHealth has Wireless Activity and Sleep Tracker.
Broadly you can classify them into two different categories,
- Wrist/arm band. They look like watches and have some or no display.
- Hip tracker. These devices look very similar to a USB memory stick. Most of them can be converted into wristbands at nighttime to track sleep. They usually have better display than wrist/arm band trackers.
I have to pick one, Who said more choices are better? Here is how I narrowed it down.
- Design & Usability: Whether I am going to wear it on my wrist/arm, or keep it on my packet and not visible to others, I wanted something that feels well designed and sleek. This eliminated BodyMedia and iHealth because both of them are bulky even though BodyMedia claims it is clinically proven. I want apps that perform well and looks clean and easy to use.
- One App: I wanted a wireless scale and activity tracker. Fitbit, Withings and iHealth are the three companies that sell tracker and scale. I could have used apps like RunKeeper or My Fitness Pal to combine scale and activity tracking, it didn’t feel native or natural to me.
- Connectivity: These devices had minimal display or no display at all. You have to consume the information and analysis somewhere else like mobile phone, tablets or computers. I didn’t want to be responsible for transferring data for obvious reason. Jawbone Up has no wireless connectivity, you have to plug it into audio jack to transfer data. Fitbit Flex has BLE[Bluetooth Low Energy] connectivity. Only few mobile phones and tables supports this. Go here to see for the full list of Fitbit supported devices. Withings Pulse seems like it can connect to most of the moderns devices with Bluetooth 2.0.
- Display: I want some feedback if I am going to use this for the whole day. Nike Fuel and Withings Pulse and Fitbit One has some nicer displays. Both Withings Pulse and Fitbit One can display number of steps taken and stairs climbed. When it comes to wrist band trackers, Nike Fuel has better display than Fitbit Flex and Jawbone UP. Fuel can display time and steps count, Flex has 5 lights and UP has no display at all.
For me it came down to Fitbit Flex, One or Withings Pulse. Withings Pulse wasn’t available couple of weeks ago. So it was Flex or One. Fitbit One has several advantages, superior display, can count number of stairs climbed and belief is that hip trackers like Fitbit One are more accurate because they sit in your hip not on your wrist which can have some false positives. I chose Fitbit Flex for these two reasons,
- Flex is all in one device for activity tracking and sleep tracking. Fitbit One needs a separate band for sleep tracking. Flex offered less friction and less work.
- Searching misplaced stuff is part of my day and I didn’t want one more thing to search. Flex can stay with my wrist day or night. Only time I take off is when I get into shower.
Links that helped me,
- Comparing Wearables: Fitbit Flex vs. Jawbone Up and More : All Things D
- Comparison of Fuel, Up and Flex : The Verge
- How Accurate Are Fitness Trackers? : New York Time
Check back later for my review of Fitbit Flex and Aria.
Wednesday, June 26, 2013
The ratio of time spent reading (code) versus writing is well over 10 to 1 ... (therefore) making it easy to read makes it easier to write.
Thursday, June 13, 2013
To access RunKeeper API, you need to do few things first.
- Create an application in their Application Portal
- Creating application will get you Client ID, Client Secret and URLs to authenticate. If you are unlucky like me and don’t see client secret, go and post a message in their support Google group. They are good at resolving immediately.
Let’s write a simple application that finds out total distance user has walked so far using RunKeeper’s API.
Accessing RunKeeper’s API involves couple of steps,
- Redirect user to RunKeeper’s authorization URL on a WebView.
- Get permission from user to access their data.
- Once they allow it, Run Keeper will redirect with an “Authorization Code”.
- With the Authorization Code make a Post request to get the access token.
- Securely save the access token for reuse. This is long lived key. It works even after users change their password. So keep it safe.
Let’s create a simple Android project with a simple activity that has a Button and WebView.
On button click, hide the Button and bring the WebView to foreground.
Embed client_id, response_type=code, redirect_uri in Authorization URL and load this URL on the WebView control. After user grants/denies permission, it will be redirected to the redirect_uri you have provided. Override shouldOverrideUrlLoading on WebViewClient to you can detect when it is redirected.
After extracting Authorization Code from the redirected URL, get access token by making a POST request. Note few interesting things, You can’t make network requests on UI thread so create a separate thread. This will return a JSON response. Extract access token from the response.
Now we have the access token, let’s go ahead and query RunKeeper’s API.To keep it simple for this example, I just hard coded the URL. But you should query “user”[https://api.runkeeper.com/user/] endpoint to get list of URLs available for you. If we query http://api.runkeeper.com/records endpoint it returns list of statistics for each activity type available in RunKeeper.
Note that we didn’t create a separate thread for this call since this method gets called in a non UI thread we created earlier. If you are calling this method from UI thread, create a separate thread.
After getting response from “records” endpoint, we have to traverse it to the walking activity type and extract overall walking distance. Parsing JSON with out dedicated parser like Gson is a real mess. To keep the example simple and friction less, I just used built in JSONObject.
RunKeeper returns total distance in meters and convert it to miles and display it on a Toast message. Note we are not on UI thread, we have to call runOnUiThread to display the Toast message. Some less interesting helper methods,
One last important thing, add android.permission.INTERNET to AndroidManifest.xml file so that our app can access internet.