Enable grub boot menu from window 10

Dec 29, 2017 1 min.

Execute the following command from Windows 10 in command prompt (run as administrator) bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi Execution Logs for reference: Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>bcdedit Windows Boot Manager -------------------- identifier {bootmgr} device partition=\Device\HarddiskVolume1 path \EFI\Microsoft\Boot\bootmgfw.efi description Windows Boot Manager locale en-US inherit {globalsettings} default {current} resumeobject {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} displayorder {current} toolsdisplayorder {memdiag} timeout 30 Windows Boot Loader ------------------- identifier {current} device partition=C: path \WINDOWS\system32\winload.

MySQL MariaDB Export and Import

Dec 26, 2017 2 min.

Export the database Use the following command to export the database mysqldump --user=<<db-user>> --password=<<db-password \  --host=<<db-host>> --port=3306 \ --single-transaction --compress --routines \ --result-file=dump.sql \ --databases <<db-name>>; Note: Include –single-transaction –compress to export and import quickly. Check documentation for the use --rountines will include procedures/functions in the dump (triggers included by default) --result-file will be the output file (instead of this param, output redirection like mysqldump [options] > dump.sql can be used, however it may have charset issues in OS like windows if you have any blob columns then include –hex-blob Import the database Use the following command to import the database

MySQL MariaDB Create User

Dec 26, 2017 1 min.

Create a user similar to root To create user with all the privileges similar to root. CREATEUSER'superuser'@'%'IDENTIFIEDBY'password';GRANTALLPRIVILEGESON*.*TO'superuser'@'%'WITHGRANTOPTION;FLUSHPRIVILEGES;Create user for Backup A separate user with minimal privileges for taking database dump. CREATEUSER'backup'@'localhost'IDENTIFIEDBY'mypassword';GRANTSELECT,SHOWVIEW,RELOAD,REPLICATIONCLIENT,EVENT,TRIGGER,LOCKTABLESON*.*TO'backup'@'localhost';Note: LOCK TABLES privilege can be removed if db has only InnoDB Create role and assign required privileges -- Create the role CREATEROLEtestrole;-- Grant privileges to the role -- OPTION 1: Grant all privileges on the database GRANTALLPRIVILEGESONtestdb.*TOtestrole;-- OPTION 2: Give selected privileges GRANTindex,create,select,insert,update,delete,drop,alter,locktablesONtestdb.

MySQL MariaDB utf8 to utf8mb4

Dec 25, 2017 1 min.

Change server settings Refer: https://yottabrain.org/database/mysql/mysql-mariadb-set-utf8mb4-as-default-charset/ on AWS RDS a parameter group needs to be created to apply above settings: refer: http://aprogrammers.blogspot.in/2014/12/utf8mb4-character-set-in-amazon-rds.html Change database Run this SQL for each database: ALTERDATABASEmydbCHARACTERSET=utf8mb4COLLATE=utf8mb4_unicode_ci;Change size of indexed columns Reduce the length of indexed columns with utf8mb4 from 256 to 190 because index with 4byte utf8mb4 have issues ALTERTABLEmydb.mytableMODIFYCOLUMNmycolumnvarchar(190)CHARACTERSETutf8mb4COLLATEutf8mb4_unicode_ci;Change Tables Run this SQL for each table: ALTERTABLEmydb.mytableCONVERTTOCHARACTERSETutf8mb4COLLATEutf8mb4_unicode_ci;Change Columns Run this SQL for the columns which needs to be stored as utf8mb4:

JEE Container Managed Transaction

Dec 25, 2017 1 min.

Transaction Attribute Client’s Transaction Business Method’s Transaction Required None T2 T1 T1 RequiresNew None T2 T1 T2 Mandatory None error T1 T1 NotSupported None None T1 None Supports None None T1 T1 Never None None T1 Error Container Manager Transaction

Java Time Difference

Dec 24, 2017 2 min.

Time difference can be calculated by subtracting the milliseconds. And then milliseconds can be converted into different Units using TimeUnit. e.g. TimeUnit.MILLISECONDS.toSeconds(1000) will give 1 because 1 second equivalent to 1000 millisecons. Following sample gives a example of finding difference between two dates and converting them into different units import java.util.Date; import java.util.concurrent.TimeUnit; public class TimeDifference { public static void main(String[] args) { Date date1 = new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)); Date date2 = new Date(); long timeDifferenceInDays = TimeUnit.

JAXRS Rest Client

Dec 20, 2017 1 min.

Option 1 : Using interface proxy import javax.ws.rs.FormParam; import javax.ws.rs.HeaderParam; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; public class RestClient { public static void main(String[] args) { final MyApiClient client = JAXRSClientFactory.create("<http://localhost:8080/api>", MyApiClient.class); final HTTPClientPolicy clientPolicy = WebClient.getConfig(client).getHttpConduit().getClient(); clientPolicy.setConnectionTimeout(15 * 1000); clientPolicy.setReceiveTimeout(15 * 1000); final Response response = client.hello("your-authorization-token", "javawiki"); System.out.println("Response Status: " + response.getStatus()); } } @Path("/testapi") public interface MyApiClient { @PUT @Path("/hello") Response hello(@HeaderParam("AUTHORIZATION") String authorization, @FormParam("name") String name); } Option 2: Direct client import javax.

Java get hostname and IP address

Dec 19, 2017 1 min.

Use java.net.InetAddress to get hostname or IP Address To get local hostname or IP import java.net.InetAddress; public class LocalIPGetter { public static void main(String[] args) throws Exception { InetAddress inetAddress = InetAddress.getLocalHost(); // Get Hostname System.out.println(inetAddress.getHostName()); // Get IP Address System.out.println(inetAddress.getHostAddress()); } } $javac LocalIPGetter.java $java LocalIPGetter mytestpc To get remote hostname or IP import java.net.InetAddress; public class RemoteIPGetter { public static void main(String[] args) throws Exception { InetAddress inetAddress = InetAddress.

MySQL MariaDB Set utf8mb4 as default charset

Nov 22, 2017 2 min.

By default charset is set to to latin1 and utf8. This can be checked by executing the following command MariaDB [(none)]> SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; +--------------------------+-------------------+ | Variable_name | Value | +--------------------------+-------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +--------------------------+-------------------+ To set the charset as utf8mb4 do the following steps:

Install Mariadb in Aws Ec2

Nov 22, 2017 2 min.

These steps can be used install mariadb on any Ubuntu based Linux system (local desktop, aws ec2, etc.) Install MariaDB Execute the following commands: curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash sudo apt install mariadb-server During this setup, it will ask for root password. Enter and keep a note of it. Install a specific version curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.3" sudo apt install mariadb-server For NON LTS version Goto this link: https://downloads.