Skip to content

Instantly share code, notes, and snippets.

View ariesmcrae's full-sized avatar
💭
typescript, node.js, aws, java, go (golang)

A. M. ariesmcrae

💭
typescript, node.js, aws, java, go (golang)
View GitHub Profile
Verifying that "ariesmcrae.id" is my Blockstack ID. https://onename.com/ariesmcrae
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React Counter</title>
</head>
<body>
<br/><br/>
<div id="app"></div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React Counter</title>
</head>
<body>
<br/><br/>
<div id="app"></div>
@ariesmcrae
ariesmcrae / DBHelper.java
Created May 12, 2017 03:14
Amazon EC2 Systems Manager Parameter Store - get environment key/value pairs using AWS SDK Java
private static Map<String, String> parameterStore() {
final AWSSimpleSystemsManagement client = AWSSimpleSystemsManagementClientBuilder.defaultClient();
GetParametersRequest request = new GetParametersRequest();
request.withNames("driver", "host", "port", "schema", "username", "password").setWithDecryption(true);
GetParametersResult result = client.getParameters(request);
Map<String, String> store = new HashMap<>();
@ariesmcrae
ariesmcrae / CredStashUtil.java
Last active May 27, 2017 05:46
Retrieve credstash values using Java JCredStash
private static Map<String, String> getStore() {
final String dynamoDbTableName = "credential-store";
AmazonDynamoDB dynamoDbClient = AmazonDynamoDBClientBuilder
.standard()
.withRegion(Regions.AP_SOUTHEAST_2)
.build();
AWSKMS awskmsClient = AWSKMSClientBuilder
.standard()
@ariesmcrae
ariesmcrae / CreditCardMasker.java
Last active August 20, 2022 08:10
Credit card masker. Any digits between 13 - 16 will be masked.
public static String maskCreditCard(String sentenceThatMightContainACreditCard) {
String maskedSentence = null;
// Find sequence of numbers between 13-16.
// Numbers can have dashes, spaces, or no dashes / no spaces.
Pattern regex = Pattern.compile("\\b(?:\\d[ -]*?){13,16}\\b");
Matcher regexMatcher = regex.matcher(sentenceThatMightContainACreditCard);
if (regexMatcher.find()) {
@ariesmcrae
ariesmcrae / DBHelper.java
Created May 16, 2017 07:27
This will get environment variables from AWS Lambda
//http://docs.aws.amazon.com/lambda/latest/dg/env_variables.html
public static Sql2o getSql2oInstance() {
//These will get environment values from the AWS Lambda,
//which are declared in the Lambda web page.
final String host = System.getenv("host");
final String port = System.getenv("port");
final String schema = System.getenv("schema");
final String username = System.getenv("username");
final String password = System.getenv("password");
@ariesmcrae
ariesmcrae / pagination.md
Last active June 3, 2017 05:03
Pagination through REST API requests
@ariesmcrae
ariesmcrae / CreditcardMasker.java
Last active September 2, 2020 15:27
This will mask the following credit cards: Visa, Mastercard, Amex, Diners, Discovery, JCB
/**
* This will mask a portion of a credit card with 'x' if it finds it in a sentence.
\b(?:
# Visa card number 4[\ -]*(?:\d[\ -]*){11}(?:(?:\d[\ -]*){3})?\d|
# MasterCard card number (?:5[\ -]*[1-5](?:[\ -]*\d){2}|(?:2[\
-]*){3}[1-9]|(?:2[\ -]*){2}[3-9][\ -]*\d|2[\ -]* [3-6](?:[\ -]*\d){2}|2[\
-]*7[\ -]*[01][\ -]*\d|2[\ -]*7[\ -]*2[\ -]*0)(?:[\ -]*\d){12}|
@ariesmcrae
ariesmcrae / DateConversion.java
Last active February 16, 2018 07:11
Convert string to LocalDate in Java 8+
/**
* Performs date validation and conversion of String to LocalDate.<br/>
* If valid, then date string is converted to LocalDate.
* @param input Date string in format.
* @return the LocalDate.
*/
public static LocalDate toDate(String date) {
if (date == null || date.trim().length() == 0) {
throw new RuntimeException("Date input can't be null.");
}