Posts

Showing posts from 2019

Delete horizontal, vertical and angled lines from an image using Python to clear noise and read text with minimum errors

I was working on an algorithm to detect lines in a image. I found many solutions online, but none of them seem to work to my satisfaction. Thereafter, I decided to write an algorithm, which can work to my satisfaction. This algorithm can detect horizontal, vertical and angled lines. Following is the pseudo code of the algorithm. The implementation is in Python and it uses third party code. pix_array = Convert the image into 2D pixel array  Mono chromate the pixel array by setting values between 0-200 as 0 (black) and greater than 200 as 255(white) as  image_width = length of pix_array[0] image_height = length of pix_array Loop through pix_array, i.e. 1 pixel high horizontal slice of image: h = x coordinate of current pixel k = y coordinate of current pixel choose a value of radius as r draw a circle taking h,k as center using equation (X-h)^2 + (Y-k)^2 = r^2 derive values of X and Y and check if pix_arrY[X][Y] is black (0) if black add them to possible line coordinate

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