Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; This package makes changes to how emacs interprets CSI escape codes, so that | |
| ;; it better understands "CSI u"-style codes, so that more key chords pass | |
| ;; through to emacs in terminal mode. | |
| ;; | |
| ;; It is intended to work with the following terminal confugration: | |
| ;; | |
| ;; - iTerm2 / Keys / Report modifiers using CSI u: enabled | |
| ;; - iTerm2 / Keys / xterm control sequences can enable modifyOtherKeys mode: enabled | |
| ;; - iTerm2 / Terminal / Report Terminal Type: xterm-direct | |
| ;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import sys | |
| import re | |
| from collections import deque | |
| def usage(): | |
| print("Usage: {} [--onebased | -o | -u] ROW COLUMN".format(sys.argv[0])) | |
| print("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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--" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :;exec emacs --no-init-file --no-site-lisp -script "$0" -- "$@" # -*- mode:emacs-lisp -*- | |
| (defun main () | |
| (require 'cl-lib) | |
| (let ((script-name (nth 2 command-line-args)) | |
| (args (cdr command-line-args-left))) | |
| ;; assert: ARGS now is a possibly empty list of command line args to the script | |
| ;; check for valid arguments here | |
| (when (not args) | |
| (princ (format "usage: %s PATH_TO_FILE" script-name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # binomial coefficients | |
| """ | |
| Recurrence relation: | |
| C(n,k) is the count of all k-subsets in a set of n items. | |
| C(n,k) = C(n-1,k-1) + C(n-1,k) | |
| Intuition underlying the relation: | |
| 1. pick any item from the n-set, call it the special item. | |
| 2. Every k-subset either includes the special item or does not. |