Skip to content

Instantly share code, notes, and snippets.

View cassiomolin's full-sized avatar
☘️
Living, working and drinking in Ireland

Cassio Mazzochi Molin cassiomolin

☘️
Living, working and drinking in Ireland
View GitHub Profile
@cassiomolin
cassiomolin / LocalDateParamConverterProvider.java
Last active October 27, 2017 09:55
Parameter converters for JAX-RS
import javax.ws.rs.BadRequestException;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@cassiomolin
cassiomolin / gist:a767e63efb4800f8efdcd402f1814400
Created July 4, 2017 20:22
Delete tag from Git repository
git tag -d [tag]
git push origin :refs/tags/[tag]
@cassiomolin
cassiomolin / Sample.java
Created July 4, 2017 11:09
Read JAX-RS Response payload into a Map<String, Object>
Map<String, Object> payload = response.readEntity(new GenericType<Map<String, Object>>() { });
@cassiomolin
cassiomolin / Sample.java
Created June 30, 2017 12:24
Generate public key from private key in Java
private static PublicKey generatePublicKey(PrivateKey privateKey) throws NoSuchAlgorithmException,
InvalidKeySpecException {
RSAPrivateCrtKey privateCrtKey = (RSAPrivateCrtKey) privateKey;
RSAPublicKeySpec publicKeySpec =
new RSAPublicKeySpec(privateCrtKey.getModulus(), privateCrtKey.getPublicExponent());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(publicKeySpec);
}
@cassiomolin
cassiomolin / instructions.md
Created June 30, 2017 11:59
Generating key pair with openssl

Example of creating a 3072-bit private and public key pair in files, with the private key pair encrypted with password foobar:

openssl genrsa -aes128 -passout pass:foobar -out privkey.pem 3072
openssl rsa -in privkey.pem -passin pass:foobar -pubout -out privkey.pub

See more in this Stack Overflow answer.

@cassiomolin
cassiomolin / loading-bouncycastle-provider.md
Last active June 30, 2017 10:48
Loading Bouncy Castle Provider dynamically
@cassiomolin
cassiomolin / instructions.md
Last active June 30, 2017 11:37
Hiding derived .js and .js.map in Visual Studio Code when working with TypeScript

Add the following to the settings.json file (File > Preferences > Settings):

"files.exclude": {
  "**/*.js": {"when": "$(basename).ts"},
  "**/*.map": {"when": "$(basename).map"}
}

See: Hide .js.map files in Visual Studio Code

@cassiomolin
cassiomolin / BasicAuthenticationFilter.java
Created June 26, 2017 17:06
HTTP Basic Authentication filter
import javax.inject.Inject;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Principal;
import java.util.Base64;
@cassiomolin
cassiomolin / DirectoryFilter.java
Last active June 22, 2017 10:00
Filtering directories in Java
Path dir = ...
DirectoryStream.Filter<Path> filter = entry -> Files.isDirectory(entry) && entry.getFileName().toString().startsWith("foo");
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
for (Path path : stream) {
System.out.println(path.getFileName());
}
} catch (IOException e) {
e.printStackTrace();
}
@cassiomolin
cassiomolin / Configurable.java
Last active June 20, 2017 18:45
Property configuration with CDI (simple alternative to Apache DeltaSpike Configuration Mechanism)
import javax.enterprise.util.Nonbinding;
import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Qualifier
@Retention(RUNTIME)