Skip to content

Instantly share code, notes, and snippets.

View lox's full-sized avatar

Lachlan Donald lox

View GitHub Profile
@lox
lox / groq-whisper.py
Created May 3, 2024 02:12
Experimental client to test Whisper on GroqCloud
import os
import argparse
import requests
from datetime import datetime
# Define the parser for command line arguments
parser = argparse.ArgumentParser(description='Groq Whisper transcribe')
parser.add_argument('file', type=str, help='Audio file to transcribe')
parser.add_argument('--output_file', type=str, help='File to write output', default="transcription.txt")
args = parser.parse_args()
@lox
lox / Setup.md
Last active March 27, 2024 01:35
Setup Ubuntu 22.04 for Deep Learning
# Check for Nvidia Hardware
lspci | grep -i nvidia

# Update
apt update
apt upgrade

# Install Nvidia drivers
apt install nvidia-driver-535 nvtop
@lox
lox / mirror_test.sh
Last active November 7, 2023 17:33
A bash script to select the fastest ubuntu apt geo-mirror
#!/bin/bash -e
# mirror_test.sh
# benchmarks closest ubuntu mirrors and outputs them in speed order
# bash -c "$(curl -fsSL https://gist.githubusercontent.com/lox/9152137/raw/mirror_test.sh)"
RELEASE=$(lsb_release -c -s 2>/dev/null || echo 14.04)
MIRRORS=$(curl -s http://mirrors.ubuntu.com/mirrors.txt)
TESTFILE="dists/$RELEASE/main/binary-amd64/Packages.bz2"
TIMEOUT=1
@lox
lox / main.tf
Last active September 14, 2023 11:28
Drata Integration for GCP in Terraform
# https://help.drata.com/en/articles/4994112-gcp-connection-details
# Create a new project for Drata Integration
resource "google_project" "drata" {
name = var.project_name
project_id = var.project_id
org_id = var.org_id
billing_account = var.billing_account_id
auto_create_network = false
}
@lox
lox / intercept.js
Created September 10, 2023 04:42
Example of using mswjs interceptors
import { BatchInterceptor } from '@mswjs/interceptors'
import { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'
import { FetchInterceptor } from '@mswjs/interceptors/fetch'
import http from 'http'
const interceptor = new BatchInterceptor({
name: 'my-interceptor',
interceptors: [new ClientRequestInterceptor(), new FetchInterceptor()],
})
@lox
lox / main.tf
Last active September 5, 2023 23:45
Terraform for setting up Identity Federation with GCP for Namespace workloads
// See https://cloud.namespace.so/docs/federation/gcp
locals {
roles = [
"roles/resourcemanager.projectIamAdmin", # allow managing identity
"roles/editor", # allow to manage all resources
"roles/iam.serviceAccountAdmin", # allow to manage service accounts
]
}
@lox
lox / Worker.js
Last active August 31, 2023 09:58
Cloudflare worker for rewriting a custom domain to work with Firebase SDK
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
/**
* Intercept requests and redirect to Firestore API
* @param {Request} request
*/
async function handleRequest(request) {
const url = new URL(request.url)
@lox
lox / README.md
Last active August 2, 2023 16:48
Grout - A golang based routing front proxy

Grout

Grout is an HTTP-based front proxy that delegates portions of a url path space to other web applications. This allows for a web application to be composed of a collection of micro-services.

Beyond routing based on url, language or ip-based region, Grout provides downstream services with a unique per-request X-Grout-Id and a per-session X-Grout-Session header for simple cross-service sessions.

Motivation

Presently 99designs.com is composed of 2-3 different web applications. Varnish sits in front of these web applications and dispatches requests to the appropriate backend based on some complicated regular expressions and a large chunk of complicated VCL.

@lox
lox / stream-to-cw-logs
Created May 24, 2023 02:35
Stream stdin to cloudwatch logs
#!/bin/bash
# Enable bash strict mode
set -euo pipefail
IFS=$'\n\t'
# Disable the pager for aws commands (no less on the host)
export AWS_PAGER=""
# Get the log group arn as a parameter and cut the group name out of it
@lox
lox / PostPolicy.php
Last active April 24, 2023 03:15
Multiple file uploads from browser to S3 via Dropzone.
<?php
namespace Aws\S3;
/**
* @category Amazon
* @package AWS
* @copyright Copyright 2009 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0