Skip to content

Instantly share code, notes, and snippets.

@schwa
schwa / xcode-select-dialog.fish
Last active October 27, 2021 21:21
Example script showing how to use dialog (`brew install dialog`) to drive xcode-select
function xcode-select-dialog
# Get current Xcode
set CURRENT_XCODE (xcode-select -p | sed "s/\/Contents\/Developer//")
# Find all Xcodes on system
set XCODES (mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode' && kMDItemContentType == 'com.apple.application-bundle'")
# Build a dialog menu
set MENU
struct ErrorHandler {
var callback: (Error) -> Void
func handle(_ block: () throws -> Void) {
do {
try block()
}
catch {
callback(error)
}
@schwa
schwa / environment.swift
Created March 27, 2021 15:49
Dash Snippet for SwiftUI Environments & Modifiers
struct __ValueType__ {
}
struct __ValueType__Key: EnvironmentKey {
static var defaultValue = __ValueType__()
}
extension EnvironmentValues {
var __KeyName__: __ValueType__ {
get {
@schwa
schwa / code-python-setup.fish
Last active September 2, 2021 20:18
Fish script for setting up a python project with poetry, pyenv, visual code, etc…
#!/usr/bin/env fish
### Fish function for setting up a Visual Studio Code python project using Poetry and Pyenv
### How to install: copy this into your ~/.config/fish/functions directory
### How to use: mkdir a project direct, cd into it, and run the code-python-setup function
### This function will:
### * install dependencies
### * select and/or install if necessary a particular python version (using pyenv)
### * set up a poetry virtual environment
### * configure the vscode project settings with the correct interpreter
import subprocess
from pathlib import Path
import plistlib
import pinboard # install via pip
from shutil import which
PINBOARD_TOKEN = "< your pinboard token>"
subprocess.check_call(
[
func movement() async {
// TODO: Dont use async version because it hangs!
GCController.startWirelessControllerDiscovery { }
while !Task.isCancelled {
// Wait for any controller to become current
_ = await NotificationCenter.default.notifications(named: .GCControllerDidBecomeCurrent, object: nil).makeAsyncIterator().next()
guard let currentController = GCController.current, let gamepad = currentController.extendedGamepad else {
return
}
@schwa
schwa / Filter1Password.py
Created February 24, 2022 02:55
Python script to help import 1Password data into iCloudKeychain
# Filter1Password.py
# Quick script to help filter records from a 1Password .csv export for importing into Safari/iCloud Keychain
# Safari rejects records with no username, password or url. This script takes your 1Password export and "splits" it
# into two CSV file, one with these records filtered out, and one with just records with the required fields. You can then import the
# filtered .csv file directly into Safari and should not get import warnings.
# This script also filters out records with the "Archive" field set to true - these are 1Password records that you previously Trashed
import csv
@schwa
schwa / GunHeatmaps.py
Created June 3, 2022 05:45
GunHeatmaps.py
# %%
import pandas as pd
import numpy as np
import datetime as dt
from datetime import datetime
import calmap
# Data from https://www.gunviolencearchive.org/
#events = pd.read_csv('ChildrenKilled.csv', parse_dates=['Incident Date'])
events = pd.read_csv('MassShootings.csv', parse_dates=['Incident Date'])
@schwa
schwa / spm-init.fish
Created July 29, 2022 20:20
CLI tool using gum (https://github.com/charmbracelet/gum) to streamline Swift Package creation…
#!/usr/bin/env fish
# brew tap charmbracelet/tap && brew install charmbracelet/tap/gum
function spm-init
gum style --foreground 11 "Package Type:"
set TYPE (gum choose "library" "executable" "empty" "system module" "manifest")
gum style --foreground 10 $TYPE
@schwa
schwa / flick.swift
Last active October 15, 2022 00:18
Flick Gesture
import PlaygroundSupport
import SwiftUI
PlaygroundPage.current.setLiveView(ContentView())
struct ContentView: View {
var body: some View {
Color.white.frame(width: 600, height: 800).touchVisualizer()
}
}