Skip to content

Instantly share code, notes, and snippets.

@hovissimo
hovissimo / aws-creds.zsh
Last active February 5, 2024 19:33 — forked from ddgenome/aws-creds.bash
Fetch AWS STS keys and set environment variables
#!/bin/zsh
# Fetch 24-hour AWS STS session token and set appropriate environment variables.
# See http://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html .
# You must have jq installed and in your PATH https://stedolan.github.io/jq/ .
# Add this function to your .bashrc or save it to a file and source that file from .bashrc .
# Online: https://gist.github.com/hovissimo/c9119820a5a4f5a6081d93f87f1688b4
# Adapted from https://gist.github.com/ddgenome/f13f15dd01fb88538dd6fac8c7e73f8c
#
# usage: aws-creds AWS_PROFILE MFA_TOKEN [OTHER_AWS_STS_GET-SESSION-TOKEN_OPTIONS...]
# example: aws-creds staging 123456
@hovissimo
hovissimo / req
Created September 30, 2022 05:42
Enhance /foo/bar/$key.mjs
{
"version": "2.0",
"routeKey": "ANY /{proxy+}",
"rawPath": "/foo/bar/baz",
"rawQueryString": "",
"cookies": [
"_idx=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..YNN--0oPCWn6ChdD.AXLDL_cMMBOSRppGv2xjlppy1PkdESx3bb99IlEvKrhnJaI7I6VPniFArldGWRNldz_YNo_ilEHhchOwKk3et1C5Xnqjo4WplXv7ItyK6STOisdYfnMmEgGVFP0AUqTZNMDdpvC-c8mvsQvD0VUGeKd1ATNGZFbyDA._M1PRjCs26cccaRM0omyMw"
],
"headers": {
"host": "localhost:3333",
@hovissimo
hovissimo / applyMiddleware.mjs
Last active September 22, 2022 13:28
Middleware function for Enhance.dev
/**
* applyMiddleware takes an array of middleware functions and returns a decorator that will apply
* the middleware functions in reverse order around the target function.
*
* Example
*
* const handleGet = async(req) => ({ ... })
* const mw1 = (next) => async (req) => await next(req) + " mw1"
* const mw2 = (next) => async (req) => await next(req) + " mw2"
* const mw3 = (next) => async (req) => await next(req) + " mw3"
export const availableEndpoint =
(handler) => async (req) => {
let currentUser
try {
currentUser = await authorizeUser(req)
} catch (e) {
if (e instanceof UnauthorizedError) {
// pass!
} else {
throw e
@hovissimo
hovissimo / web_components_demo.js
Last active September 11, 2022 15:30
Web component default slot content
customElements.define('my-span',
class extends HTMLElement {
constructor() {
super();
// '<span><slot>default text</slot></span>'
const span = document.createElement('span')
const slot = document.createElement('slot')
slot.appendChild(document.createTextNode('default text'))
span.appendChild(slot)
@hovissimo
hovissimo / flow.json
Created September 4, 2022 18:45
Node-RED simple modulo router
[
{
"id": "211d2ade5b37281c",
"type": "function",
"z": "0d3a28192a31e0f9",
"name": "mod router",
"func": "const count = context.get('count') ?? 0;\n\nif (count < 5) {\n context.set('count', count + 1);\n return [msg, undefined];\n} else {\n context.set('count', 0);\n return [undefined, msg];\n}",
"outputs": 2,
"noerr": 0,
"initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.set('count', 0)",
#!/bin/zsh
# Redirect output to stderr.
exec 1>&2
# join_by from https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
# pattern is just all of these strings smushed into a big regex pattern
booboos=(
class Truck:
def __init__(self, num_wheels, max_load_per_wheel):
self.num_wheels = num_wheels
self.max_load_per_wheel = max_load_per_wheel
self.cargo = []
def max_load(self):
return self.max_load_per_wheel * self.num_wheels
def describe_cargo(self):
0eNqtXNtu20gM/ZWFnq2FOHflsb+xKBZOrA2EtWVBkosGhf99ZQerpImV4SH91Lq2ecgzh5yhzOmv4nF/avqh7abi4Vcxdtu+nI7l89DuLq9/Fg+h2hQvxUM6b4r26diNxcNf8+fa5267v3xieumb4qFop+ZQbIpue7i8emy280eLy1e6XTMbofMm+6Vm3zxNQ/tU/nMauu1T8+7rhvP1n/3QjGM5Ddtu7I/DVD42++mdEcswcmh27elQLq70x/17P9z5+6Zouqmd2uaViOuLl7+70+GxGeY4v7a0KfrjOH955uaV3NL4P/2V33L+y/ni4QeLZrE4Hrb7fbnfHvpbdlzGjkU9ozpj0fE8o5Sx42HPbMZiYHpmMnYi6lnMGEw8x0LGTA0zljFIFc+xKmcH1X9OtcSTfy6JCFU/ZSPlqZ+yzKPqp5w4iKd+ymmVUPWbXDoRT/4ml95Uf9xobtTDJbzZq0sBn8v8eN3h+qbZlYfj7rRvSnvZWm4V3YqB4FQIxEAgFYLJI7zVZhGCZSB4FYJjIBgVgs8j1CqAkAcIKoCYB7AqgJQHqFQA+XxWrbHNZ7NKpTafy6o8s/lMJlWpsPlEJlW1s/k8JlXBtvk0NiqN2nwaG1WW2XwaG1WdsO9232n79G/ZdmMzTPNbX+081RVp1w7z1n/9gLllugZM/5/Knyy7Wz1G9am/O82t2PA8HOc/Xzu8LzBuuL9ZGr+uP13aw8+YtN6SftEmVb+vST/MyzGD/phN55bGGT5/S57w+LMS/t5y8Qv+jqdpjUAHhOMhpTkviieo9BAgPdg76CGKoiTdqgH1YYHiiRAoDzUkBy8qD2/NnUQOHioPUa8GD1QHj6yLFxUHr1KZB2qDxbQgKg12jTCOEkLu4eNnPLeKdwsgygFKngQSVNvuIGZ+LagQLYcKpqqC5BVIIC/SFJrAz3uDhSLJe6NIlOAU3InKTPCArp1e1iGw1ypAspacBIKqQgf+OSBhsqsFsURNBkXJ8SAphB5JEaJotaIBhE6
#! /bin/zsh
fancy_git_pickaxe() {
# -S$1 -- pickaxe the first argument to the function
# "${@:2}" -- pass the remaining arguments along
git log -S$1 "${@:2}" \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" \
--color=always |
# from https://gist.github.com/junegunn/f4fca918e937e6bf5bad
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \