Skip to content

Instantly share code, notes, and snippets.

@therightstuff
therightstuff / RSA.cs
Last active January 31, 2024 15:13
Simple RSA Encryption, Decryption, signing and signature verification using Base64 encoded strings in C#
using System;
using System.Security.Cryptography;
using System.Text;
namespace MyProject.Data.Encryption
{
/* Encryption, decryption, signing and signature verification that's compatible with
* simple-free-encryption-tool
*/
public class RSA
@therightstuff
therightstuff / _end-to-end-enc.js.md
Last active December 19, 2023 02:17
Javascript / Node.js end-to-end encryption
@therightstuff
therightstuff / RSAKeys.cs
Last active November 3, 2023 16:34
Import and export RSA Keys between C# and PEM format using BouncyCastle
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;
using System;
using System.IO;
using System.Security.Cryptography;
namespace MyProject.Data.Encryption
{
@therightstuff
therightstuff / build-layers.js
Created August 30, 2023 22:46
Node/Python Lambda layer build script
"use strict"
// build-layers copies layers/src folder contents into layer/build, then runs
// the npm install and prune commands
const fs = require("fs");
const fse = require("fs-extra");
const path = require("path");
const spawn = require("child_process");
const { checksumDirectory } = require("simple-recursive-checksum");
@therightstuff
therightstuff / parallel_test.sh
Last active July 28, 2023 00:29
Sample bash script for managing multiple parallel processes
#!/usr/bin/env bash
# inspired by https://stackoverflow.com/a/29535256/2860309
pids=""
failures=0
function my_process() {
seconds_to_sleep=$1
exit_code=$2
// calculate md5 hash for entire src directory
// according to https://unix.stackexchange.com/a/35834/305967
console.log(`calculating md5 hash for ${layer}...`);
let hash = process.execSync(`tar -cf - ${layerSrcPath} | md5sum | cut -d ' ' -f 1`, { encoding: 'utf8' }).trim();
@therightstuff
therightstuff / requests_mocking.py
Last active May 31, 2023 08:34
Simple request mocking with requests_mock
def setup_mocker(mocker, expected_requests):
"""Note: this requires the exact number of expected requests.
expected_requests is an array in the following format:
[
{
"url": "https://www.example.com",
"method": "GET",
"exc": requests.exceptions.ConnectTimeout, # will override "status_code" and "json"
"status_code": 404, # defaults to 200
@therightstuff
therightstuff / README.md
Created April 28, 2023 09:25
AWS Breaking (Change) News: New S3 Buckets Blocked For Public Access

See the Medium article for more details.

In a nutshell: AWS has recently rolled out a change wherein S3 buckets cannot be created with public access.

These Serverless snippets are for use in the article, with the final.form.yaml being the one that worked for us, but mileage may vary and some people (and parts of our own solution) needed different options.

@therightstuff
therightstuff / README.md
Last active March 5, 2023 22:15
Connecting a domain to a static-hosted S3 website with CDK 2
@therightstuff
therightstuff / is_between.sh
Last active January 23, 2023 06:11
A shell script to test whether the current time is between two given times
#!/usr/bin/env sh
# A script that receives start and end parameters in the format HH:mm and
# exit with an error code if the current time is not within the desired
# window.
# The given times are not inclusive, so if you want 06:00-10:00 inclusive
# you need to specify 05:59 and 10:01 respectively.
# This script assumes that we are interested in time periods shorter than
# a single day, and it handles overnight periods.
# Inspired by https://unix.stackexchange.com/a/395936/305967