Skip to content

Instantly share code, notes, and snippets.

@algal
algal / Bikeshed.md
Last active October 27, 2018 02:55

Obviously the big question is whether it's wise to add these protocols. But I got curious and did a little research just on the naming question, to see if "intensional set" and "extensional set" are well-established mathematical terms for different kinds of sets. Seems like they're not.

I checked two reference works -- The Princeton Companion to Mathematics and the Encyclopedic Dictionary of Mathematics (2nd edition). I looked in their tables of contents, their indexes, and in their articles discussing set theory, and there is no mention of the idea of an "intentional set" or an "extensional set". Also, anecdotally, I did some math in grad school and never ran into the terms.

The terms "extensional" and "intensional" originate in philosophy of l

@algal
algal / osxvpnrouting.markdown
Created October 4, 2018 18:23 — forked from Eradash/osxvpnrouting.markdown
Routing tips for VPNs on OS X

Routing tips for VPNs on OS X

When VPNs Just Work™, they're a fantastic way of allowing access to a private network from remote locations. When they don't work it can be an experience in frustration. I've had situations where I can connect to a VPN from my Mac, but various networking situations cause routing conflicts. Here are a couple of cases and how I've been able to get around them.

Specific cases

Case 1: conflicting additional routes.

In this example the VPN we are connecting to has a subnet that does not conflict with our local IP, but has additional routes that conflict in some way with our local network's routing. In my example the remote subnet is 10.0.x.0/24, my local subnet is 10.0.y.0/24, and the conflicting route is 10.0.0.0/8. Without the later route, I can't access all hosts on the VPN without manually adding the route after connecting to the VPN:

@algal
algal / run_tee.py
Last active October 23, 2018 06:29
# known-good: python 3.7.0
class RunOutput(object):
def __init__(self, return_code, stdout, stderr):
self.return_code = return_code
self.stdout = stdout
self.stderr = stderr
def run_tee(s):
"""Runs shell command s, returning a RunOutput with (return_code, stdout, stderr).
;; Car salesman, *slapping roof of defun*: this bad boy can fit so much damn file management convenience in it.
(defun kill-buffer-file-name-or-name ()
"Pushes a useful path to the kill ring.
When visiting a file, pushes the file's path. In dired,
pushes the path of the file at point or else the current
directory. In magit, pushes the path of the file at point or else
the repo's root. Otherwise, pushes buffer's name. Displays
whatever was pushed in the message area."
@algal
algal / NamesOnMacOS.md
Last active September 5, 2018 02:30
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.

macOS networking entities

A network location is a set of network services in a particular order. So two network locations can differ by including different sets of network services or by including the same networking services but in a different order.

You might have only one network location, “Automatic”. networksetup -listallnetworkservices will list the network services of your current network location. There’s also a GUI in System Preferences. There’s more info at How to Use Network Location and Create and manage Network Location.

The service order of the network services determines which service macOS will prefer if multiple services are connected. A connected service gets a green indicator in Network preferences. (Services can also b enabled/disabled from the CLI, or made active/inactive from the GUI.)

A network service is a group of settings for a particular network port (see [Add a

import Foundation
import AVFoundation
import ImageIO
import MobileCoreServices
import BespokeCore
struct FrameInfo {
var frame:CGImage
var frameDuration:TimeInterval
@algal
algal / LineEndsFind.mm
Created April 22, 2018 22:48 — forked from jpsim/LineEndsFind.mm
A function to find the offsets of newlines ('\n') in UTF-16 encoded string. Try as I might, I cannot get a Swift version within an order of magnitude of the C++ version. Both routines must return arrays of the same size and with equal elements.
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <iostream>
#import <vector> // Needed for gist to compile.
#pragma mark - Pure Implementation Functions
const static unichar kUTF16Newline = (unichar)'\n'; // old naming habits die hard!
/**
* Calculates an array of line end "positions" for a given string.
* The equivalent Swift function was `(String) -> [Int]` or `(NSString) -> [Int]`
*
@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 / gist:0f047de3493b34a21026336ba0bf90fd
Created March 14, 2018 03:04
ClojureAgentInSwift.swift
import Foundation
/*
Same API as Clojure's agents, but sadly not based on a lockless compare-and-swap operation since Swift doesn not provide one yet.
*/
class Agent<T>
{