Skip to content

Instantly share code, notes, and snippets.

@andrewthauer
andrewthauer / progress.ts
Last active May 27, 2023 13:31
Deno Progress Bar
import { tty } from "https://deno.land/x/cliffy@v0.25.7/ansi/tty.ts";
interface ProgressBarOptions {
label?: string;
total?: number;
width?: number;
}
/**
* A simple progress bar for Deno
@andrewthauer
andrewthauer / jq-key-map.sh
Created August 22, 2020 21:05
jq-examples
#!/usr/bin/env bash
#
# Adapted as a fix for https://github.com/spotify/backstage/blob/master/docker/run.sh
#
# Call with
local key_map='{ "BACKEND_BASEURL": "backend_baseUrl" }'
config="$(jq --arg keyMap "$key_map" -n 'env |
def swap_key($k): $keyMap | fromjson | if has($k) then with_entries(select(.key == $k)) | .[] else $k end;
@andrewthauer
andrewthauer / asdf-alias
Created January 3, 2020 15:19
asdf-alias
#!/usr/bin/env bash
#
# description:
# Symlink a short name to an exact version
#
# usage:
# asdf-alias <plugin> <name> [<version> | --auto | --remove]"
# asdf-alias <plugin> --auto"
# asdf-alias <plugin> [--list]"
#
@andrewthauer
andrewthauer / ga-nginx-template
Created June 16, 2019 15:53
Inject Google Analytics Tracker with Nginx
server {
# ...
set $tracking_id 'UA-#########';
sub_filter "</head>" "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create', '$tracking_id', 'auto');ga('send', 'pageview');</script></head>";
}
// lodash - reduceAll/Assign (using fp/over)
const fp = require("lodash@4.16.6/fp");
let data = [{valA: 1, valB: 2}, {valA: 2, valB: 3}];
const reduce1 = fp.sumBy('valA');
const reduce2 = fp.sumBy('valB');
const reducers = [reduce1, reduce2];
const reducedKeys = ['sumA', 'sumB'];
const R = require('ramda'),
prop = R.prop,
path = R.path,
curry = R.curry;
// Test Data
let user1 = {
id: 1,
login: 'andrew',
details: {
import * as Rx from 'rxjs';
import { setInterval } from 'timers';
const mockInterval = Rx.Observable.create(obs => {
let i = 0;
setInterval(function() {
i = i + 1;
obs.next(i);
}, 500);
});
@andrewthauer
andrewthauer / replace-values.js
Created April 28, 2018 15:32
Node Script - Replace Values in File
#!/usr/bin/env node
/* eslint-env node */
/* eslint-disable no-console */
const path = require('path');
const replace = require('replace');
const argv = require('yargs').argv;
const targetPath = path.join(__dirname, '../dist/');
@andrewthauer
andrewthauer / Replace-Vars.ps1
Last active March 22, 2021 06:28
PowerShell Script - Update Env Variables in Files
# Replace-Vars script
#
# Description:
# Replaces varibles in the specified files
#
# Usage:
# Replace-Vars.ps1 [files_to_update_array] [config_vars_hash]
#
# Examples:
# ./Replace-Vars.ps1 ./file1.txt @{ API_URL = 'MY_VAR' }
@andrewthauer
andrewthauer / PushTo-S3.ps1
Created April 28, 2018 15:29
Copy Files to S3
# PushTo-S3 script
#
# Description:
# Copies the source files to an S3 bucket
#
# Usage:
# PushTo-S3 -SourcePath [Path] -AwsAccessKey [KEY] -AwsSecretKey [SECRET] -AwsRegion [REGION] -S3BucketName [BUCKET]
#
# Example:
# ./PushTo-S3 -SourcePath "./dist" -AwsAccessKey "KEY" -AwsSecretKey "SECRET" -AwsRegion "REGION" -S3BucketName "BUCKET"