Skip to content

Instantly share code, notes, and snippets.

View hsuh's full-sized avatar
🦕

Hsu Hlaing hsuh

🦕
  • Edinburgh
  • 03:34 (UTC -12:00)
View GitHub Profile
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
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.
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
@hsuh
hsuh / objects.js
Created January 10, 2016 20:39
Mucking about with javascript objects
var a = function(y) {
var z = 1; //shared between instances, accessible via prototype method
var x = 2; //shared between instances
var self = this;
this.y = null; //not shared
var impl = function(y) {
};
var init = function(y) {
@hsuh
hsuh / gist:d0e6727e42fc2c504734
Last active August 29, 2015 14:20
Removing old linux images
*** 1. Remove --no-act for run the commands for real.
*** 2. Find out the range of your kernel version numbers and replace the numbers below. e.g. {start..end}
Finding out versions:
dpkg -l | grep linux-image
Purging the images:
sudo dpkg -P --no-act --force-depends linux-image-3.13.0-{32..46}-generic
sudo dpkg -P --no-act --force-depends linux-image-extra-3.13.0-{32..46}-generic
sudo dpkg -P --no-act --force-depends linux-headers-3.13.0-{32..46}-generic
@hsuh
hsuh / README.md
Last active August 29, 2015 14:18 — forked from mbostock/.block
@hsuh
hsuh / gist:1a087fe39e67aae7910f
Created March 18, 2015 07:55
angularjs directive to directive communication (directive's controllers)
app.directive("child", function() {
return {
...
require: ["^parent", "child"],
link: function(scope, elem, attrs, ctrls) {
var parentController = ctrls[0],
childController = ctrls[1];
childController.setParent(parentController);
},