Skip to content

Instantly share code, notes, and snippets.

@algal
algal / pick.py
Last active April 25, 2024 17:36
pick
#!/usr/bin/env python3
import sys
import re
from collections import deque
def usage():
print("Usage: {} [--onebased | -o] ROW COLUMN".format(sys.argv[0]))
print("")
@algal
algal / PKCS12.swift
Last active March 21, 2024 07:13
Reading PKCS12 with Swift in Foundation
// xcode 7.3
import Foundation
/**
Struct representing values returned by `SecPKCS12Import` from the Security framework.
This is what Cocoa and CocoaTouch can tell you about a PKCS12 file.
*/
@algal
algal / Zipping.swift
Created February 17, 2019 01:18
Zip files on iOS, without using external libraries and without interoperating with the low-level Compression framework
// Zipping.swift
// known-good: Swift 4.2
// Alexis Gallagher
import Foundation
public extension URL {
/// Creates a zip archive of the file or folder represented by this URL and returns a references to the zipped file
///
@algal
algal / Claude.sh
Last active March 7, 2024 19:37
Calls Anthropic's claude-3-opus, passing in the command-line argument as the prompt.
#!/usr/bin/env bash
if [ "$#" -eq 0 ]; then
echo "Usage: $(basename "$0") promt_to_send_to_claude"
echo ""
echo " Requirements: ANTHROPIC_API, defined; jq and curl, installed; bash, version 3 or higher."
exit 1
fi
function claude() {
local json_request
@algal
algal / dateify
Last active February 7, 2024 07:49
Rename a file to prefix with its creation date, or undo this. Makes file match the Denote file-naming scheme
#!/bin/bash
# compatibility: works on Debian 12, macOS Sonoma, and in Linux-simulating shell environments in macOS.
# Function to display usage message
usage() {
echo "Usage: $(basename "$0") [OPTION]... [FILE]..."
echo
echo "Rename files by adding or removing a date-time prefix"
echo "in the following format yyyymmddThhmmss--"
@algal
algal / p.sh
Created January 22, 2024 17:31
bash script to query perplexity.ai
#!/usr/bin/env bash
# based off of https://gist.github.com/rauchg/c5f0b1dc245ad95c593de8336aa382ac?permalink_comment_id=4842642#gistcomment-4842642
if [ "$#" -eq 0 ]; then
echo "Usage: $(basename $0) promt_to_send_to_perplexity"
echo ""
echo " Requirements: PERPLEXITY_API, defined; jq and curl, installed; bash, version 3 or higher."
exit 1
fi
function p() {
@algal
algal / websitescreenshot.md
Last active December 26, 2023 11:07
Taking website screenshots, in Chrome or Safari, including simulating iPhones

Taking website screenshots

These are instructions for taking screenshots of an entire webpage, not just the part of the webpage visible in the browser.

Website Screenshots in Safari

This requires Safari 11.3, which comes on macOS 10.3.4.

  1. Open the website in Safari
  2. If needed, go Safari > Preferences > Advanced > Show Develop Menu in Menu Bar
@algal
algal / nginx-cors.conf
Created April 29, 2013 10:52
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@algal
algal / excel_parseDates.vba
Last active September 27, 2023 21:28
please god why aren't these predefined?
' Expects a datetimestr in the format "YYYYMMDD" with - or / or no separator
' Parses independently of local region, unlike VBA.DateTime.DateValue()
' Known-good on Excel for Mac Version 16.4
Function parseYYYYMMDD(dateTimeStr As String) As Date
Dim normalized As String
normalized = VBA.Strings.Trim(dateTimeStr)
normalized = VBA.Strings.Replace(dateTimeStr, "/", "")
normalized = VBA.Strings.Replace(normalized, "-", "")
@algal
algal / ScaleAspectFitImageView.swift
Last active September 24, 2023 10:19
UIImageView subclass that works with Auto Layout to express its desired aspect ratio
import UIKit
// known-good: Xcode 8.2.1
/**
UIImageView subclass which works with Auto Layout to try
to maintain the same aspect ratio as the image it displays.
This is unlike the usual behavior of UIImageView, where the