Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
emmanuelnk / .gitconfig
Last active January 6, 2020 07:10
Git Recent: Add git alias to display recently accessed branches in descending order (and with color!)
[alias]
recent = "!r(){ git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always|column -ts'|'; }; r"
@emmanuelnk
emmanuelnk / timestampUpdate.js
Last active August 14, 2019 03:01
Recursively update all timestamps in a document to current timestamps based on when the document/fixture was created (Moment.js, Node.js)
// great for fixtures used in tests that need to stay up to date
// needs moment.js
const moment = require('moment')
const updateTimestamps = (entity, baseTimestamp, path = '', tsFields) => {
// usage: recusrively updates all Timestamps in a json fixture for tests
const nowTs = moment().clone().startOf('hour')
const diff = Math.abs(nowTs.diff(baseTimestamp, 'hours'))
@emmanuelnk
emmanuelnk / git_clean.bash
Created July 4, 2019 08:17
Git: Clean out branches merged to master branch from local git repository (without deleting master branch)
git branch --merged master | grep -v "\master" | xargs -n 1 git branch -d
@emmanuelnk
emmanuelnk / script.bash
Last active July 1, 2022 11:29
Installing vscode transparency/blur ubuntu 18.04
# [UPDATE]
# Its no longer complicated! Yay!
# Install Glassit Linux VSCode Extension
# then install this:
sudo apt install -y wmctrl x11-utils bash
# then restart VSCode. Done!
@emmanuelnk
emmanuelnk / terraform_install_64bit_linux.bash
Created April 10, 2019 09:20
Install Terraform on 64 bit Linux
# 0.XX.XX is the terraform version you need
wget https://releases.hashicorp.com/terraform/0.XX.XX/terraform_0.XX.XX_linux_amd64.zip -P ~/Downloads/terraform/
cd ~/Downloads/terraform && unzip terraform_0.11.8_linux_amd64.zip && cd terraform
sudo mv terraform /usr/local/bin/
nano ~/.bashrc
export PATH="$PATH:/usr/local/bin/terraform"
source ~/.bashrc
# then from anywhere
@emmanuelnk
emmanuelnk / DynamoDBClient.py
Last active June 1, 2023 02:13
Simple client wrapper library for Dynamodb access in Python (boto3)
# based off the excellent gist by Martina Pugliese
# https://gist.github.com/martinapugliese/cae86eb68f5aab59e87332725935fd5f
import boto3
from boto3.dynamodb.conditions import Key, Attr
from boto3.dynamodb.types import DYNAMODB_CONTEXT
dynamodb = boto3.resource("dynamodb")
@emmanuelnk
emmanuelnk / safePromiseAllHandler.js
Last active February 13, 2019 08:19
Handling the fast-fail behavior of Promise.all when using async/await
// TL,DR :
// here is a wrapper for PromiseAll that handles rejection and avoids fast fail behavior
const softPromiseAll = arr => {
return Promise.all(arr.map(
promise => new Promise(
resolve => promise.then(resolve).catch(resolve)
)
)).then(results => results)
}
@emmanuelnk
emmanuelnk / fizzbuzz_in_ES6.js
Last active August 1, 2019 09:46
FizzBuzz but with ES6!
const fizzbuzz = (min, max) => new Array(max-min+1)
.fill(0)
.map((f,i) => console.log(`${((i+1)%3 === 0) ? 'fizz' : ''}${((i+1)%5 === 0) ? 'buzz' : ''}` || i+1))
fizzbuzz(1, 100)
# first install npx (https://github.com/zkat/npx)
npm install -g npx
# set your npm defaults if you havent already
npm set init.author.name "Your name"
npm set init.author.email "your@email.com"
npm set init.author.url "https://your-url.com"
npm set init.license "MIT"
@emmanuelnk
emmanuelnk / download_file_from_ftp_progress_bar.py
Created August 30, 2018 02:31
Download file from FTP Server, upload file to S3 with Progress Bar in Python
import progressbar
from hurry.filesize import size
filesize = ftp.size(file)
try:
down_progress = progressbar.AnimatedProgressBar(end=filesize, width=50)
with open(TEMP_DIR + file, 'wb') as f:
def download_progress(chunk):
f.write(chunk)
down_progress + len(chunk)