Skip to content

Instantly share code, notes, and snippets.

View SafeEval's full-sized avatar

Jack Sullivan SafeEval

View GitHub Profile
@SafeEval
SafeEval / agent.py
Created March 31, 2025 02:38
Hello DSPy — A simple "hello world" style DSPy script
import dspy
from typing import Dict
class PortlandOracle(dspy.Signature):
"""Answer questions about Portland restaurants."""
question: str = dspy.InputField()
answer: str = dspy.OutputField()
def forward(self, question):
@SafeEval
SafeEval / scrypt-example.ts
Last active February 6, 2025 23:26
Example of using Scrypt hashing in TypeScript.
import { randomBytes as csprngRandomBytes, scrypt, timingSafeEqual } from 'crypto';
import { promisify } from 'util';
const scryptAsync = promisify(scrypt);
/**
* Hashes a string using the scrypt algorithm.
*
* @param value - The value to hash.
* @returns A promise that resolves to the hashed value in the format `base64(salt):base64(derivedKey)`.
@SafeEval
SafeEval / argon2-demo.ts
Last active February 6, 2025 06:02
TypeScript demo of argon2 for string hashing and verification
import { hash, verify, Options, Algorithm } from '@node-rs/argon2';
/**
* Hashes a string using the Argon2id algorithm.
* Argon2 is a memory-hard function that requires a large amount of memory to compute.
* The 'id' variant mixes resistance against both GPU cracking and side-channel attacks.
* A generated salt value adds resistance against pre-computed rainbow table attacks.
* The configuration options are included in argon2 hashes to simplify verification.
*
* @param value - The value to hash.
@SafeEval
SafeEval / gen-otp-sha256.sh
Last active September 20, 2024 02:07
Generate the sha256 hashes of all six digit OTPs in 970 seconds (16 minutes, 69 MB)
#!/bin/bash
OUTFILE="otp-hashes.csv"
function gen_hash() {
otp=$1;
hash=$(echo -n $otp | sha256sum | awk '{print $1}');
echo "$otp,$hash" >> $OUTFILE;
}
@SafeEval
SafeEval / get-tfc-profile
Created August 27, 2024 20:49
Show the HCP Terraform (Terraform Cloud) profile information for a user with a given token
#!/bin/bash
curl \
--header "Authorization: Bearer $TFC_TOKEN" \
--header "Content-Type: application/vnd.api+json" \
"https://app.terraform.io/api/v2/account/details"
@SafeEval
SafeEval / update-tfc-workspace-vcs-config.sh
Created August 14, 2024 04:02
Update a set of TFC workspace VCS configs to use a Github App
#!/bin/bash
# Connect a TFC workspace to a Github VCS provider using the TFC API.
INFILE_WORKSPACES="tfc-workspace-name-list.txt"
function check_env() {
var_name="$1"
var_value="$2"
@SafeEval
SafeEval / tfc-workspace-vcs-config.sh
Created August 14, 2024 00:48
List out the VCS configs for all TFC workspaces in the organization
#!/bin/bash
# Script to pull details on all TFC workspaces and then focus on VCS configs.
# Note: jq is used to parse JSON, you need to install it if not already available
# Variables - Replace with your actual values
if [ -z $TFC_API_TOKEN ]; then
echo "Missing TFC_API_TOKEN environment variable";
exit 1;
fi
@SafeEval
SafeEval / list-rds-force-ssl.sh
Created August 12, 2024 16:25
List `rds.force_ssl` RDS DB Parameter Group values for all DBs in the account. Dump results to CSV.
#!/bin/bash
# List `rds.force_ssl` RDS DB Parameter Group values for all DBs in the account.
# Dump the results to CSV.
OUTFILE="rds-force-ssl.$(date +%s).csv"
# Get all RDS parameter group names
parameter_groups=$(aws rds describe-db-parameter-groups --query "DBParameterGroups[].DBParameterGroupName" --output text)
@SafeEval
SafeEval / age-example.sh
Created August 7, 2024 17:14
Using the 'age' file encryption tool to securely exchange a large sensitive file between two parties over a hostile network.
#!/bin/bash
# Example of using the 'age' file encryption tool to securely exchange
# a large sensitive file between two parties over a hostile network.
# https://age-encryption.org/
# https://github.com/FiloSottile/age
# https://htmlpreview.github.io/?https://github.com/FiloSottile/age/blob/main/doc/age.1.html
###############################################################
@SafeEval
SafeEval / gh-app-auth.sh
Last active July 30, 2024 18:53
Get a Github access token as a Github App in pure bash
#!/usr/bin/env bash
# Get a Github access token as a Github App in pure bash.
# 1. Generate a JWT (CLIENT_ID and PEM)
# 2. Obtain the access token (JWT and INSTALLATION_ID)
#
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app#example-using-bash-to-generate-a-jwt
set -o pipefail