Monday, October 22, 2018

Fixing yum command on linux





You may find yourself having to fix more packages. So you can just remove everything you had installed via pipand reinstall everything that you had installed via yumBEWARE. The following uninstalls yum itself:


pip  freeze --local | xargs pip uninstall -y

# Actually clear out ALL python stuff:
rm -rf /usr/lib/python2.7/site-packages

# Install yum:
rpm -ihv --force --replacepkgs http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
rpm -ihv --force --replacepkgs http://mirror.centos.org/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm

# Fix yum:
yum info yum --show-duplicates
yum reinstall yum-3.4.3-154.el7.centos.1
yum reinstall yum-*

# Reinstall everything:
yum -y upgrade # in case reinstall isn't possible for older version packages which are no longer available
yum -y reinstall \*



If may seem a little harsh to reinstall everything but this will definitely fix the system and whatever Python packages you had “broken” via pip (example pyOpenSSL or MySQL-python).














Wednesday, May 16, 2018

How to make DB connection string encrypted in wildfly 10?



How to make DB connection string encrypted?


Go inside wildfly directory on your machine.

cd /wildfly

then run below command with your own password


sudo java -cp modules/system/layers/base/org/picketbox/main/picketbox-4.9.6.Final.jar org.picketbox.datasource.security.SecureIdentityLoginModule <password>

you will get something encrypted password string like below.

ufqewbrqeqewcn4398790291kjxfe



Put Datasource Change in standalone.xml:

                  <security>
                        <security-domain>encrypted-ds-WASM2</security-domain>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                        <background-validation-millis>1</background-validation-millis>
                    </validation>
                    <statement>
                        <prepared-statement-cache-size>0</prepared-statement-cache-size>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>


Added Security Domain and updated data source being used in application for DB encrypted string in standalone.xml.

<security-domain name="encrypted-ds-WASM2" cache-type="default">
                    <authentication>
                        <login-module code="org.picketbox.datasource.security.SecureIdentityLoginModule" flag="required">
                            <module-option name="username" value="admin"/>
                            <module-option name="password" value="ufqewbrqeqewcn4398790291kjxfe"/>
                            <module-option name="managedConnectionFactoryName" value="jboss.jca:service=LocalTxCM,name=MySqlDS_Pool"/>
                        </login-module>
                    </authentication>
                </security-domain>


Friday, January 19, 2018

START AND STOP WILDFLY USING TERMINAL



START AND STOP WILDFLY USING TERMINAL

To start Wildfly:
$ ./standalone.sh
To stop Wildfly:
$ ./jboss-cli.sh --connect command=:shutdown

Tuesday, December 19, 2017

Java 8 Feature 1. Lambda Expressions


Lambda Expression:

You might have heard of lambda in mathematics.It is a bog change in math and is introduced in 1930’s.It solved complex problems easily.

Java is not first language to use lambda expression. First language which lambda expression is LISP.

There are other languages as well:
C, C++,objective c, c# .net, SCALA, ruby,python …. And Java.

Why Lambda ?

1. Lambda expression is to enable functional programming in Java.

2. To write more readable, maintainable and concise code.

3. To use APIs very easily and effectively.

4. To enable parallel processing.


There is wrong understanding in between developers that Lambda Expression has come to replace anonymous inner classes. Which is totally incorrect.








Basic difference between Anonymous Inner Class and Lambda Expression.



          Anonymous Class                                           lambda expression

  1. Class without name function without name

  1. Can extend abstract and can extend,can implement
Concrete class
    3.    Can implement interface with any          only 1 interface which contain single               abstract number of methods method (functional interface only)

4. We can declare instance variable can’t declare instance variable, whatever
Variable are considered as local variable.

5. Can be initiated can not

6. this always referer current inner    this always refers current outer class
Class object but not outer class object object

7. Best choice if want to handle multiple best choice to handle functional interface
  Methods.

8. For every class a separate .class file will no separate class
be generated internally

9. Memory will be allocated in heap inside method area. Inside permanent
Memory of JVM.




Demo Labmda Expression:

interface Interf {
public void m1();
}

public class Test1 {
int x=10;

public void m2(){

int y=20;

//lambda expression

Interf i = () -> {
System.out.println(x);
System.out.println(y);
};
i.m1();
}
public static void main(String[] args) {
Test1 t1 = new Test1();
t1.m2();
}
}



Any local variable which is referenced from lambda expression is always final whether we are declaring or not..In above sample code its y which is local and referenced from lambda expression.

This lambda expression is not executing inside the m2() method.But from t.m2()

You can not change local variable value which is y anywhere within or out of lambda expression.



If you are using local variable, then it becomes final.


Compile Error: Local variable y defined in an enclosing scope must be final or effectively final

If you are not using local variable in lambda expression, then its not final.




We can replace big code with small code and complexity using lambda expression.
Eg.

String s = “sks”;

Below highlighted is a function assigned to interface.  :)

Interf i = () -> System.out.println(“hello”);

We are in a position to pass lambda expression to the method as parameter and pass field in constructor.

Eg.

New Thread( () ->{
super(“child thread”);
}; )

Java 8 Feature and its purpose


Features:

Below mentioned are few features in java 8:

1. Lambda Expressions
2. Functional Interfaces   (type to call lambda expressions)
3. Default methods in interfaces (we can declare concrete methods here)  1.8 version onwards
4. Static methods in interfaces (also static inside interfaces) 1.8 version onwards
5. Predicate is  predefined functional interface
6. Function is predefined functional interface
7. Consumer is predefined functional interface
8. :: was in c++, but now in Java 8 with different purpose which is method reference and constructor reference.
9. Stream API :(Most Imp)  to perform bulk operation on collection becomes very easy. More readable and concise code in a single line instead of 6 lines.
10. Date and time API :  --  Introduced by joda.org-- Also known as Joda API


Purpose of java 8 features:

  1. To simplify programming.
  2. To enable/utilise functional programming benefits in Java in the form of Lambda expression.
  3. To enable parallel programming/processing in java.I can write more compatible code which is going to run on multi core systems. (overall performance is going to be improves).


Wednesday, September 20, 2017

fatal: Not a gitflow-enabled repo yet. Please run "git flow init" first.


fatal: Not a gitflow-enabled repo yet. Please run "git flow init" first.

Please follow below steps to remove this issue:


  1. Open the .git\config file
  2. Remove all the [gitflow * entries and save the file
  3. Close and re-open SourceTree
  4. Go in the main menu, go to Repository > Git Flow > Initialise Repository (should be enabled now)

Using Sed command to search and replace text in XML file or any other file .




Using Sed command to search and replace text in XML file or any other file .


To replace entire line with a specific text/string in linux by using sed command

Syntax:

sed -i 's/.*<TEXT>.*/<TEXT TO BE ON REPLACED LINE>/' *.xml

Replace below placeholders completely to put your required string/text in above syntax.

<TEXT>
<TEXT TO BE ON REPLACED LINE>

Please be aware of the escape sequence while executing the command. 


eg. Here I am replacing entire line which contains <lastmod> tag with <lastmod>2017-07-19T15:09:05+08:00</lastmod>

So please see that closing </lastmod> tag is having `\` (escape sequence). In you case it may vary depending upon your requirement.

sed -i 's/.*<lastmod>.*/<lastmod>2017-07-19T15:09:05+08:00<\/lastmod>/' *.xml

Be specific to the syntax and consider each and every comma and other preposition.









Fixing yum command on linux

You may find yourself having to fix more packages. So you can just remove everything you had installed via  pip and reinstall everythin...