Spring jdbcTemplate query using Lambda

public class Employee
{
	private int id;
	private String name;
	private double salary;

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public double getSalary()
	{
		return salary;
	}

	public void setSalary(double salary)
	{
		this.salary = salary;
	}

	public Employee(int id, String name, double salary) {
		super();
		this.id = id;
		this.name = name;
		this.salary = salary;
	}

	@Override
	public String toString()
	{
		return "Employee [id=" + id + ", name=" + name + ", salary=" + salary + ", getId()=" + getId() + ", getName()="
				+ getName() + ", getSalary()=" + getSalary() + ", getClass()=" + getClass() + ", hashCode()="
				+ hashCode() + ", toString()=" + super.toString() + "]";
	}

}


import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;

public class EmployeeDao
{

	private final JdbcTemplate jdbcTemplate;

	public EmployeeDao(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public List<Employee> findEmployes()
	{

		return jdbcTemplate.query("select id,name ,salary from Employee", new Object[] {},
				(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("name"), rs.getDouble("salary")));
	}
}

Read More

JRI

In Mac:

.Install R
.install.packages(“rJava”)

Create Java Application with eclipse:

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;


public class JavaToR {

	public static void main(String[] args) {
		System.out.println("Hello");
		
		// Start R session.
		Rengine re = new Rengine (new String [] {"--vanilla"}, false, null);

		// Check if the session is working.
		if (!re.waitForR()) {
		    return;
		}

		re.assign("x", new double[] {1.5, 2.5, 3.5});
		REXP result = re.eval("(sum(x))");
		System.out.println(result.asDouble());
		re.end();
	}

}

Run application config:

VM arguments: -Djava.library.path=/Library/Frameworks/R.framework/Resources/library/rJava/jri/
Environment variable: R_HOME: /Library/Frameworks/R.framework/Resources

More linkes:
1. https://stackoverflow.com/questions/4894002/question-about-jri-error
2. https://bioincloud.wordpress.com/2015/04/02/jri-javar-problem-java-lang-unsatisfiedlinkerror-no-jri-in-java-library-path/
3. https://autofei.wordpress.com/2010/08/04/getting-rjavajri-to-work-it-is-painful/
4. http://www.studytrails.com/r/r-and-java-jri-using-eclipse/

Read More

Right click, open folder with sublime text


@echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
pause

Read More

Git cherry-pick from another repository

Git cherry-pick from another repository


# Cloning our fork
$ git clone git clone git@gitlab.com:tongancity/Leespace-git-demo.git

# Adding (as "demo2") the repo from we want to cherry-pick
$ git remote add demo2 git@gitlab.com:tongancity/Leespace-git-demo2.git

# Fetch their branches
$ git fetch demo2

# List their commits
$ git log  demo2/develop 

# Cherry-pick the commit we need
$ git cherry-pick  d434sgdffedac 

# Pushing to our master
$ git push origin develope

Read More

How to set up a Nginx server on Mac computer

From wiki: Nginx (pronounced “engine-x”) is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavors. It also has a proof of concept port for Microsoft Windows.

 

  • Step 1: install nginx with command:
    • brew install nginx
  • step 2: Prepare for start nginx service
    • sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
    • sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
  • step 3: You can also do some basic configuration by specifying the location file is feeding up.
    • By default, nginx is running on port 8080, so you can verify if the server is running of not by visiting :http://localhost
    • Also, if you want to stop the servie, you can run this command
    • sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

The nginx configuration file is located in /usr/local/etc/nginx/

Here is an example for some basic setting:

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

root /var/www/virtual/test.com/htdocs;
index index.html inde.htm;

location / {
default_type “text/html”;
try_files $uri.html $uri $uri/ /index.html;
}

you need to restart nginx service to have the new setting loaded up, so with this simple change, port is changed to 80 from 8080 and you can visit your site from http://localhost.
Enjoy!

Read More