Skip to content

Instantly share code, notes, and snippets.

View vicly's full-sized avatar

Vic vicly

  • Auckland, New Zealand
View GitHub Profile
@vicly
vicly / aws-change-profile.sh
Created December 14, 2018 03:08
[AWS chang profile] #AWS #Bash
#!/bin/bash
export AWS_PROFILE=<PROFILE_NAME> # defined in .aws/config, e.g. system-admin
aws sts get-caller-identity
@vicly
vicly / allow_cognito_invoke_lambda.md
Created November 20, 2018 02:49
[Allow Cognito to invoke lambda] #AWS
  AllowCognitoInvokeLambdaFunctionPermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: lambda:invokeFunction
      FunctionName: !GetAtt LambdaFunction.Arn
      Principal: cognito-idp.amazonaws.com
      SourceArn: !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/<COGNITO_USER_POOL_ID>
@vicly
vicly / git_command.md
Last active July 3, 2019 02:12
[Git command] #Git
# refresh local branches with remote
git remote update origin --prune

Modify last commit message

@vicly
vicly / git_ autocrlf.md
Last active October 17, 2018 01:36
[how autocrlf works] #Git
@vicly
vicly / aws_decrypt.sh
Created September 23, 2018 23:40
[AWS encrypt and decrypt] #AWS #Bash
#!/bin/bash
set -euf -o pipefail
usage() {
echo "Usage: $0 -e [dev|test|preprod|prod] -t [encrypted text in base64]" 1>&2;
exit 1;
}
[ $# -eq 0 ] && usage
@vicly
vicly / bash_profile.sh
Created September 23, 2018 23:36
[bash profile] #Bash #Shell #Handy
# Terminal
export TERM="xterm-color"
PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad
export GREP_OPTIONS='--color=auto'
# Alias
@vicly
vicly / jwtRegex.java
Created August 8, 2018 01:25
[JWT Regex] #Java #Regex
private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final Pattern JWT_PATTERN = Pattern.compile("^([a-zA-Z0-9\\-_]+=*)\\.([a-zA-Z0-9\\-_]+=*)\\.([a-zA-Z0-9\\-_]+=*)$");
Matcher matcher = JWT_PATTERN.matcher(jwt);
if (matcher.matches())
{
String header = matcher.group(1);
@vicly
vicly / publicKeyFromPEMString.java
Created August 8, 2018 01:20
[read public key from PEM string] #Java
import java.security.*;
import java.security.spec.*;
public static java.security.Key publicKeyFromPEMString()
{
String devPublicKey = "-----BEGIN PUBLIC KEY-----\n"
+ "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsXn7MZWEOr1egercQtIk\n"
+ "......\n"
@vicly
vicly / aws_init_client.md
Last active July 20, 2018 04:35
[AWS init client] #AWS

credential from AWS profile

# ~/.aws/credentials
[a-profile]
aws_access_key_id = ...
aws_secret_access_key = ...
@vicly
vicly / tagging_aws_resource.md
Last active July 20, 2018 10:31
[Tagging AWS resource] #AWS

Tag is metadata of a resource; allow up to 50 tag per resource.

Why tagging resource

  1. Reporting: in AWS console or billing reports
  2. Management: tools like Stax use tags to group and classify your cloud data
  3. Permissions: can restrict permission based on tag data
  4. Filtering: AWS Resource Groups allow the console to be filtered based on tag
  5. Automated Processes: used to drive scheduled shutdowns, backup policies, or AWS config policies