Skip to content

Instantly share code, notes, and snippets.

View grational's full-sized avatar

Giuseppe Ricupero grational

View GitHub Profile
@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) {
@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 / 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 / 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 / extractLanding.java
Created November 9, 2015 16:16
Extract central field of the landing url
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String input = "https://test-landing.seat.it/Ristoranti_di_SCHIRALLI_ANTONIO_14b9/home.html";
//Extract services
final Pattern landingPattern = Pattern.compile(":\\/\\/.*\\/(.*)\\/");
Matcher m = landingPattern.matcher(input);
if(m.find()) {
@grational
grational / python_parametric_sub.py
Created November 11, 2015 16:54
Replace a matching group with a name passed as parameter with another parameter
import re
from functools import partial
pattern = '^[a-zA-Z0-9-_]*_(?P<pos>[A-Z]\d\d)_T\d{4}(?P<fID>F\d{3})L\d{2}A\d{2}(?P<zID>Z\d{2})(?P<cID>C\d{2})\.tif$'
filename = '151006_655866_Z01_T0001F015L01A02Z01C03.tif'
def replace_closure(subgroup, replacement, m):
if m.group(subgroup) not in [None, '']:
start = m.start(subgroup)
#!/bin/bash
# set -e: if a command fails, it will make the whole script exit
# set -u: treat unset variables as an error, and immediately exit.
set -eu
SCRIPT_NAME="${0##*/}"
usage() {
echo "${SCRIPT_NAME} usage:"
echo '<*> [-P | --profile] <local|test|production>'
@grational
grational / build.gradle
Created May 26, 2016 09:45
Simple gradle configuration to run a java standalone binary
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the application plugin to run standalone artifacts
apply plugin: 'application'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
@grational
grational / IOL-smart-cap-usage.java
Created June 27, 2016 09:23
This class is just a simple test cases for the SmartCap filter
import it.italiaonline.rnd.filters.TextFilter;
/**
* This class includes simple test cases for the SmartCap filter
* <p>
* A couple of arrays are defined with input / expected_output and a for loop
* to couple them checking against the SmartCap filter.
* @author Giuseppe Ricupero
* @date 27/06/16 09.12
*/
import it.italiaonline.rnd.filters.TextFilter;
/**
* This class includes simple test cases for the AddressSmartCap filter
* <p>
* A couple of arrays are defined with input / expected_output and a for loop
* to couple them checking against the SmartCap filter.
* @author Giuseppe Ricupero
* @date 26/10/16 10.26
*/