Skip to content

Instantly share code, notes, and snippets.

@keksipurkki
keksipurkki / getenv.sh
Created March 15, 2022 08:57
SSM parameters to .env file
#!/bin/sh
set -e
function usage()
{
echo "Usage: $(basename $0) PATH"
}
function to_env()
@keksipurkki
keksipurkki / binary_strings.js
Created March 12, 2022 06:08
All binary srings of given length
#!/usr/bin/env node
function memoize(fn) {
const cache = {};
return (...args) => {
const key = JSON.stringify(args);
cache[key] = cache[key] || fn(...args);
return cache[key];
};
}
@keksipurkki
keksipurkki / parse-junit
Created November 26, 2021 10:01
Parse Junit.xml with JS
#!/usr/bin/env node
const Parser = require("junitxml-to-javascript");
function countErrors(testsuites) {
let errors = 0;
for (const testsuite of testsuites) {
errors += testsuite.errors;
}
return errors;
#!/usr/bin/env jq -f
# Flatten ./flatten.jq [FILE...]
# Unflatten: ./flatten.jq [FILE...] --args unflatten
def json_flatten:
[ paths(scalars) as $path | { Key: $path | join("/"), Value: getpath($path) } ]
;
def json_unflatten:
#!/usr/bin/env jq -rf
# input is assumed to be an array of JSON entries [{"Key": ..., "Value": ... }, ...]
.[]
| [.Key,.Value]
| @tsv
# Decode AWS parameter store configuration
get_parameters_by_path() {
local prefix=$1
shift
local starting_token="$*"
json=$(
aws ssm get-parameters-by-path \
--path $prefix \
--max-items 30 \
@keksipurkki
keksipurkki / x509.js
Last active January 16, 2021 09:48
NodeJS + X509
const crypto = require("crypto");
const assert = require("assert");
const tls = require("tls");
function getCertificate(url) {
if (url.protocol !== "https:") {
throw new TypeError("Expected an HTTPS URL");
}
return new Promise((resolve, reject) => {
interface Result<S> {
failure?: Error;
success?: S;
}
class Failure implements Result<never> {
failure: Error;
constructor(failure: string | Error) {
if (failure instanceof Error) {
this.failure = failure;
@keksipurkki
keksipurkki / nuclear.sql
Last active January 17, 2020 11:03
PostgreSQL — Nuke the public schema
-- You sane bro?
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
COMMENT ON SCHEMA public IS 'standard public schema';
@keksipurkki
keksipurkki / flags.js
Last active January 16, 2023 16:50
ISO-3166 Country code to flag emoji
#!/usr/bin/env node
const [NODE_MAJOR_VERSION] = process.versions.node.split('.');
const assert = require('assert');
assert(NODE_MAJOR_VERSION >= 18, 'NodeJs 18 or greater is required');
function countryEmoji(code) {
const offset = 0x1f1a5;
return code
.toUpperCase()