Skip to content

Instantly share code, notes, and snippets.

@valtoni
valtoni / git-rewrite-source-target.sh
Last active October 18, 2016 11:44
Rewrite target author and commiter name/email/date with data from source commit
#!/bin/sh
# Rewrite's the commit with data from source commit
echo "WARNING: Your TARGET_COMMIT must have in your current branch."
SOURCE_COMMIT=$1
TARGET_COMMIT=$2
SOURCE_COMMIT=$(git rev-parse $SOURCE_COMMIT)
if [ $? -ne 0 ]; then
@valtoni
valtoni / git-branches-by-commit-date.sh
Created September 2, 2016 18:46 — forked from l15n/git-branches-by-commit-date.sh
List remote Git branches and the last commit's author and author date for each branch. Sort by most recent commit's author date.
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ai %ar by %an" $branch | head -n 1` \\t$branch; done | sort -r
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class ReferenceToConstructor {
/**
* @param args the command line arguments
*/
@valtoni
valtoni / extract_cert_keystore.sh
Created May 29, 2016 13:36
Script to export certificate and private key from jks store
#!/bin/bash
FILE=$1
OUTPUT_NAME=$2
# Export to PKCS12 format
keytool -importkeystore -srckeystore "$FILE" -destkeystore "$OUTPUT_NAME".p12 -deststoretype PKCS12
# Export certificate in pem format
openssl pkcs12 -in "$OUTPUT_NAME".p12 -nokeys -out "$OUTPUT_NAME"_cert.pem
# Export certificate in x509 format
@valtoni
valtoni / char-donot-repeat.py
Created April 18, 2016 11:30
Do not repeat chars in python
word = raw_input()
reduced_word = ''.join(
[char for index, char in enumerate(word) if char not in word[0:index]])
@valtoni
valtoni / GMapV2Direction.java
Last active April 8, 2016 12:23
How to obtain directions from code to destiny, using google maps api.
import java.io.InputStream;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
public class Testa {
private static int fatorial(int numero) {
if (numero == 1)
return 1;
return numero * fatorial(--numero);
}
private static int combinacao(int n, int p) {
return fatorial(n) / (fatorial(n - p) * fatorial(p));
}
@valtoni
valtoni / MemoryPropertyBuilder.java
Created April 14, 2015 12:44
Create an property file in memory (Builder like)
static class MemoryPropertyBuilder {
StringBuilder builder = new StringBuilder();
PropertyBuilder add(String param, String value) {
builder.append(param + "=" + value);
return this;
}
Properties properties() {
@valtoni
valtoni / config-ddwrt-rw.sh
Last active June 29, 2017 17:39 — forked from Thinkscape/gist:3426581
Config Read Write mode in DD WRT Router
# From: http://www.dd-wrt.com/phpBB2/viewtopic.php?t=86912
# 1. Prepare the USB disk
# Create an ext3 partition using GParted for instance
#2. Configure DD-WRT
#Under Services->Services->Secure Shell:
#* Enable SSHd
#* Click Apply Settings
#
public class Ipc2014ProblemA {
private static class BaggageBin {
int space;
char destination;
public BaggageBin(int space) {
if (space > 0) {
if (space % 2 == 0) {
this.destination = 'A';