Posts

Java 8 streams, grouping by transformed stream object

Following example demonstrates, how to use Java streams to group an object based on its property and transforming the object to some other Class before they are collected in a list. In the following example, we create a list of objects of Class A and stream the list to produce a map based on a property of Class A but containing a list of objects of Class B. public class A { public A(String a) { super(); this.a = a; } private String a; public String getA() { return a; } public void setA(String a) { this.a = a; } } public class B { public B(String a) { super(); this.a = a; } private String a; public String getA() { return a; } public void setA(String a) { this.a = a; } } public class Main { public static void main(String a[]) { A a1 =...

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

Many times we encounter this error and think that there might be some JPA issue or network issue. However, the error is pretty explicit in its nature, but still not clear to ring the bell very first time. As the error says there is a timeout, and since Oracle is saying, we shall accept it. Another clue is "user requested cancel of current operation". This means that the connection was closed by the application server not the database server, hence it can be safely concluded that application has configured timeouts on transactions at its end. However, if you feel that this transaction should have been concluded within the application server limits, your doubt might be true. This problem can arise in case there is a lock on the record being updated by JPA or lock on the table in which JPA is attempting to insert. The lock is most probably being held by some other application, and since application server configuration is on aggressive SLA, the transaction is waiting its...

git switch all projects on your local from one branch to other

Many a times we have to switch projects from one git branch to other in our workspaces. With handful of projects it is easy to do in your editor or to use command line. However if the number if projects is bigger, it become monotnous boring and cumbersome. Following is the simple shell script to help with that. The prerequisite is that all projects must be in same directory and your credentials are already set and saved for git repository. The script will show all branches for suggestion. Just select the one you want to switch to by simple copy and paste. #!/bin/bash COL='\033[0;33m' #Yellow RED_COL='\033[0;31m' RESETCOL='\033[0m' unset SELECTED_BRANCH START_DIR=`pwd` echo "select a branch you want to switch, from listed branches" for i in */ ; do if [ -d "$i/.git" ]; then echo -e "${COL}--##__ $i __##--${RESETCOL}" cd $i if [ -z $SELECTED_BRANCH ]; then branches=`git branch -a| sed -e ...

svn bulk update projects on your local from one branch to other

Many a times we have to switch projects from one svn branch to other in our workspaces. With handful of projects it is easy to do in your editor or to use command line. However if the number if projects is bigger, it become monotnous boring and cumbersome. Following is the simple Python program to help with your svn switches. Usage of program is very simple. Save the folowing program and execute it with python 3.x. Rest of the course is simple and interactive. import sys import subprocess PROJECT_DIR = "" SVN_BRANCH_OLD = "" SVN_BRANCH_NEW = "" if ( len (sys . argv) < 3 or len (sys . agrv) > 3 ): sys . stdout . write( " \033 [0;32m" ) print ( "Three arguments are required. First is parent directory where all projects reside." ) print ( "Second is name of current branch. Only provide the part of URL that has changed" ) print ( "Third is name of the branch, to which ou w...

sql maven plugin write file in target encoding.

Sql-maven-plugin is used to execute database queries as part of build steps. It can also generate files from database queries. It is an excellent tool when it comes to generating file where certain application parameters are saved in a database and are needed by an application as properties. Some applications save configuration parameters in the database but do not want to read it from the database at runtime, because of various business or architecture compliances. These applications rather produce configuration files from the database as part of the build step and use them as application properties as resource bundle. One good use is for locale messages. applications supporting multiple languages, generate message files of different locale from database tables, which are usually managed by business teams. Locale support needs specific encodings, which is not supported by out of the box by popular sql-maven-plugin from codehaus. The maven plugin code at GitHub.com has a pull ...

uscis case dump in a given range

I am providing a simple Python script, that one can use to download USCIS cases in agiven range. The case data may provide you an idea on time of action in your case. Do not abuse the script and put undue pressure on USCIS system. Your IP will get blocked for abuse for long ranges. An abuse may be seen as DOS (denial of service) attack and may invoke felony proceedigs. To use the code, edit  "START_CASE", "END_CASE" and "fname" vaiables. Read comments for details. # Use this code very responsibly and do not abuse the system. Abusing the system may result in a felony. import requests #pip install htmldom from htmldom import htmldom import re import os CASE_TYPE = "I-485" # put the start case number in full as in the example below START_CASE = 'MSC2290530000' #MSC2290532863 # put the end case number in full as in the example below END_CASE = ' MSC2290540000 ' # file location to save the results fname = "case-with-date.c...

pandas dataframe add missing date from range in a multi-dimensional structure with duplicate index

This solution demonstrates how to fill in the missing dates in a given range in a multi-index pandas dataframe. The complexity is added by the presence of duplicate dates in the given data, where the date is considered as an index. In case you try to reindex a data frame with duplicate indexes, you will get the following error. ValueError : cannot reindex from a duplicate axis To resolve this situation and to achieve the end goal of refitting dataset with missing indexes, following pseudo code can be used. Read multidimensional data into pandas dataframe (dataset), with date column as an index (only one index). Transform dataframe index created above into datetime index type Create a new dataframe (d) with the required date range, and value of other records as null Append 'd' into 'dataset' Set index of 'dataset' to include more column to create a multi-level index Reindex to 'dataset', and fill the desired value. The example python co...