Monday, July 24, 2017

MySQL BIT field values are not being displayed properly when using SELECT command


Suppose if we have created a mysql table with bit type, while using SELECT sql command, the results returned will not be readable and visible.

Therefore by using the cast function, we can easily fix this

SELECT id, CAST(enabled AS UNSIGNED) AS enabled FROM my_table

Sunday, July 23, 2017

How to add local dependencies Jar on maven





${project.basedir} points to the POM location.

custom jar file is placed on following location.

/libs/com.wso2.enterprise/enterprise-1.0.0.jar

This location can be defined under dependency path location.


<dependency>
    <groupId>com.wso2.enterprise</groupId>
    <artifactId>enterprise</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/com.wso2.enterprise/enterprise-1.0.0.jar</systemPath>
</dependency>

Monday, July 17, 2017

Java Regular Expression

Regex defines the the search pattern of strings in Java.

Regex consists of set of symbols. Following are the common matching symbols used for regex purpose.



Symbol
Description
.
Any character
^      $
Regex matches beginning of the line and end of the line
[abc][pq]
Matches a/b/c followed by p/q
[^abc]
Negates the matching pattern
[p-z4-9]
Matches characters between p and z or 4 to 9.
p|q
Equivalent to [pq]
pq
q immediately follows p


These matching symbols are further defined by quantifiers which will be defining number of occurrences of regex pattern.


Regex
Description
{p,q}
Occurs between p to q times
{p}
Occurs p times
*
{0,}
+
{1,}
?
{0,1}


There are certain meta characters that can be used to simplify defining symbols.


Symbol
Description
\s
Equivalent of  [ \t\n\x0b\r\f]
\S
[ ^\t\n\x0b\r\f]
\w
[A-Za-Z0-9_]
\W
[^\w]
\d
[0-9]
\D
[^0-9]
\b
\w

Note: Grouping of regex elements can be done using ( ) operators.
          p(?!q) denotes regex matches iff p is not followed by q.

Eventually we can consider following example, where I wanted to identify following string

{
               "@nil":"true"
            }


and replace this string with empty("") String.

Input String;

{
   "Opportunities":{
      "Opportunity":[
         {
            "Name":"Firzhan",
            "Age":"30 years",
            "EPF_Start_Date__c":{
               "@nil":"true"
            },
            "EPF-Id":"006E000000",
            "EPF_End_Date__c":{
               "@nil":"true"
            },
            "EPF_Closed_Date__c":{
               "@nil":"true"
            },
             
"CreatedDate":"2016-12-12+05:30",
            "Location":"Dehiwala"
         },
         {
            "Name":"Firzhan2",
            "Age":"31 years",
             "Puppies":{
               "@nil":"true"
            },

            "EPF-Id":"006E000000",
        
            "EPF_Start_Date__c":"2017-03-25+05:30",
            "EPF_End_Date__c":"2017-03-02T00:00:00.000+05:30",
            "EPF_Closed_Date__c":"2017-07-17T12:26:46.000+05:30",
            "CreatedDate":"2013-12-12+05:30",
             "Location":"Dehiwala"
         }
      ]
   }
}


Pattern pattern = Pattern.compile(Utils.JSON_REGEX_CONSTANT);
//Matcher matcher = pattern.matcher(opportunityJson.replaceAll("^\\s|\n\\s|\\s$", "''"));Matcher matcher = pattern.matcher(jsonResponse);
jsonResponse = matcher.replaceAll("\"\"");

Here JSON_REGEX_CONSTANT is equal to 

([\{]{1}[\s|\n]*(\"@nil\"){1}(\s*|\n*[:]+\s*|\n*)(\"true\"){1}[\s|\n]*[\}]{1})

Posting JSON payload via CURL

curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:8080/StockQuote -k -v

Sunday, January 15, 2017

Ubuntu 16.10 is not booting because of error stick: gfxboot.c32: not a COM32R image


When trying to boot Ubuntu 16.10 from USB stick, it fails to boot from following error


Missing parameter in configuration file. Keyword: path
gfxboot.c32: not a COM32R image
boot :

This error had been reported since the Ubuntu versions 14.04. Discussion regarding this can be found here.


Therefore as a solution for this issue, I figured out following workaround.


  1. Whenever this error is getting thrown during startup, press the TAB key
  2. Choose among options like live, live-install etc ... I chose the live option.
  3. Next press enter.
This will take into the live OS and from thereon wards, Ubuntu 16.10, can be installed using USB stick.

How to prepare bootable usb stick for Ubuntu 16.10


In this post I will explain to create a bootable USB disk to install Ubuntu 16.10.

Prerequisites


  • USB Flash disk with at least 2 GB free space.
  • Ubuntu 16.10 ISO image


Steps

Install gparted tool to enable formatting of the USB disk.
Install mksub tool to wipe out the first mega byte of file system and create a new a partition of
  same file system.

- Run Startup Disk Creator/USB Creator


  1. Insert the usb disk and run the Startup Disk Creator.
  2. Choose the image file and make sure to format the USB stick using usb creator's graphical user interface.

 


Once you click the right-most button, eventually it will create a bootable USB disk for Ubuntu 16.10.

Now as the final step after using usb stick for boot-able disk task, in order to restore usb disk to standard storage drive we can use the mksub-nox utility.

Monday, January 9, 2017

How to fix the ERROR 1698 (28000): Access denied for user 'root'@'localhost'


After upgrading from MySQL version 5.5 to 5.7, whenever I tried to log in to the database as non sudo user it throws following error. But I was able to log into the system as sudo user without any issues.



firzhan@firzhan-wso2:/etc/mysql$ mysql -u root -padmin 
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


I followed following steps to do a quick fix

  • First connect to the mysql as sudo user.
  • Check the users presently available in the databases's user table.
  1. SELECT User,Host FROM mysql.user;
    +------------------+-----------+
    | User             | Host      |
    +------------------+-----------+
    | admin            | localhost |
    | root             |    *      |
    | root             | %         |
    | mysql.sys        | localhost |
    | root             | localhost |
  • Delete all the entries/accounts related to root user.
  • mysql> DROP USER 'root'@'localhost';
    Query OK, 0 rows affected (0,00 sec)
    
    mysql> DROP USER 'root'@'*';
    Query OK, 0 rows affected (0,00 sec)
    mysql> DROP USER '%';
    Query OK, 0 rows affected (0,00 sec)
  • Again insert an entry for root user in the table.
  • mysql> CREATE USER 'root'@'%' IDENTIFIED BY '';
    Query OK, 0 rows affected (0,00 sec)
  • Grant relevant permissions for that particular user of the database and make sure to flush the privileges.
  • mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
    Query OK, 0 rows affected (0,00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0,01 sec)
  • Exit and try to reconnect to the terminal without sudo.