Skip to content

Instantly share code, notes, and snippets.

View grational's full-sized avatar

Giuseppe Ricupero grational

View GitHub Profile
@grational
grational / RemoteExecOfLongRunningTask.groovy
Last active October 7, 2015 13:31
Execute remotely a long running command in java/groovy
#!/bin/bash
//bin/true && SCRIPT_DIR="$(dirname $(readlink -f "${0}"))"
//bin/true && exec groovy -cp "${SCRIPT_DIR}/lib" "${0}" "${@}"; exit $?
@Grab(group='ch.ethz.ganymed', module='ganymed-ssh2', version='262')
import ch.ethz.ssh2.*
String hostname = "localhost";
String username = "gsus";
@grational
grational / HttpsConnWithProxy.java
Created September 29, 2015 10:39
Java HTTPS Connection with HTTP Proxy
String proxyIpAddress = "192.168.0.1";
String proxyPort = "80";
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(
new Proxy( Proxy.Type.HTTP,
new InetSocketAddress(proxyIpAddress, proxyPort) ) //close new Proxy
); //close url.openConnection
@grational
grational / MatrixPermutations.groovy
Last active October 6, 2015 14:59
Generate Permutations of a given seed with some constraints
#!/bin/bash
//bin/true && SCRIPT_DIR="$(dirname $(readlink -f "${0}"))"
//bin/true && exec groovy -cp "${SCRIPT_DIR}/lib" "${0}" "${@}"; exit $?
/*
* Given N elements (with N = 6):
*
* ['C', 'G', 'Q', 'F', 'M', 'E']
*
* and given a matrix NxP where P is the number of permutations of N
@grational
grational / filterbyRegex.java
Last active November 9, 2015 17:01
Extract service from input string
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//Example Input Strings
//String filterby = [ "13|123.12|123.service|1.12|123.service|2", "service|1.12|123.service|2", "service|1.service|2", "13|123.12|123.12|123", "13|123", "service|1" ]
//Filter services from filterby
String[] results = filterby.split("\\.?service\\|\\d+");
StringBuilder sb = new StringBuilder();
for( String result in results) {