This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const whitespacesToCharacter = char => s => s.replace(/(^\s+)/gm, p => (new Array(p.length+1).join(char))) ; | |
const replacer = whitespacesToCharacter("<200b> "); | |
const diff = require('diff'); | |
out = diff.diffJson(one, other).map((part) => { | |
const c = part.added ? "#00FF00" : part.removed ? "#FF0000" : "#000000"; | |
return `<font color="${c}">${replacer(part.value)}</font>`; | |
} | |
).join(""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
const wait = (ms) => {const n = Date.now(); while (Date.now() - n < ms) {}} | |
const randomDelay = () => delay(Math.random() * 1000); | |
const randomWait = () => wait(Math.random() * 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://curl.se/docs/manpage.html | |
# CTRL+F -> '--write-out' to see more | |
curl -sw '%{json}' -o /dev/null "$@" | jq '{ | |
time_appconnect, | |
time_connect, | |
time_namelookup, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jq = subprocess.Popen( | |
args=['jq', '-r', args.filter], | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
) | |
stdin = json.dumps(context) | |
stdout, stderr = jq.communicate(stdin.encode()) | |
stdout, stderr = stdout.decode(), stderr.decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def deepmerge(left, right): | |
left, right = left.copy(), right.copy() | |
for k, v in left.items(): | |
if k in right and all(isinstance(e, dict) for e in (v, right[k])): | |
right[k] = deepmerge(v, right[k]) | |
left.update(right) | |
return left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read -r -d '' TF_CLI_ARGS_init << \ | |
---------------------------------------------- | |
-reconfigure | |
-otheroption | |
-etc | |
---------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# problem: write to file, don't show it on the screen | |
$ get-passwords > passwords.txt | |
# works okay | |
# problem 2: write to file with sudo, don't show it on the screen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recurset(key, val, dct, sep='/'): | |
out = dct | |
*parts, last = key.split(sep) | |
for part in parts: | |
if part not in out: | |
out[part] = {} | |
out = out[part] | |
out[last] = val | |
return dct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# all resources left in all state files | |
find . -type f | xargs cat | jq -rs '.[].resources | select(. != []) | .[].instances | .[].attributes.arn | select(. != null)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use JSON 'encode_json'; | |
my $code = `find .. -name '*.tf' -exec cat {} +`; | |
my @blocks = map { $_ =~ m/ (?^:((?:\{(?:(?>[^\{\}]+)|(?-1))*\}))) /xg } $code; | |
my @repos = grep { m| \s* source \s*=\s* ".+/modules/repository" |xg } @blocks; | |
my @names = map { $_ =~ m/ \s* name \s*=\s* "((?:[^"]+|"")*)" /xg } @repos; | |
my @unique = sort { $a cmp $b } do { my %seen; grep { !$seen{$_}++ } @names }; | |
print encode_json { data => encode_json { repos => \@unique } }; |
NewerOlder