Skip to content

Instantly share code, notes, and snippets.

@jahands
jahands / Earthfile
Created February 14, 2024 14:57
Go multiplatform docker builds
VERSION 0.8
PROJECT jahands/docker
# Local targets:
tidy:
LOCALLY
RUN go mod tidy
build-local:
LOCALLY
@jahands
jahands / Get-DirHash.ps1
Last active December 22, 2023 16:26
Get hash of entire directory in powershell.
Function Get-DirHash {
[Cmdletbinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateScript({
if(Test-Path -Path $_ -ErrorAction SilentlyContinue)
{
return $true
}
else
@jahands
jahands / repeat.ts
Last active January 8, 2023 17:08
Repeat.dev to Notion Dashboard https://repeat.dev
import { Client as NotionClient } from '@notionhq/client';
import formatISO from 'date-fns/formatISO'
import { utcToZonedTime } from 'date-fns-tz'
import { ThrottledQueue, auth } from '@jahands/msc-utils';
let notion: NotionClient;
function setup(env: Repeat.Env) {
if (!notion) {
notion = new NotionClient({
@jahands
jahands / repeat.ts
Last active January 7, 2023 21:20 — forked from Erisa/repeat.ts
Repeat for clearing out Pages deployments (https://repeat.dev)
// https://gist.github.com/jahands/c68b4786d1cea696e61714354c1d3019
import { ThrottledQueue } from '@jahands/msc-utils';
import PQueue from 'p-queue';
// ===== SETUP ===== //
// Required ENV vars:
// CLOUDFLARE_ACCOUNT_ID
// CLOUDFLARE_API_TOKEN
// WEBHOOK_KEY
@jahands
jahands / statsGraph.ts
Last active November 22, 2022 23:11
Serving a graph from Google Sheets, cached via Cloudflare R2 + Edge Cache for maximum uptime
async function statsGraph(params: Params, request: any, env: Env, ctx: ExecutionContext): Promise<Response> {
const graphKey = 'uuid.rocks/stats/graph.png'
const defaults = {
contentType: 'image/png',
cacheControl: 'public, max-age=1800',
} as const
const r2CacheTime = '2 hours' // itty-time format
// First check edge cache
// @ts-ignore
const cache = caches.default
@jahands
jahands / ConvertTo-WslPath.ps1
Created May 1, 2022 21:41
A PowerShell function to convert a path to WSL format
Function ConvertTo-WslPath {
Param(
[Parameter(Mandatory = $true, ValueFromPipeline)]
[string]$Path
)
$p = Get-Item $Path
$wslPath = "/mnt/$($p.PSDrive.Name.ToLower())$($p.FullName.Substring($p.FullName.IndexOf(':')+1).Replace('\','/'))"
$wslPath
}
@jahands
jahands / csvtojson-bulk.ps1
Last active October 17, 2021 17:49
Convert a csv to json key-value pairs for importing to Cloudflare Workers KV (REQUIRES POWERSHELL 7!!)
# This version is for very large datasets that might be too big for Wrangler
# You might have to run `sed -i '1s/^\xEF\xBB\xBF//' FILE.json` on the output file if wrangler gives errors
# Example row of data:
# Slug ID : 2723
# Slug Name : AJ_FV057
# Report Title : Wholesale Market Asian Vegetable Report - Atlanta, GA (AJ_FV057)
# Published Date : 2/24/2021 12:10
# Report Date : 2/24/2021
# Report Status : Final
@jahands
jahands / repl.new.js
Created May 20, 2021 03:21
Updates repl name based on url (eg. repl.new/py/python_project)
// ==UserScript==
// @name Replit_New_Namer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sets the name based on the url when using repl.new. Eg. repl.new/py/my awesome python project
// @author Jacob Hands
// @match https://replit.com/new/*
// @grant none
// ==/UserScript==
import { Router, Method, Params } from 'tiny-request-router'
// Let the router know that handlers are async functions returning a Response
type Handler = (params: Params, request: Request) => Promise<Response>
const router = new Router<Handler>()
router.get('/upload/:name', async (params: Params, request: Request) => upload(params, request))
export async function handle(event: FetchEvent): Promise<Response> {
let request = event.request
@jahands
jahands / README.md
Last active May 14, 2020 18:04
Count requests for every IP to CountAPI.xyz using Cloudflare Workers

I created this in order to count how many requests each IP is using, without sending personal data to CountAPI.xyz To accomplish this, I used Workers KV to map the IP address to a random UUID, which is used as the identifier on CountAPI.

Here's an example of what's stored in workers KV, with the user's IP as the key:

{
    "userID": "5e64db68-d628-4938-9c01-0968a2f76861",
    "userIP": "1.2.3.4",
    "firstSeenDate": "2020-05-11T02:12:16.377Z",