Skip to content

Instantly share code, notes, and snippets.

@trmaphi
trmaphi / vpn-compare.md
Created July 13, 2023 04:47
VPN compare for self-managed multi k8s cluster support service mesh
VPN IPsec OpenVPN WireGuard
Layer 3 4 4
Protocol IP UDP/IP UDP/IP
Topology site2site subnet, net30, p2p mesh
Multi cluster kubernetes Yes Not Found Yes
Self managed mulicluser No No Yes
Implementation (1) NotFound (2)

References:

@trmaphi
trmaphi / GNUPG_agent_forwarding.md
Created November 15, 2022 17:58 — forked from TimJDFletcher/GNUPG_agent_forwarding.md
GnuPG agent forwarding

Forward GnuPG agent from macOS to Linux

On the remote machine

Run gpg once as your to create the directory structure

gpg --list-keys

For headless systemd based hosts

@trmaphi
trmaphi / graphql-apollo-xray-error-formatter.js
Created January 4, 2021 04:28 — forked from mdlavin/graphql-apollo-xray-error-formatter.js
An Apollo Server formatError function that avoids "Converting circular structure to JSON" errors
// This is the attribute that continuation local storage uses to hold onto
// the current context. The value comes from https://github.com/othiym23/node-continuation-local-storage/blob/fc770288979f6050e4371c1e1b44d2b76b233664/context.js#L11
const CLS_CONTEXT_ATTRIBUTE = 'error@context';
// A formatError function that can be used with
// https://www.apollographql.com/docs/apollo-server/features/errors#for-the-client-response
function formatError (err) {
// The continuation-local-storage module attaches a context attribute to
// errors so that the context can be resolved from errors. The attribute
// is enumerable by default and so it gets included in GraphQL error
@trmaphi
trmaphi / tracing.ts
Last active January 7, 2021 03:53
Setup X-ray on Lambda
/// Setup tracing in a separate file
import * as AWSXRay from 'aws-xray-sdk-core';
// Configure the context missing strategy to do nothing
// https://docs.aws.amazon.com/lambda/latest/dg/nodejs-tracing.html
AWSXRay.setContextMissingStrategy(() => { });
// https://github.com/aws/aws-xray-sdk-node/issues/143
AWSXRay.captureAWS(require('aws-sdk'));
@trmaphi
trmaphi / x-ray-graphql.ts
Last active January 4, 2021 04:28
Tracing GraphQL resolvers with X-Ray
import traceResolvers from '@lifeomic/graphql-resolvers-xray-tracing';
// Apply tracing middleware if running Lambda environment
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
traceResolvers(schema);
}
const apolloServer = new ApolloServer({
schema,
context: contextFn,
@trmaphi
trmaphi / noti.sh
Created March 12, 2020 12:15
Notify slack incoming webhooks about current deployment
#!/usr/bin/env bash
TARGET=$(git describe --dirty --broken --all --long);
PROJECT=$(git config remote.origin.url |sed 's#.*\/\(.*\)\.git#\1#');
git pull && \
curl -i \
-H "Content-Type:application/json" \
-X POST \
-d "{\"text\": \"deployed \`${PROJECT}\` \`$TARGET\` to \`$1\` \"}" \
var AWS = require('aws-sdk');
var region = ''; // e.g. us-west-1
var domain = ''; // e.g. search-domain.region.es.amazonaws.com
var index = 'node-test';
var type = '_doc';
var id = '1';
var json = {
"title": "Moneyball",
"director": "Bennett Miller",
@trmaphi
trmaphi / getProps.js
Created August 19, 2019 07:34
Safely get a nested property of an object in Javascript
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
@trmaphi
trmaphi / changeJDK.bash
Last active April 5, 2024 04:06
[Change system wide java version on Mac OS] Inspire by a stackoverflow answer https://stackoverflow.com/a/44169445/6730571 #bash #mac
#!/usr/bin/env bash
JDKS_DIR="/Library/Java/JavaVirtualMachines"
JDKS=( $(ls ${JDKS_DIR}) )
JDKS_STATES=()
# Map state of JDK
for (( i = 0; i < ${#JDKS[@]}; i++ )); do
if [[ -f "${JDKS_DIR}/${JDKS[$i]}/Contents/Info.plist" ]]; then
JDKS_STATES[${i}]=enable