Skip to content

Instantly share code, notes, and snippets.

View barata0's full-sized avatar

Daniel Ribeiro barata0

  • Rio de Janeiro
View GitHub Profile
@barata0
barata0 / UrlQueryStringParser.groovy
Created July 16, 2017 15:51
Groovy Url Query String Parser. accepts multiple keys (every key has an array as value) and accept a equal sign = on the query value (
def parseQuery(query) {query.split('&').collect{it.split('\\=', 2)}.groupBy{it[0]}.collectEntries{k, v ->[k, v.collect{it.size() == 2 ? it[1] : ''}]}}
// USAGE EXAMPLE BELOW (uncomment lines below to test)
// def query = 'orange=price=10&orange=color=red&edit&separator==========='
// def queryParameters = parseQuery(query)
// assert queryParameters.toString() == '[orange:[price=10, color=red], edit:[], separator:[==========]]'
// assert queryParameters.orange[0] == 'price=10'
// assert queryParameters.orange[1] == 'color=red'
@barata0
barata0 / proxy-server.js
Created December 14, 2016 17:15
A nodejs proxy server e.g. https to http
// To start
// node proxy-server.js REMOTE_ADDR PORT
// REMOTE_ADDR the remote address. eg. https://my-secure-site
// PORT port number to listen
var http = require('http');
var request = require('request');
var url = require('url')
@barata0
barata0 / ignore_ssl.groovy
Created December 13, 2016 21:08
Ignore SSL certs in groovy
def nullTrustManager = [
checkClientTrusted: { chain, authType -> },
checkServerTrusted: { chain, authType -> },
getAcceptedIssuers: { null }
]
def nullHostnameVerifier = [
verify: { hostname, session ->
//true
hostname.startsWith('yuml.me')
@barata0
barata0 / java_pack_to_jar.bat
Created December 13, 2016 20:41
Altera as extensões dos arquivos .pack para .jar no pacote de instalação JAVA.
for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar"
@barata0
barata0 / allow-s3-bucket.json
Created December 5, 2016 13:44
Allow Access to s3 specific Bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
@barata0
barata0 / .profile
Created July 18, 2016 14:45
Ubuntu bash with colors and path and ll alias
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
@barata0
barata0 / elasticsearch-reindex.groovy
Created June 15, 2016 17:51
Elasticsearch reindex groovy script. Read from oldServer/oldIndex/oldType/ and saves it on newServer/newIndex/newType
/*
* Reindex elasticsearch
* Read all documents from oldServer/oldIndex/oldType and put them into newServer/newIndex/newtype
* If the newIndex raises an error script will print and stop
*/
/* Configuration START */
// OLD Server config - READ_ONLY
def oldServer = "http://localhost:9200"
@barata0
barata0 / sub-directories-size-linux
Created April 11, 2016 14:42
sub directories size in linux
du -h --max-depth=1
@barata0
barata0 / sha256base64.groovy
Created April 5, 2016 22:41
generate a SHA256 encoded as Base64
@Grapes(
@Grab(group='commons-codec', module='commons-codec', version='1.10')
)
import java.security.*
import java.util.Base64;
def file = new File('c:/users/danielr/Downloads/mortalkombat.mp4')
FileInputStream fis = new FileInputStream(file);
def md5 = org.apache.commons.codec.digest.DigestUtils.sha256(fis);
fis.close()
println md5
@barata0
barata0 / log4j.properties
Created August 13, 2015 21:26
console and rolling file appender for a log4j.properties file
log4j.debug=true
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=TRACE, CONSOLE, ROLLINGFILE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%6.6r]%m%n