Skip to content

Instantly share code, notes, and snippets.

Avatar

Rodrigo Proença rproenca

  • FWW
  • Brazil
View GitHub Profile
@rproenca
rproenca / smartsheet_column_mapper.js
Last active March 24, 2021 17:35
An ad hoc solution for mapping smartsheet columns ids to columns titles and vice-versa given an arbitraty object as input
View smartsheet_column_mapper.js
/*
Usage
-----
$ npm init
$ npm install axios
Replace variables "token", "smartsheetId" and "payload"
$ node smartsheet_column_mapper.js
View gist:917652a3de0a3b247cfaa9949b09eb3e
### Keybase proof
I hereby claim:
* I am rproenca on github.
* I am proenr (https://keybase.io/proenr) on keybase.
* I have a public key ASDlJxkD5QtJUszTbPVNFaCwDhaqM4_uqUo6VJNpJAkSPAo
To claim this, I am signing this object:
@rproenca
rproenca / gen_random_string.js
Created November 10, 2020 12:22
Generate a random string (letters and numbers) of a given length
View gen_random_string.js
const getRandomString = length => {
let s = '';
do {
s += Math.random()
.toString(36)
.substring(2);
} while (s.length < length);
s = s.substr(0, length);
@rproenca
rproenca / gist:bfa316618823ff01c39a5643f90637a7
Created November 6, 2020 17:09
Transform an arbitrary JSON array into CSV
View gist:bfa316618823ff01c39a5643f90637a7
cat input.json | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' > output.csv
@rproenca
rproenca / update_vault.sh
Last active October 13, 2020 20:12
A bash script that updates Azure Vault network ACLs given list of CIDRs addresses
View update_vault.sh
#!/bin/bash
# This script updates Azure Vault network ACLs given list of IP Addresses in CIDR format
VAULT_NAME=$1; # Vault name
INPUT_FILENAME=cidr_list.txt
if [ -z $VAULT_NAME ]
then
printf "Incorrect usage. Please use: ./update.sh [vault_name]\n";
@rproenca
rproenca / gen_cidr_list.sh
Created October 13, 2020 20:01
A bash script that generates a list of CIDRs given a Azure IP Ranges JSON file
View gen_cidr_list.sh
#!/bin/bash
# Generates a list of CIDRs given an Azure IP Ranges JSON file
# https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519
INPUT_FILENAME=$1; # Name of the JSON file downloaded from MS website (ServiceTags_Public_YYYYMMDD.json)
OUTPUT_FILENAME=cidr_list.txt
if [ -z $INPUT_FILENAME ]
then
@rproenca
rproenca / dynamodb_batch_delete.js
Last active May 1, 2023 14:51
Delete multiple items in a DynamoDB table
View dynamodb_batch_delete.js
const AWS = require('aws-sdk');
const {parallelScan} = require('@shelf/dynamodb-parallel-scan');
const TABLE_NAME = '[table-name]';
const PRIMARY_PARTITION_KEY = '[partition-key]';
async function fetchAll() {
const CONCURRENCY = 250;
const alias = `#${PRIMARY_PARTITION_KEY}`;
const name = PRIMARY_PARTITION_KEY;
View p-pipe.js
const fetch = require('node-fetch')
const pipe = require('p-pipe')
const { table } = require('table')
async function fetchDogs(dogs) {
const promises = dogs.map(async function (dog) {
const response = await fetch(`https://dog.ceo/api/breed/${dog}/images/random/1`)
const data = await response.json()
return {
[dog]: data.message
@rproenca
rproenca / sequential_parallel_promises.js
Last active June 27, 2019 14:40
Javascript sequential vs parallel promise execution
View sequential_parallel_promises.js
const fetch = require('node-fetch')
async function fetchDogsImagesSequential(dogs) {
const images = []
for (const dog of dogs) {
const response = await fetch(`https://dog.ceo/api/breed/${dog}/images/random/3`)
const data = await response.json()
images.push({
@rproenca
rproenca / Clipboard.js
Last active August 10, 2023 04:22
Copy text to clipboard using Javascript. It works on Safari (iOS) and other browsers.
View Clipboard.js
window.Clipboard = (function(window, document, navigator) {
var textArea,
copy;
function isOS() {
return navigator.userAgent.match(/ipad|iphone/i);
}
function createTextArea(text) {
textArea = document.createElement('textArea');