tag:blogger.com,1999:blog-10194980609974275462024-03-13T13:52:34.984-04:00A Common IT Man's BlogRaves, rants, views, reviews, comments and experiences of a Common IT Man.Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.comBlogger197125tag:blogger.com,1999:blog-1019498060997427546.post-87447101579894250892023-03-31T18:38:00.003-04:002023-03-31T18:38:50.841-04:00Spring Data JPA Query Methods Spring Data JPA Queries are a great way to create queries derived from the method name without needing to write tons of boiler-plate code to create connection & query, execute it and then process the result set. This generally works fine for simple queries and method names are very explicit in pointing out what is being returned by that method so the code is more readable and Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-38087376263855531162023-01-21T15:38:00.000-05:002023-01-21T15:38:43.626-05:00Piping output of top through grep does not give any outputRecently I was trying to grep for "load average" in the output of top and then redirect it to a file to save for later analysis - however the output file would be totally empty for quite some time. That is the time I realized that grep was buffering its output causing the output file to be empty. So the grep command was not writing to the file immediately but was collecting large amounts of data Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-30056052111262800782022-12-31T13:30:00.001-05:002022-12-31T13:30:00.172-05:00Extract a range of lines from a file on LinuxSay you have a huge file, but want to extract only a specific range of lines from that file into another one. There are many ways to do this, but a very simple way would be to use sed as follows:sed -n '$start_line,$end_linep;$end_lineq' input_file.txt > output_file.txtThis will print all lines from the start_line to end_line and stop processing once it reaches end_line.Note that the p&Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-67453127163007995772022-12-30T17:54:00.002-05:002022-12-30T17:54:33.983-05:00Disable automatic backslash insertion before $ when using auto-complete in bashWhen using bash that is not configured properly, on using tab to auto-complete paths, it automatically escapes dollar symbols by inserting a backslash symbol before them, causing the commands to fail if run after auto-completion. For example: ls -l $HOME_DIR/code/wo (TAB) becomes ls -l \$HOME_DIR/code/workspace/ To stop this from occurring, you need to add this command to yourDarshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-46614850844240256572021-05-06T16:35:00.001-04:002021-05-06T17:03:45.167-04:00Extract files from RPM package without installingAn RPM package is a file consisting of a cpio archive that contains the files to be installed and a header that contains metadata information about the package.
You can use the simple utility tool rpm2cpio to convert the contents of an RPM package into a cpio archive and then use the cpio command to extract the contents of that archive without needing to install the RPM package.
rpm2cpio Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-84932002836943070512021-05-05T15:48:00.001-04:002021-05-05T17:10:39.493-04:00Handling Exceptions in EJB using InterceptorsIn my previous posts Using EJB Interceptors to add functionality to existing Beans, and Using EJB Interceptors to execute code AFTER service method completes, we saw how to use EJB3 Interceptors to add common concern features like logging, etc. to J2EE service methods.
In case you want to have common exception handling logic for all service method calls, you can wrap the return context.proceed();Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-85240820161739527452021-05-04T17:22:00.003-04:002021-05-04T17:31:31.129-04:00Using EJB Interceptors to execute code AFTER service method completesIn my previous post Using EJB Interceptors to add functionality to existing Beans, we saw how to use EJB3 Interceptors to add common concern features like logging, etc. to J2EE service methods.
In case you want to run any piece of code after each service method call, you can wrap the return context.proceed(); in a try-finally block and add the "after" code in the finally block as shown below:
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-15435437495556533632020-11-10T23:31:00.003-05:002021-05-04T17:31:09.028-04:00Using EJB Interceptors to add functionality to existing BeansTo add any decorations or cross-cutting features like logging, profiling or performance measurement for service method calls of existing enterprise beans, you can use EJB3 Interceptors that were provided starting with JavaEE5.
Interceptor is a method that wraps around the invocation of the actual business method call allowing you to apply the required feature and can either exist in the target Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-83593717648362837082020-11-09T19:13:00.002-05:002020-11-09T19:15:00.581-05:00Undo git stash clearYou can clear git stashes using the command:
git stash drop stash@{stash_index}
### OR
git stash clear
If you need to recover very recently deleted stashes, you can try the following two commands to try to recover them:
1. List all the available stashes that can be receovered using the below command:
git fsck --unreachable | grep commit | cut -d ' ' -f3 | xargs git log --merger --no-walk
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com1tag:blogger.com,1999:blog-1019498060997427546.post-74612709940101484042020-06-17T22:51:00.004-04:002021-05-06T16:28:08.853-04:00Syntax Highlighting Code in BloggerI was using Syntax Highlighter created by Alex Gorbatchev to highlight code snippets on this blog, but of late, it was not working or taking too long to load up. So it was time again to figure out a new way to do this and there were a few options that work in a similar fashion:
highlight.js : https://highlightjs.org/code prettifier: https://github.com/googlearchive/code-prettifyTheDarshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-80576100632010143342018-03-24T16:54:00.003-04:002021-05-07T16:37:18.684-04:00Copy specific files from within nested foldersI had a situation where I needed to save all log files that were present in nested sub-folders and copy them over to another folder for analysis.
There are many ways to do this - but here is the simplest that I could figure out using rsync:
rsync -aihv --include='*/' --include='*.log*' --exclude='*' /source_folder/to/search/in/ /destination_folder/to/copy/to/
Important thing to note here is Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com6tag:blogger.com,1999:blog-1019498060997427546.post-21452119152955647082018-03-24T16:38:00.004-04:002020-06-17T20:45:18.226-04:00Rename multiple files in one commandIf you want to rename multiple files, the trusty old Unix "mv" command can't help as it can rename only one file at a time.
This requires us to bring out something different from our Unix arsenal - the "rename" command!
Use the rename command in conjunction with find to rename multiple files:
find /source_folder/to/search/in/ -name 'myapp*.log.201*' -exec rename -v .log. .oldlog. {} \; >> /temp/Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com1tag:blogger.com,1999:blog-1019498060997427546.post-52806230878247415612018-03-24T16:19:00.004-04:002020-06-17T20:45:55.241-04:00Running same set of commands on multiple servers using for loopDevelopers as usual are very lazy and so instead of going to each server to grep for an error string in the log file and creating a report, here is a simple way to collect all the necessary log lines.
Create a file containing a list of server names on which we want to check the logs - one on each line and then run this for loop if using bash:
for s1 in $(cat servers_list.txt); do
ssh -q ${s1}Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-46221379555761836502018-02-06T21:46:00.003-05:002018-02-06T21:46:47.271-05:00Obi keeps ringing - Calls from weird numbers - Ghost callsSome time back my Obi Google Voice phone kept ringing constantly and the caller ids were weird numbers. Strangely, Google Voice had no history of any such calls that I could mark as spam and rebooting the Obi device would help.
Researching this problem showed that it could be SIP scanning by bots that probe standard SIP ports causing the phone to ring and caller id to show strange numbers Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com9tag:blogger.com,1999:blog-1019498060997427546.post-13108870476974853982018-02-06T19:45:00.004-05:002018-02-06T19:45:56.373-05:00Obi100 and Obi110 Google Voice with Simonics GatewayObi100 and Obi 110 devices worked great with Google Voice but Obihai declared these devices to be end of life in August 2016. So a recent Google change made these devices to stop working with GV.
To solve this, you could either buy a newer Obi 200 series device or use a paid GV gateway setup by simonics.
Here are the instructions for using simonics GV gateway from the ObiTalk forum post:
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-50328553770547803022018-01-31T22:46:00.001-05:002018-01-31T22:46:21.420-05:00Use CSipSimple instead of ObiTalk ObiOn App on AndroidAndroid app for ObiTalk - ObiOn stopped working some time back so here is my solution for using CSipSimple instead.
It requires you to sign-up for a free IP Freedom account at Callcentric and a bit of setup.
Create an IP Freedom account 12341234567 at Callcentric here
Create a sub-account 12341234567101 (extension 101)
On your Android phone download and install CSipSimple from the Play Store
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com4tag:blogger.com,1999:blog-1019498060997427546.post-42463790696475530332015-05-18T21:00:00.000-04:002015-05-22T16:13:38.822-04:00Solve Spring NoUniqueBeanDefinitionExceptionI encountered the NoUniqueBeanDefinitionException where-in Spring was unable to which class to inject for an Autowired variable even though the it was properly qualified!
This happened because the Qualifier did not get post-processed and so multiple implementations of the Interface type of the variable being injected were now available in the classpath. So Spring found more that one Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com1tag:blogger.com,1999:blog-1019498060997427546.post-6802084517706202742015-05-15T20:30:00.000-04:002015-05-15T20:30:01.532-04:00Upgrade Hibernate 3..x to Hibernate 4.3.xNOTE: This is a partial guide to upgrade your Hibernate 3 project to Hibernate 4.3.x
Hibernate has a come a long way from version 3.x to the latest version Hibernate 4.3.x with lots of major changes, bug fixes and enhancements:
Started using gradle for builds
Redesign the way SessionFactory is built
Improved metamodel
Initial osgi-fication by package splitting (public, internal, spi)
Migration Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-27642606593340433442015-05-14T22:10:00.000-04:002015-05-14T22:10:01.384-04:00Upgrade from Spring 2.5.x to Spring 4.1.x - JBossAfter completing the steps mentioned in my previous post for Upgrading Spring 2.5.x to Spring 4.1.x, the project compiles without problems, however, JBoss deployment does not work as it does not get all the required new Spring Jars.
The Spring component jars also need to be added to the JBoss classpath. However, here are a few specific exceptions that point to requiring specific jars in the Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com1tag:blogger.com,1999:blog-1019498060997427546.post-5209166959680959622015-05-06T22:52:00.000-04:002015-05-06T22:52:03.890-04:00EasyMock Exceptions when mocking Classes instead of InterfacesEasyMock as the name suggests, provides an easy way to mock objects for testing where-in you mock interfaces of the classes you want to test. EasyMock then generates mock objects on the fly using Java's proxy mechanism and then simulates it in a simple way and also verifies whether it is used as expected.
When creating some new mock objects for testing using EasyMock 2.5.x, I noticed the below Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com5tag:blogger.com,1999:blog-1019498060997427546.post-29083414780157627372015-05-05T20:00:00.000-04:002015-05-06T22:51:33.567-04:00Oracle Date / Timestamp difference in Hours, Minutes & SecondsFiguring out the exact time difference that has elapsed between between two Date / Timestamp columns in Oracle using SQL is not as easy as it sounds.A simple subtraction the those values using this query yields:
SQL> select runnumber, starttime, endtime, (endtime-starttime) TotalMinutes0 from run_log;
RUN STARTTIME ENDTIME TOTALMINUTES0
---- -------------------- ------Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-14273034978531686882015-04-22T20:18:00.000-04:002015-05-22T16:10:52.956-04:00Upgrade from Spring 2.5.x to Spring 4.1.xI am upgrading Spring libraries of a critical project from Spring 2.5.x to the latest available release which is Spring 4.1.6 right now. One of the major issues I faced is that the packaging strategy was changed in Spring 3.0 release. Earlier, a single spring.jar with all jars and required libraries was provided, but this was discontinued from the 3.0 release. Now we would need to include each Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com1tag:blogger.com,1999:blog-1019498060997427546.post-51809535759114677112014-11-07T10:00:00.000-05:002014-11-07T10:00:08.011-05:00MongoDB keyfile permissions are too open errorCreating an authenticated replicated set requires setting up of a secret key file on all the nodes.
In spite of creating the key file and putting the same file on all the nodes, you may encounter error stating that the permissions are too open:
permissions on /var/mongodb/conf/mongodb-keyfile are too open
To solve this, here are the two things that you need to do to solve it:
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0tag:blogger.com,1999:blog-1019498060997427546.post-1255152001035727682014-11-07T09:59:00.000-05:002014-11-07T09:59:00.529-05:00Amazon Echo - your own personal digital concierge!Amazon has launched nifty device named Echo - which is like a stand-alone "Siri" - but more like a personal digital concierge for the family. The cost is pretty reasonable at $199 and Amazon is running a promotion right now where Prime members can get it for only $99.
Check out the Echo on Amazon - looks pretty interesting but is available by invite only.
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com1tag:blogger.com,1999:blog-1019498060997427546.post-30946619844668128742014-09-05T18:38:00.000-04:002014-09-05T21:59:25.027-04:00MongoDB warning for running on NUMA machineWhen running MongoDB on a Linux server (having multiple physical processors as most servers have these days), you will see the below warning in your log file on startup:
2014-09-04T13:13:35.245-0400 [initandlisten] ** WARNING: You are running on a NUMA machine.
2014-09-04T13:13:35.245-0400 [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
Darshan Shahhttp://www.blogger.com/profile/18011697486352773391noreply@blogger.com0