git: file history with diff

Show diff ONLY for src/main/resources/file.xml
git log -p src/main/resources/file.xml

Show diff for ALL FILES that touches src/main/resources/file.xml
git log -p --full-diff src/main/resources/file.xml

Posted in git | Leave a comment

async.js – download multiple files from multiple urls to first success

var async = require('async');
var files = ['file1','file2','file3'];
var urls = ['url1','url2','url3'];
var down = function(url, file, callback) {
		var r = Math.random() >= 0.5;
		console.log('--- end '+file+', '+url+', '+r);
	}, 1000);
async.concat(files, function(file, callback){
	async.someSeries(urls, function(url, callback1){
		down(url, file, function(isOk){
			callback1(null, isOk);
	}, function(err, r){
		callback(err, r);
}, function(err, fullRes){
Posted in JavaScript, async.js | Leave a comment

SSH Tunneling with plink

To make local port 1234 forwarding to remote hostA port 21:
plink -v -C -N -L 1234:hostA:21 user@hostB
Now You can connect to localhost:1234 to access hostA:21 by tunnel created with hostB.

To accept connection from other hosts (not local only):
plink -v -C -N -L user@hostB

Posted in plink, ssh | Leave a comment

HTTPS Redirect with exclude

Example how to redirect to HTTPS, but excluding .well-know/* directory.

<VirtualHost *:80>
   RedirectMatch 301 ^/((?!\.well-known).*)$$1
Posted in Uncategorized | Leave a comment

node.js – port test

80, ''
, function(error, status) {
Posted in node.js | Leave a comment

async.js: parallel get

 * jednoczesne wywolanie GET'ow na adresy
 * zwracana jest tablica odpowiedzi w callbacku
 * jako drugi parametr lub error jako pierwszy
var parallelGets = function(urls, callback) {
	var calls ={
		return function(callback){
 	    	       $.get(url, function(data){
				callback(null, data);
	async.parallel(calls, function(err, res){
		if(err) {
		} else {
			callback(null, res);
Posted in JavaScript, async.js | Leave a comment

RxJava .reduce()

Observable.from(new Integer[]{1,2,3,4,5})
.reduce(new Func2<Integer, Integer, Integer>() {			
	public Integer call(Integer t1, Integer t2) {
		return t1+t2;
}).subscribe(new Action1<Integer>() {
	public void call(Integer t) {
                // t = 15
Posted in Java, RxJava | Leave a comment

public interface Api {
    Observable<X> getX();
    Observable<Y> getY();
}, api.getY(), new Func2<X, Y, Pair>() {
    public Pair call(X x, Y y) {
        return new Pair(x, y);
}).subscribe(new Action1<Pair>() {
    public void call(Pair pair) {
        // you got pair ;)
Posted in Java, Retrofit, RxJava | Leave a comment

RxJava – Observable.interval()

package rxjava;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Observer;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
public class RxInterval {
	private final Random random = new Random();
	public RxInterval() {
		Observable<Integer> observable = Observable
		.interval(5, TimeUnit.SECONDS)
                 * startWith()
		 * do Observable dodawany jest element startowy, który emitowy jest przed pierwszym głównym, 
		 * a między nimi nie ma zwłoki - efekt jest taki, że pierwszego Integer'a dostajemy od razu, 
		 * a nie po 5 sekundach
		.map(new Func1<Long, Integer>() {
			public Integer call(Long t) {
				return random.nextInt();
		Observer<Integer> observer = new Observer<Integer>() {
			 * observable skonczyl emisje
			public void onCompleted() {
			 * observable gdzies sie wysypal
			public void onError(Throwable e) {
				// TODO Auto-generated method stub
			 * nowy element z observable
			public void onNext(Integer t) {
	public static void main(String[] args) {
		new RxInterval();
Posted in Java, RxJava | Leave a comment

Spring Annotation Based Single Class Web Application with JSP View Resolver

Works on Servlet 3.0+ containers.
Better not mix Configuration classes with Controller classes. It is only for simplicity ;)

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
public class SpringWebApp implements WebApplicationInitializer {
	public String helloView(Model model) {
		model.addAttribute("hello", "Hello World!");
		return "hello";
	 * jsp View Resolver
	 * @return
	public ViewResolver internalViewResolver() {
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		 * put Your .jsp in src/main/webapp/WEB-INF/views/ directory
		return resolver;
	 * initialize Spring Dispatcher Servlet 
	 * required Servlet Container 3.0+
	public void onStartup(ServletContext servletContext) throws ServletException {
		AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
		ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));

Complete pom.xml

<project xmlns="" xmlns:xsi=""
			<!-- Jetty testing server -->


Posted in Java, Spring, jetty | Leave a comment