Author Archives: admin

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 0.0.0.0:1234:hostA:21 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 domain.net RedirectMatch 301 ^/((?!\.well-known).*)$ https://domain.net/$1 </VirtualHost>

Posted in Uncategorized | Leave a comment

node.js – port test

require(’portscanner’).checkPortStatus( 80, ’192.168.1.234′ , 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 = urls.map(function(url){ 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

Observable.zip()

public interface Api {   @GET("x") Observable<X> getX();   @GET("y") Observable<Y> getY();   } Observable.zip(api.getX(), 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 org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 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

Spring Annotation Based Single Class Web Application

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.Configuration; import org.springframework.stereotype.Controller; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.config.annotation.EnableWebMvc;   @Configuration @EnableWebMvc @Controller public class SpringWebApp implements WebApplicationInitializer {   @RequestMapping("/") @ResponseBody public [...]

Posted in Java, Spring | Leave a comment

Java 8 Lambda expressions

(parameters) -> expression (parameters) -> {statements;} Examples from Java 8 Lambdas: Functional Programming For The Masses Example 1 ActionListener oneArgument = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { System.out.println("button clicked"); } }; ActionListener oneArgument = event -> System.out.println("button clicked"); Example 2 Runnable noArguments = new Runnable() { @Override void run() { System.out.println("Hello World"); [...]

Posted in Java | Leave a comment