Adding a MySQL Remote User / Accessing MySQL Database Remotely [Simple Solution]

Here is a background – I have two desktops and a laptop that I generally use for development purposes. One of the desktop is my database server. However, when I tried to access the database from either my development laptop or a development desktop, I could not remotely connect to the mysql database that was running just a feet away under my desk within the same network.

Then a little research revealed that the mysql needs to approve a remote usage. There were tons of solutions online, not as close to this one.

All I basically had to do was three basic steps

  1. Add the remote user with it’s ip address in the mysql database (mysql.user)
  2. Grant permissions for this new user.
  3. Then flush the privileges.

My tip is create a unique user id that is not used locally or anonymously (‘user’@’localhost’ or ‘user’@’%’). Although the localhost one should not be a problem, the anonymous one (%) did create a problem by trumping my other ip addresses.

Here is how you can create user id – I suggest you do this from the database server, although it is possible to do it if you already have a remote access established.

NOTE: These commands are run either mysql prompt or your GUI CLIENT

CREATE USER 'someuser'@'192.168.0.77' IDENTIFIED BY 'somepassword';

This will add a user on mysql.user table.

The step to grant permission is:

GRANT ALL ON *.* TO ‘someuser’@‘192.168.0.77’; 

This is granting all permissions, but you can choose your specific ones.

Finally flush the privileges.

FLUSH PRIVILEGES;

In rare cases, you may need to restart the mysql or OS.

How to extract plain Text from HTML Website easily in Java

I was looking for ways to crawl websites, and to be able to only extract text. The reason I was trying to do this was to get the text from various websites to prepare Text Corpus for Natural Language Processing for a Nepali Language. There were several solutions on the internet, but nothing could be as simple as this one. I wrote this using a JSoup Library. In the example below, I have extracted text from the entire body, but if you want you can extract text for a desired node (and children) easily.

/**
 * 
 * @author Kushal Paudyal
 * Created on: 3/9/2017
 * Last Modified on: 3/9/2017
 *
 */
package com.icodejava.research.nlp;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class HtmlTextExtractor {
	
	public static void main (String args []) throws IOException {
		Document doc = Jsoup.connect("http://swasthyakhabar.com/news-details/3356/2017-03-09").get();
		
		System.out.println(doc.body().text());
	}

}

Recursively Finding Greatest Common Divisor (GCD) – Java Implementation

This articles shows a java program that finds a greatest common divisor between two input integers and also prints the intermediate steps of recursion. Can you think about the complexity of this algorithm? It is O(Log(N)) where N is the largest number of the two. See the analysis here.

package com.icodejava.research.ready;
/**
 * 
 * @author Kushal Paudyal
 * Created on: 2/8/2017
 * Last Modified on: 2/8/2017
 * 
 * Recursive way of finding the GCD (Greatest Common Divisor)
 */
public class GCDRecursive {
	
	 public static int gcd(int a, int b) {
		 System.out.println("First Number: " + a + " Second Number: " + b);
	        if (a < 0 || b < 0) {
	            throw new IllegalArgumentException("No GCD of negative integers");
	        }
	        return b == 0 ? a : gcd(b, a % b);
	    }
	 
	 public static void main(String args []) {
		 System.out.println("Greatest Common Divisor of 35 and 21 is " + gcd(35,21));
	 }

}

The following is the output of this program.

First Number: 35 Second Number: 21
First Number: 21 Second Number: 14
First Number: 14 Second Number: 7
First Number: 7 Second Number: 0
Greatest Common Divisor of 35 and 21 is 7