Skip to content

Instantly share code, notes, and snippets.

@algal
algal / aoc2023d3.ipynb
Created December 3, 2024 17:29
My Dialog
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@algal
algal / advent2022.ipynb
Created December 3, 2024 01:03
My Dialog
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@algal
algal / advent2024d3.ipynb
Created December 4, 2024 01:52
My Dialog
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / NamesOnMacOS.md
Last active October 30, 2024 15:17
A note on how a Mac gets its various names

Names on macOS

Since I couldn't find documentation on how a Mac machine gets its name, I thought I'd write up these notes for my own reference later.

A macOS machine has a few different names, which might or might not be equal.

1. ComputerName

Every machine has a pretty user-facing name. This is the ComputerName.

def find_free_port(candidates=[]):
for p in (candidates + [0]):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind(('localhost',p))
return s.getsockname()[1]
except Exception:
logging.info(f"Could not bind to port {p}. Trying another")
port = find_free_port([5001,5010,5100])
@algal
algal / CircleView.swift
Last active October 10, 2024 04:53
Custom UIView hosting a CAShapeLayer
// known-good: Xcode 8.2.1, Swift 3, 2017-02-08
/**
Draws a circle, centered in the view, with the specified radius
*/
class CircleView: UIView
{
// API
var circleRadius:CGFloat = 15 {
didSet { self.setNeedsLayout() }
@algal
algal / openjup.py
Last active October 2, 2024 19:00
Python script to open a notebook in your local browser, no matter where the server or notebook is
#!/usr/bin/env python3
import os, os.path, sys, urllib.parse, base64, subprocess
def on_iterm2(): return 'ITERM_SESSION_ID' in os.environ or os.environ.get('LC_TERMINAL','') == 'iTerm2'
def on_macOS(): return sys.platform == 'darwin'
def on_remote_host(): return 'SSH_CLIENT' in os.environ or 'SSH_TTY' in os.environ
def openurl(url):
@algal
algal / websitescreenshot.md
Last active August 11, 2024 18:37
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