Skip to content

Instantly share code, notes, and snippets.

@fbatroni
fbatroni / async.js
Created July 31, 2020 00:59 — forked from bschwartz757/async.js
Async/await function to fetch data from multiple URLs in parallel
/* Client side, works in Chrome 55 and Firefox 52 without transpilation */
//https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/
async function fetchURLs() {
try {
// Promise.all() lets us coalesce multiple promises into a single super-promise
var data = await Promise.all([
/* Alternatively store each in an array */
// var [x, y, z] = await Promise.all([
// parse results as json; fetch data response has several reader methods available:
//.arrayBuffer()
@fbatroni
fbatroni / openvpn_on_google_cloud.md
Created December 21, 2020 20:17 — forked from neuni/openvpn_on_google_cloud.md
Create a openVPN server on Google Cloud Platform to connect to your Google Cloud network using openVPN and/or to route your internet traffic through the VPN (Road Warrior Scenario)

Install openVPN server on Google Cloud using Pritunl

Purpose:

Create a openVPN server on Google Cloud Platform to connect to your Google Cloud network using openVPN and/or to route your internet traffic through the VPN (Road Warrior Scenario)

Create instance

  • Create new instance in default network
  • Chosse Ubuntu 16.04 LTS
@fbatroni
fbatroni / npm-scripts-for-docker.md
Created March 4, 2021 01:01 — forked from duluca/npm-scripts-for-docker.md
npm scripts for Docker

These are generic npm scripts that you can copy & paste into your package.json file as-is and get access to convinience scripts to manage your Docker images all in one place.

How to Use

npm i -g mrm-task-npm-docker
npx mrm npm-docker

Contribute

Here's the code repository https://github.com/expertly-simple/mrm-task-npm-docker

anchors:
tf_init: &tf_init |
terraform init -lock=false \
-backend-config="resource_group_name=terraform" \
-backend-config="key=${{ env.TF_BACKEND_KEY }}" \
-backend-config="access_key=${{ secrets.TF_BACKEND_ACCESS_KEY }}" \
-backend-config="storage_account_name=${{ secrets.TF_BACKEND_SA }}"
setup_backend_key: &setup_backend_key "githubdeployment.${{ github.event.inputs.environment }}.aks_setup.terraform.tfstate"
configure_backend_key: &configure_backend_key "githubdeployment.${{ github.event.inputs.environment }}.aks_configure.terraform.tfstate"
@fbatroni
fbatroni / .bash
Created October 14, 2021 22:05 — forked from devonhk/.bash
detect changed files in mono repo
CHANGED_FOLDERS=$(git diff --name-status $TRAVIS_COMMIT_RANGE -- | awk 'BEGIN {FS="/"} {print $1}' | awk '{print $2}' | uniq)
@fbatroni
fbatroni / gist:aa6b1db71aa83b8f079592b6954ede63
Created November 22, 2021 16:05 — forked from mbains/gist:3406184
Factory pattern using C++ templates
#include <iostream>
#include <map>
using namespace std;
class BaseClass{
public:
virtual int funk() {
return 0;
}
@fbatroni
fbatroni / DeadLetterQueueStack.ts
Created July 6, 2022 17:01 — forked from brianfoody/DeadLetterQueueStack.ts
Dead Letter Queue example with CDK
import { Queue } from "@aws-cdk/aws-sqs";
import { App, Duration, Stack, StackProps } from "@aws-cdk/core";
import { Runtime, Code, Function } from "@aws-cdk/aws-lambda";
import { SqsEventSource } from "@aws-cdk/aws-lambda-event-sources";
class DeadLetterQueue extends Stack {
constructor(parent: App, name: string, props?: StackProps) {
super(parent, name, props);
@fbatroni
fbatroni / mock_imports.py
Created November 8, 2022 10:12 — forked from dangunter/mock_imports.py
For testing, use the mock module to wrap non-importable code. Also provide hooks for putting back in real functions/classes where needed.
import importlib
from mock import MagicMock, patch
def example():
with patch_modules():
import something.not.importable
print("yay! it worked!")
def patch_modules():
sm = mock_import('not.importable', 'something')

How To Install OpenSSL 1.1.1 on CentOS 7

This tutorial goes through how to install openssl 1.1.1 on CentOS 7, since the yum repo only installs up to openssl 1.0.

Requirements

Upgrade the system

yum -y update
@fbatroni
fbatroni / README.md
Created May 8, 2023 16:24 — forked from rainabba/README.md
Bash retry with exponential backoff

A 1-liner bash function to provide basic non-zero exit retry with exponential backoff:

Minified

function retry_backoff {local m=${ATTEMPTS:-5};local t=${TIMEOUT:-1};local a=0;local e=1;while (($a < $m));do "$@";e=$?;if (($e == 0)); then break;fi;echo "Failure! Retrying in $t.." 1>&2;sleep $t;((a++));t=$((t*2));done;if (($e != 0));then echo "Max attempts reached!" 1>&2;fi;return $e; }

Use

retry_backoff $YOUR_COMMAND # default of 5 retries, starting with 1 second timeout