Skip to content

Instantly share code, notes, and snippets.

View hsuh's full-sized avatar
🦕

Hsu Hlaing hsuh

🦕
  • Edinburgh
  • 16:06 (UTC -12:00)
View GitHub Profile
url - https://aws.amazon.com/blogs/security/a-safer-way-to-distribute-aws-credentials-to-ec2/
Finding hard-coded credentials in your code
Hopefully you’re excited about deploying credentials to EC2 that are automatically rotated. Now that you’re using Roles, a good security practice would be to go through your code and remove any references to AKID/Secret. We suggest running the following regular expressions against your code base:
Search for access key IDs: (?<![A-Z0-9])[A-Z0-9]{20}(?![A-Z0-9]). In English, this regular expression says: Find me 20-character, uppercase, alphanumeric strings that don’t have any uppercase, alphanumeric characters immediately before or after.
Search for secret access keys: (?<![A-Za-z0-9/+=])[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=]). In English, this regular expression says: Find me 40-character, base-64 strings that don’t have any base 64 characters immediately before or after.
If grep is your preferred tool, run a recursive, Perl-compatible search using the following commands
Step 1.
Rename C:\code\ifrs17\.git\hooks\prepare-commit-msg.sample
and remove .sample
Step 2.
copy/paste the following bash script into prepare-commit-msg
#!/bin/bash
@hsuh
hsuh / README.md
Last active October 19, 2022 04:53 — forked from pasela/README.md

A soft pastel color theme for mintty

This is ported version of color theme xoria256.

screenshot

Settings

Merge mintty-color-xoria256-rc into your .minttyrc

Notes from - http://nvie.com/posts/a-successful-git-branching-model/
The main branches
master
develop
Supporting branches
Feature branches
Release branches
Hotfix branches
QUnit.begin(function(obj) {
console.log("Test amount:" + obj.totalTests);
});
QUnit.moduleStart(function (obj) {
console.log("##teamcity[testSuiteStarted name='" + obj.name + "']");
});
QUnit.moduleDone(function (obj) {
console.log("##teamcity[testSuiteFinished name='" + obj.name + "']");
@hsuh
hsuh / gist:9f4d34f56ce32120e894
Created February 5, 2015 09:26
Adding Mintty to WebStorm 9.0.3
#if you haven't already
1. Install chere
#Run the line below in terminal
chere -i -t mintty -f
Add external tools on WebStorm(Settings):
Program: C:\cygwin64\bin\mintty.exe
Use /J to create a hard link pointing to a directory, also known as a directory junction:
mklink /J Link Target
e.g mklink /J C:\LinkToFolder C:\Users\Name\OriginalFolder
Use quotes "" around the links if the names have spaces
e.g. mklink /J "C:\Link To Folder" "C:\Users\Name\Original Folder"
source - https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/
@hsuh
hsuh / gist:a30b8d89aa20ebf1f1108d595aea02a9
Created February 2, 2017 11:47
prettifying django print
import yaml
a = [0, 1, ['a', 'b', 'c'], 2, 3, 4]
print yaml.dump(a)
@hsuh
hsuh / gist:f128576cd6e201c6bb9ee508a54958b1
Created February 1, 2017 11:39
Javascript floating point numbers
JavaScript's Math object provides a method for rounding to whole numbers. If we want to round to a set number of decimal places, then we have to handle that ourselves. This post doesn't get into the details of floating-point arithmetic, but the short of it is most programming languages use a binary floating-point representation which can only approximate many decimal fractions. This results in rounding errors for the most common approaches to rounding in JavaScript.
Rounding Errors
The most common solutions for rounding to a decimal place is to either use Number.prototype.toFixed(), or multiply the float by some power of 10 in order to leverage Math.round(). Both of these work, except sometimes a decimal of 5 is rounded down instead of up.
Number((1.005).toFixed(2)); // 1 instead of 1.01
Math.round(1.005*100)/100; // 1 instead of 1.01
A Better Solution
The rounding problem can be avoided by using numbers represented in exponential notation:
url - https://forums.aws.amazon.com/message.jspa?messageID=671934
You could verify that they match a regular expression that describes every access key and every secret key (the AWS Security Blog has regexes you could use), but there's no way for the SDK to check if your credentials are valid without sending a request to a service. (Otherwise, the SDK would need to ship with everyone's access keys embedded in its source.)
If you do make a call to a service, though, the remote service will be able to validate your credentials and respond accordingly. If you call $s3Client->listBuckets() before calling $s3Client->registerStreamWrapper(), the client will call the service and convert the error to an exception if your credentials are invalid.