Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexis Gallagher algal

  • San Francisco
View GitHub Profile
@algal
algal / addWideMargins.bash
Created Jul 15, 2020
Add wide margins to a PDF for annotations
View addWideMargins.bash
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "usage: $0 PDF_filename..."
echo
echo "This script takes a PDF file as command line arguments,"
echo "and generates a new, landscape-formatted PDF file, where every "
echo "page has very large margins which may be useful for editorial notes"
echo
echo "Requires: pdfjam"
echo
@algal
algal / ReverseH2.swift
Last active Jun 22, 2020
Deno and Swift scripts to reverse H2 headers in text
View ReverseH2.swift
#!/usr/bin/swift
/*
Reads stdin, requiring UTF8-encoded text.
Parses it as initial text followed by a sequence of H2 markdown blocks.
Prints to stdout the initial text plus the H2 blocks in reversed order.
*/
import Foundation
@algal
algal / colorize-emacs.bashsource
Last active May 1, 2022
Setting up truecolor (24 bit color) in emacs in the terminal, under iTerm2, blink.sh, and others.
View colorize-emacs.bashsource
# sourcing this file will define a bash functions that
# tries to run subsequent calls to emacs with 24 bit color.
#
# It sets TERM=xterm-emacs-leg if
# - we've created a user-local terminfo record for xterm-emacs-leg, and
# - we're using iTerm2 or something has set COLORTERM=truecolor
#
# This will cause emacs to use 24 bit color only when it will work,
# inside or outside of tmux. I haven't found a way to auto-detect Blink.sh yet.
#
@algal
algal / fixssh-forwarding.el
Created Feb 20, 2020
Within emacs, fix ssh agent forwarding, which breaks in long-running tmux sessions
View fixssh-forwarding.el
;; The purpose of this file is to define the function `fixssh-in-tmux`,
;; which attempts to fix ssh agent forwarding when it breaks within
;; a tmux session
;; from https://github.com/magnars/s.el/blob/master/s.el
(defun fixssh--s-match (regexp s &optional start)
"When the given expression matches the string, this function returns a list
of the whole matching string and a string for each matched subexpressions.
If it did not match the returned value is an empty list (nil).
@algal
algal / California-time.bash
Created Oct 7, 2019
print the time in California, in RFC 2822 format
View California-time.bash
#!/bin/bash
# prints California time, on macOS or Ubuntu 18
exec env TZ='America/Los_Angeles' date -R
@algal
algal / vmstatistics64.swift
Last active Aug 16, 2022
Get virtual memory usage on iOS or macOS
View vmstatistics64.swift
import Darwin
import Foundation
// known good: Swift 5
// runs on macOS, probably works on iOS (but haven't tried)
/// Wraps `host_statistics64`, and provides info on virtual memory
///
/// - Returns: a `vm_statistics64`, or nil if the kernel reported an error
///
View MapLines.swift
//
// processFIle.swift
// LineIteratorProj
//
// Created by Alexis Gallagher on 8/14/19.
// Copyright © 2019 Sculpt Labs. All rights reserved.
//
// known-good: Swift 5
@algal
algal / SwiftLineReader.swift
Created Aug 14, 2019
Lazily read a line at a time in Swift
View SwiftLineReader.swift
import Foundation
// known good: Swift 5
typealias LineIteratorState = (
// pointer to a C string representing a line
linePtr:UnsafeMutablePointer<CChar>?,
linecap:Int,
filePtr:UnsafeMutablePointer<FILE>?
)
@algal
algal / RangeStrider.swift
Last active Apr 30, 2019
Sequence of Range<Int>s
View RangeStrider.swift
// known-good: Swift 5.0.1
/*
# how to use:
instead of:
for i in 0 ..< (n-1)/bs {
let startIdx = i * bs
@algal
algal / PileView.swift
Last active Mar 8, 2019
Like a simple vertical stack view. No animations. But no magical mystery meat, and it works.
View PileView.swift
//
// Pile.swift
// PileTest
//
// Created by Alexis Gallagher on 3/6/19.
// Copyright © 2019 Bespoke. All rights reserved.
//
// known-good: Swift 4.2, iOS 12