Author Archives: admin

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) { setTimeout(function(){ var r = Math.random() >= 0.5; console.log(’— end ‘+file+’, ‘+url+’, ‘+r); callback(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); [...]

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> ServerAlias RedirectMatch 301 ^/((?!\.well-known).*)$$1 </VirtualHost>

Posted in Uncategorized | Leave a comment

node.js – port test

require(’portscanner’).checkPortStatus( 80, ’′ , function(error, status) { console.log(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); }).fail(function(jqXHR){ callback(jqXHR); }); }; }); async.parallel(calls, function(err, res){ if(err) { callback(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>() { @Override public Integer call(Integer t1, Integer t2) { return t1+t2; } }).subscribe(new Action1<Integer>() { @Override public void call(Integer t) { // t = 15 } });

Posted in Java, RxJava | Leave a comment

public interface Api {   @GET("x") Observable<X> getX();   @GET("y") Observable<Y> getY();   }, api.getY(), new Func2<X, Y, Pair>() { @Override public Pair call(X x, Y y) { return new Pair(x, y); } }).subscribe(new Action1<Pair>() { @Override 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 [...]

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; 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;   @Configuration @EnableWebMvc @Controller public class [...]

Posted in Java, Spring, jetty | Leave a comment