Skip to content

Instantly share code, notes, and snippets.

View aksel's full-sized avatar
🤠
Howdy

aksel

🤠
Howdy
View GitHub Profile
@aksel
aksel / rds_auth.sh
Created April 22, 2024 11:04
Bash port of aws rds generate-db-auth-token
#!/bin/bash
##########################################
# Bash port of aws rds generate-db-auth-token
#
# Required environment variables:
# AWS Credentials (AWS_ACCESS_KEY_ID; AWS_SECRET_ACCESS_KEY; AWS_SESSION_TOKEN)
# PGUSER: Database user name.
# PGHOST: Database host.
# PGDATABASE: Database name.
@aksel
aksel / aws-cli-authenticate-mfa.sh
Created February 12, 2021 11:49
Script for authenticating using MFA for the AWS CLI. Variables are exported, so the script can be sourced.
#!/bin/bash
MFA_DEVICE=$1
if [ -z "$MFA_DEVICE" ]; then
echo "MFA device ARN not specified." >&2
exit 1
fi
# Prompt for OTP
OTP=
@aksel
aksel / createToken.js
Created July 1, 2020 09:07
Generating JWT.
const jwt = require('jsonwebtoken');
const fs = require('fs');
// Get jwt.dev.key from AWS Secrets Manager.
const privateKey = fs.readFileSync('jwt.dev.key');
const payload = {
user: {
// Must correspond with the ID of a user, in whichever database your connecting to.
// Otherwise, inserts will fail, due to FK constraints.
@aksel
aksel / SamPlugin.js
Created January 23, 2020 14:15
A very barebones Webpack plugin, that builds Node functions, and recursively traverses nested stacks.
const fs = require('fs');
const { yamlParse } = require('yaml-cfn');
const merge = require('lodash/merge');
const resourceReducer = (acc, [key, value]) => {
switch (value.Type) {
case 'AWS::Serverless::Application':
return merge(acc, { applications: { [key]: value } });
case 'AWS::Serverless::Function':
return merge(acc, { functions: { [key]: value } });
@aksel
aksel / routes.js
Created December 1, 2017 09:20
Util function that recursively traverses routes, finding the component of a route.
const SomeComponent = () => <span>Hello world</span>
export default [
{
path: '/',
name: 'main',
component: SomeComponent,
},
{
path: '/parent',
name: 'parent',
@aksel
aksel / middlewares.js
Last active June 28, 2019 21:45
Route HTTP status code middleware for router5
import { startsWithSegment } from 'router5-helpers';
import { transitionPath } from 'router5';
// Reduces the activated routes, so the last status is used, defaulting to 200
// Reducingg instead of finding, assures that child routes determine the status codes, even when a parent has a different one.
export const statusCodeDecorator = routes => () => (toState, fromState) => {
const status = getActivatedRoutes(routes, toState, fromState).reduce((s, route) => route.status || s, 200);
return Promise.resolve({ ...toState, status });
};
@aksel
aksel / encryption.js
Last active March 19, 2018 19:50 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const KEY_LENGTH = 32; // Must be 32 bytes
const IV_LENGTH = 16; // For AES, this is always 16
// Creates 32 byte key (for AES-256), buffer
const createKey = () => crypto.randomBytes(KEY_LENGTH);
@aksel
aksel / Kotlin Socket.IO example
Last active February 12, 2021 11:35
Kotlin Socket.IO example connection function.
import io.socket.client.IO
import io.socket.client.Socket
fun connect() {
val socket = IO.socket("http://localhost:4000?user=aksel")
socket.connect()
.on(Socket.EVENT_CONNECT, { println("connected") })
.on(Socket.EVENT_DISCONNECT, { println("disconnected") })
}