Sunday, August 2, 2015

Love this

Take up one idea. Make that one idea your life - think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone. This is the way to success. Swami Vivekananda

Friday, October 24, 2014

An ode to my beloved grandfather

A few lines that I penned (typed) out in the couple of minutes after hearing about the loss of a loved one .Helped with the mourning process
An ode to my thatha

The heart stops, The blood gets stagnant
The body starts to get cold
I watch it all confused for that body was I


Relatives come check the pulse of the now dead me
Sorrow and cries frantic calls to doctors and family
I watch from my chair confused and flustered
For it has not sunk in


The body cage is finally cremated
I have no body to return to
Now I know I have clinically died


Was that really me?
Who am I Oh Lord for I have lost my identity


A Divine light shines engulfing me and my surrounds
I hear the cosmos within me and around me
A set of Golden stairs in front beckon
I bless my family for its my time to go
In a second my whole life flashes in my mind
Oh what a glorious life I have had


I start to climb the stairs
I climb and climb and climb
For 3 days and 3 nights I climb
There is no tiredness no fatigue
I am growing younger
I am now the lad I once knew at 18
Full of joy and life

I come to the end of my journey
I see all my loved ones
People whom I seem to have known for an eterntiy
I merge with my divine family
I am now part of them and they are part of me
Joy permeates me 


Friday, June 27, 2014

Apaches PDFBox

With 2 kids to manage I am always looking out for interesting activities to keep them occupied and not tear down the house The elder one is now taking an interest in writing and reading so I download worksheets for her print them out and hand them to her .I need to print 20-30 pages for her on a daily basis so I wrote a small program to merge pdfs by directory ,name etc. I had used IText before but PDFBox is even easier
public void mergeFiles(File[] filesInFolder, String destinationFile)
   throws COSVisitorException, IOException {
  PDFMergerUtility mergePdf = new PDFMergerUtility();
  for (File file : filesInFolder) {
   mergePdf.addSource(file);
  }
  mergePdf.setDestinationFileName(destinationFile);
  mergePdf.mergeDocuments();

 }

List out all files that have an extension of pdf

class PDFExtFilter implements FilenameFilter {
  private String ext;

  public PDFExtFilter(String ext) {
   this.ext = ext;
  }

  public boolean accept(File dir, String name) {
   return (name.endsWith(ext));
  }
 }

private static final String ext = ".pdf";

private File[] getFiles(String folder, PDFExtFilter filter) {
  File dir = new File(folder);
  File[] filesInFolder;
  filesInFolder = dir.listFiles(filter);
  return filesInFolder;
 }
When files are encrypted we will need to decrypt them first then ask PDFBox to merge them

public void decrpyt(String folder, File[] files) 
throws IOException, CryptographyException, COSVisitorException {
  for (File file : files) {
          PDDocument doc=null;
   try{
   doc = PDDocument.load(file);
   if (doc.isEncrypted()) {
    doc.decrypt("");
    doc.setAllSecurityToBeRemoved(true);
    doc.save(file);
   }}
   finally {
    doc.close();
   }
  
 }}

Saturday, November 23, 2013

Google charts

I finally had some time to dabble with the Google charts API. Its really cool .
Here is a sample chart I prototyped using the Yahoo finance api (YQL).

Sunday, August 11, 2013

Interesting Quote

Crave for a thing, you will get it. Renounce the craving, the object will follow you by itself.
-Swami Sivananda This quote holds soo true to me

Tuesday, July 2, 2013

Highcharts

I was dabbling with this new chart library called Highchart . This is a simple prototype that plots RBA gold prices in USD currently statically ..

Thursday, July 28, 2011

Android Aync task

I am working on some android applications and thought I'd share how Async task works with a simple example.

Android applications are designed to be responsive. When unresponsive the android OS uses the tough love approach and offloads the app i.e the ANR(App not responding exception). When we do network calls off the mainthread these will block since network connections are relatively slow . To avoid this problem we will need to offload this network call to another worker thread.
This can be achieved using the AsyncTask

Methods we care about in AsyncTask
*onPreExecute()-
Runs on UI Thread before handing over to worker thread

*doInBackground()
Workhorse runs in background
*publishProgress()
inform UI about progrèss called from doInBackground()
*onProgressUpdate()
runs on UI thread and updates progressBar
*onPostExecute
runs in UI thread once worker thread is done

ProgressActivity has a button which will update a progress bar when hit.


package com.foo;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

public class ProgressBarActivity extends Activity implements OnClickListener {
private ProgressBar progressBar;
private Button start;

public class BackgroundAsyncTask extends AsyncTask {

int myProgress;

@Override
protected void onPostExecute(Void result) {
Toast.makeText(ProgressBarActivity.this, "onPostExecute all done back in UI",
Toast.LENGTH_LONG).show();
}

@Override
protected void onPreExecute() {
Toast.makeText(ProgressBarActivity.this,
"preexecute -before back ground processing starts",
Toast.LENGTH_LONG).show();
myProgress = 0;
}

@Override
protected Void doInBackground(Void... params) {

while (myProgress < 100) {
myProgress++;
publishProgress(myProgress);
SystemClock.sleep(20);
}
return null;
}

@Override
protected void onProgressUpdate(Integer... values) {

progressBar.setProgress(values[0]);// called by the publishProgress
// method to update progress bar
}

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

start = (Button) findViewById(R.id.startprogress);
progressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
progressBar.setProgress(0);

start.setOnClickListener(this);

}

@Override
public void onClick(View v) {
new BackgroundAsyncTask().execute();

}
}