Skip to content

Instantly share code, notes, and snippets.

View babldev's full-sized avatar

Brady Law babldev

View GitHub Profile
@babldev
babldev / partition_data.py
Last active January 10, 2024 02:29
Script for partitioning training, test, validation data files randomly (e.g. Yolo object detection)
#!/usr/bin/python3
"""
Randomly bucket files in a directory based on percentages for the purposes of machine learning training.
E.g. `python3 partition-data.py --data labels:**/*.txt images:**/*.png --partitions train:80 val:10 test:10
Will move files in the current directory to:
- train/ (80%)
- val/ (10%)
- test/ (10%)
"""
@babldev
babldev / MyApp.swift
Last active February 16, 2024 09:42
Change background color of root view in SwiftUI, fixing white background during rotation
//
// MyApp.swift
// MyApp
//
// Created by Brady Law on 8/25/23.
//
import SwiftUI
@main
@babldev
babldev / Info.plist
Last active August 31, 2023 17:27
Make iOS app files saved to Documents directory visible in the Files app
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
@babldev
babldev / Dockerfile
Last active March 6, 2024 16:37
Next.js + worker orchestration on Google Cloud example
# Alpine image is smaller but Prisma is broken on M1 https://github.com/prisma/prisma/issues/8478
# FROM node:18-alpine AS builder
# RUN apk update
# RUN apk add --no-cache openssl
FROM node:18-slim AS runner
RUN apt-get update \
&& apt-get install -y openssl
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
@babldev
babldev / README.md
Last active August 30, 2024 09:04
NextJS Background Task

NextJS Background Task Example

An example of how to add a background task (e.g. a queue consumer) to an existing NextJS project.

Setup

  • Add your background task file
  • Add a new worker-tsconfig.json, specifically specifying "module": "commonjs" and targeting only the worker source files.
  • Add convenience functions for building & running to package.json

Then to build once:

@babldev
babldev / .pre-commit-config.yaml
Created April 27, 2022 23:41
Typescript precommit settings
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.12.0
@babldev
babldev / .pre-commit-config.yaml
Last active April 19, 2022 20:31
Pre-commit hook for typescript type checking
repos:
- repo: local
hooks:
- id: typescript-check
name: typescript-check
entry: npx tsc
language: system
types_or: [ts, tsx]
pass_filenames: false
@babldev
babldev / github.sh
Created April 5, 2019 20:34
Open commit on github v2
#!/bin/sh
REPO=$(git config --get remote.origin.url | sed "s/^.*://" | sed "s/\.git\$//")
open https://github.com/$REPO/commit/$1
@babldev
babldev / decode_flask_cookie.py
Last active December 15, 2023 12:02
Decode a Flask Session cookie, given the cookie and secret key