Popular posts

Pages

Saturday, June 27, 2026

Plight of the Modern Man

Hearing two recent news are deeply unsettling - Roshan, 21, stabbed in Mumbai local and Ketan killed by his fiancé and her lover, supposedly. While the sad news of a husband's murder during honeymoon trip, is still in my memory.


It really begs the questions, what is the state of a average man today? Men are in distress, period. The sad part is the fact it is largely unacknowledged by the mainstream. I bet, if one cannot identify with atleast 2-3 of these

  • mounting financial burdens - loans, school fees, medical expenses.
  • health issues - sedentary lifestyle, high cholesterol, obesity, heart-attacks in young people (gym goers too), you name it. 
  • work uncertainty - I don't think I need to harp on this. Everyone knows the current state and where it is headed.
  • spousal discord - criticism, judging and woke-feminism. Where is peace, if not at home?
  • societal expectations - keep a smiling face, be a man, should be the provider, show up for work. 
  • dependents - supporting and care giving to our children and elders. At one side, I hear sons abandoning elders and I loathe those. The other side, I'm preparing myself not to expect much from my next generation. Crazy times!


How are we supposed to carry on and what are we supposed to do? I don't think the stressors are going away anytime soon. To me, the end of the tunnel is far. I do not have any answers, and I'm as baffled by these events as you are. But I'm going to share the practices which I find helpful. 

  • Mental and physical fitness - nothing is above SELF well-being. Staying physically active is A fundamental thing, it elevates the mood and detoxes negativity. Best decisions are taken only when the mind is calm and balanced.
  • Invest in yourself - do something that you love or like, develop a hobby, learn something, go trek if that's your thing. Channelize your energy positively. You need a fallback from your day job (when you don't have one)
  • Don't take anything personally - actively avoid stressful situations. When they are unavoidable, do realize to look at them objectively as a 3rd person. Detach yourself. Generalize it, it could happen to anyone. If you like this one, read "The Four Agreements" by Don Miguel Ruiz. This book is wisdom!
  • Forgive and forget (detach) - I took very long to imbibe this one. It is a gift to self to be able to forgive and forget the pain and the pain-creators. The more I think of 'it', the larger it grows and longer it lingers in me. That's why I need to let it go for MY inner peace. Bottomline is, revenge mentality harms oneself.
  • Live a simple life - save as much as possible, invest, live 2 notches lower than your income permits. Financial freedom will keep you sane with a high head.
  • Build meaningful relations - have few, even 1 if not more, caring and loving people around you. Friends or family. Nurture them. Sometimes you will get hurt, but forgive and forget, and continue to pursue them. Everyone is human. I read somewhere that certain locals in Japan live the longest and healthiest globally. A study was conducted which found - they still live in small communities and spend maximum time in chit-chats, gatherings and communal activities.


Maybe I went far with this. But these are the facts which trouble me. Sometimes more, sometimes less. I wanted to put them into words and bring them out. It is my belief that I'm echoing the thoughts of men, who would have pondered on recent violent incidents, but had responsibilities to attend to, and couldn't pen them down.

Thursday, April 8, 2021

Thoughts on Mental Toughness

The What: Mental toughness is not about how we respond to extreme situations and demonstrate perseverance or superhuman courage. It is not about those life changing events. Mental toughness is more humble. It is about living the everyday life by doing things which we know we are supposed to do. It is about constantly overcoming distractions and working step-by-step towards the long-term goals. It is about consistency.

The How: We can train our mental muscles gradually, for instance by - not missing a day in the workout for a week, by calling regularly on your family and friends to stay connected, by reducing sugar intake and dropping the late-evening tea, by committing those 30 mins daily to your hobby.

Ultimately it comes down to imbibing those atomic habits which compound in the long run and make us better than what we were the last month or the last year. Remember, it does not require talent or luck to be mentally strong.

Saturday, October 8, 2016

Create a Windows service out of Java Program using Apache prunsrv / procrun

When I had to run a stand-alone Java application in the background, I used to run it with an "&" and push it to background in Linux. Then I scheduled a cron to check the program every hour and start it if it went dead. This helped me in most scenarios on Linux platform.

However, when I had to write an 'always on' Java application on Windows platform.. I didn't like the idea of an always open cmd console with program output running on it. What if someone closed the cmd window by mistake? What if the server got rebooted for any reason? Yes, to run a program in background I could use javaw.exe instead of java.exe to push it into background as I used to do in Linux. But it didn't appeal me much. Then I stumbled upon this cool thing Apache Commons procrun/prunsrv application to wrap around the program and create a Service out of it. It would run in background, and a service could be set to automatic start... elegant and perfect solution for my problem.

Here is how it got working for me after troubleshoot for many days...now I’m writing it down here, so nobody has to spend so much time again. Refer and use as you like.
  1. Download the prunsrv exe for Windows - link
  2. I had to modify my Main class to suite the prunsrv format, as initially I didn’t plan to use it.
a)      prunsrv.exe takes lot of arguments which you can study here.
b)      I have used the StartMethod and StopMethod as "main" itself, and the StartParams as "start" and StopParams as "stop". These params get passed to main as arg[0]. Now my program looks like below. Notice that 'stopServer()' is static method, that is important.
      public static void main(String[] args) throws Exception {
            EventServer server = new EventServer();
            if ("start".equals(args[0])) {
                 
                  // your program or calls etc etc.

            }
            if("stop".equals(args[0]))
                  stopServer();

      }
     
      public static void stopServer() {
            log(EventServer.class.getSimpleName() + " ENDING SERVER PROGRAM.");
            System.exit(0);
      }

  1. Contents of installapp.bat file, which I run in cmd prompt to install the service. It looks scary, but remember it is a single line. If you study the parameters, all are easily understood. Some parameters have different behavior to accept data like JvmOptions, which you can study on the commons page. Note that prunsrv.exe resides in folder windows\amd64, because my processor is amd64 (you can check by running the command "echo %PROCESSOR_ARCHITECTURE%")
  2. prunsrv.exe //IS//EventGridGateway --DisplayName="EventGridGateway" --Description="Event Grid Gateway" --Install="C:\Users\abhishek\Downloads\commons-daemon-1.0.15-bin-windows\amd64\prunsrv.exe" --Jvm="C:\Program Files\Java\jdk1.8.0_92\jre\bin\server\jvm.dll" --StartMode=jvm --StopMode=jvm --Startup=auto --StartClass=com.eventgridgateway.server.EventServer --StopClass=com.eventgridgateway.server.EventServer --StartParams=start --StopParams=stop --StartMethod=main --StopMethod=main --Classpath="D:\MyStuff\workspace_eclipse\eventgridgateway\target\gatewayserverv2.jar;D:\MyStuff\workspace_eclipse\eventgridgateway\target\bin\hsqldb-2.3.4.jar;D:\MyStuff\workspace_eclipse\eventgridgateway\target\bin\guava-19.0.jar;D:\MyStuff\workspace_eclipse\eventgridgateway\target\bin\sqljdbc41.jar" --JvmOptions=-Dprops="D:\MyStuff\workspace_eclipse\eventgridgateway\target\config.properties" --LogLevel=DEBUG --LogPath="D:\logs" --LogPrefix=procrun.log --StdOutput="D:\logs\stdout.log" --StdError="D:\logs\stderr.log"

  3. Once you run installapp.bat, and if everything is fine, Windows will install your service successfully. Search services.msc with name EventGridGateway. If you need to recreate the service, say any change in above command, first you need to uninstall the service using below command in cmd (Run as Administrator)
  4. After the service is setup, you can run it. For me, it took many attempt before it actually started. The log in D:\logs capture details regarding service and program output (system.out.print)

I have tested this on my machine which is Windows 8, with JRE 1.8




    Saturday, March 7, 2015

    DB2 GRANT privilege example

    Scenario: Suppose you have a database table and now an external application wants to connect to your database and read/view the records of this table.

    Approach: For the external application create a separate user and grant only the SELECT access to this table. This way your access is controlled and there is no chance of an inadvertent update/insert by the new-user

    Here are the steps:
    1. Create a local user on the db2 machine for external application to connect. If you have a db2 user group on the machine, add this user to it and try to connect to your database. Once you are able to connect, proceed to next step.
    2. With the new-user, run a select command on the needed table. DB2 will throw authorization error and should not return any rows since access is not granted to the new user.
      • db2 select count(*) <schema_owner_name>.MyTable.
    3. Open another terminal and connect to you database with the admin user.
    4. With your admin user, issue the GRANT command to new-user:
      • db2 grant select on table MyTable to user NewUser.
    5.  From the first terminal, again issue a select query from step 2. This time you should be able to see something returned.

    Login with new-user, and result of select query before the grant was given



    Login with admin user, the table COMPANY in database AD, and the GRANT statement

     


    After the grant was given



    For revoking the access use below command:
    db2 revoke select on table company from user ab844900

    I've successfully tested these commands on these environments
    1. DB2 10.5 Express C on Windows 7
    2. DB2 10.1 Enterprise on Windows 2008 Server Standard Edition R2

    NOTE:
    1. Test all database commands in a development/test environment prior to running on Prod. Always!!
    2. No matter how certain you are, make sure you have access to a database specialist in-case of trouble :)

    There are plethora of options with GRANT like insert,update,alter table. Refer the IBM DB2 documentation here
     http://www-01.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_sql_granttableorviewprivileges.dita

    Good luck!

    Friday, November 29, 2013

    Awesome tutorial on Perl Hashes

    If you do programming in perl you know how useful Hashes are! Found this cool tutorial and I'm amazed to see so many ways in which Hashes can work for me.... check it out

    http://www.perl.com/pub/2006/11/02/all-about-hashes.html

    Saturday, September 7, 2013

    Regular expression in javascript / jquery

    In this small snippet I'm going to show usage regex in javascript (with jquery). I'm not going to explain the usage and importance of regex in programming. There are entire books written solely on regex :). All I can say is regex can be one of the most powerful tools in your coding toolkit.

    So here is the situation: I've got a website. A text <input> inside a form and drop-down <select> object. Now based on the change in <select> I want to replace some content in the <input> text value.

    HTML
    <select>
        <option value="SEV2/min">sev2/min</option>
        <option value="SEV3/maj">sev3/maj</option>
        <option value="SEV4/cri">sev4/cri</option>
    </select>
    <br>
    <input id="sms" type="text" value="bharti, sev: SEV2/min,circle: bihar,impact: voice" />

    JS
    var re = /sev:\sSEV\d\/[a-zA-Z]+,/;
    $("select").on('change',function(){
        var newsev =  $(this).val();
        var text = $("#sms").val();
       
        var newtext = text.replace ( re, "sev: " + newsev + "," );
        $("#sms").val( newtext );
    });

    Once the <select> is changed, the 'sms' text becomes for ex:

    [bharti, sev: SEV4/cri,circle: bihar,impact: voice]

    jsfiddle link: here

    The html is straight forward. Coming to JS now, here is the sequence:
    - define a 're' variable which will be our regular-expression PATTERN
    - get the value of <select> drop-down, everytime it is changed
    - get the text value of "sms" element.
    - populate a variable 'newtext' using the function str.replace( re-pattern, "new string" ). The replace takes two arguments. first, the pattern 're' (or actual string, eg: "sev4"), and second the string to replace matched text. After this call, the 'newtext' contains the updated string.
    - set the value of 'sms' element to 'newtext'

    This is all about replace(re,"new str") function, hope you enjoyed it!

    Thursday, August 15, 2013

    Java Web Start error - unable to launch the application

    While going through some online java tutorials (at oracle) I found two ways of running them. 1> Java Web Start, 2> Copy the code onto your computer and compile.
    Java Web Start is the latest technology where java code at server will run on your laptop. I was going through 'Swing' (GUI/browser) tutorials and I selected option 1.
    Now when the 'jnpl' file is downloaded on your machine, it invokes the required JRE and will try to run the program.

    The problem I was facing is, when trying to execute the JNPL file, I was getting error 'unable to launch the application' and in 'details tab' I found that it was unable to find JRE1.7, even while I've got the needed jre installed. To find out your installed jre version, on cmd type 'java -version'. This problem was stopping me from running tutorials using Java Web Start.

    Below solution worked for me (windows 7)
    1> Control Panel > Java icon
    2> General tab > Temporary Internet Files > Settings. This will pop-up a window with 'Delete Files' button. Delete the pre-selected two options.
    This should work generally, but my problem still persisted. Then proceed to 3
    3> In step 2, copy the Location of temporary files. (for me: C:\Users\IBM_ADMIN\AppData\LocalLow\Sun\Java\Deployment\cache) and go to that folder.
    4> Delete whatever is there. For me, there was a folder '6.0', maybe because I've another JRE1.6 running on my machine.
    5> Once I deleted this folder, and again tried running the JNPL file it worked flawless for me!

    Hope this works for you too!