Skip to content

Instantly share code, notes, and snippets.

@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
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
}
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(
[
@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
@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 {
struct ErrorHandler {
var callback: (Error) -> Void
func handle(_ block: () throws -> Void) {
do {
try block()
}
catch {
callback(error)
}
@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