Skip to content

Instantly share code, notes, and snippets.

@joethephish
joethephish / PromptWindowController.swift
Last active April 2, 2025 17:37
Substage's flippy out command bar
import AppKit
import SwiftUI
class PromptWindowController: NSWindowController, NSWindowDelegate {
// Essential properties
private var promptWindowContext: PromptWindowContext
private let finderContext: FinderContext
init() {
public struct PartialForEach<
Data: RandomAccessCollection & MutableCollection,
ID: Hashable,
Content: View,
More: View
> where Data.Index == Int {
@Binding var data: Data
let idKeyPath: KeyPath<Data.Element, ID>
let maxItems: Int
let collapsible: Bool
@IanKeen
IanKeen / Example_Complex.swift
Last active September 10, 2024 11:53
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
struct User: Equatable {
var firstName: String
var lastName: String
}
@main
struct MyApp: App {
@State var value = User(firstName: "", lastName: "")
@State var showEdit = false
@sharplet
sharplet / KeychainItem.swift
Created April 25, 2020 23:57
A lightweight keychain wrapper for querying the keychain databse
// Copyright (c) 2019–20 Adam Sharp and thoughtbot, inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@IsaacXen
IsaacXen / README.md
Last active April 12, 2025 01:49
(Almost) Every WWDC videos download links for aria2c.
// Copyright (c) 2019–20 Adam Sharp and thoughtbot, inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@davedelong
davedelong / NSLocale.m
Last active October 15, 2022 08:02
Locales
/*
======================================================
THIS CODE IS FOR EDUCATIONAL PURPOSES ONLY.
I'M NOT RESPONSIBLE IF YOU SHIP THIS AND IT BLOWS UP IN YOUR FACE.
IF IT DOES AND YOU COMPLAIN TO ME I WILL LAUGH AT YOU.
@laynemoseley
laynemoseley / deploy.sh
Last active October 1, 2019 19:16
Zork deploy script
#!/bin/bash
echo "You enter a dark dungeon. A sign in front of you says: Choose wisely or you'll probably die."
read -p 'staging or production: ' ENV
if [ $ENV != "staging" ] && [ $ENV != "production" ]
then
echo "You go into the wrong hallway, a skeleton comes out and decapitates you. The End."
exit 1
fi
@catlan
catlan / README.md
Last active May 10, 2024 15:04 — forked from zrxq/.lldbinit
Execute lldb command and open its output in Kaleidoscope diff

Diff output of two lldb commands

Setup

  1. Copy the contents of the last snippet (lldbinit) from the gist page, and paste into your .lldbinit file. This makes the ksdiff macro known inside lldb.
  2. Put file ksdiff.py in ~/.lldb/
  3. sudo pip install temp
  4. Restart Xcode debug session

Example

(lldb) ksdiff ;

// Extend NSWorkspace and add a method to test if the volume is a network mount
@implementation NSWorkspace (Extras)
- (BOOL)checkForNetworkMountAtPath:(NSString*)path {
struct statfs stat;
int err = statfs([path fileSystemRepresentation], &stat);
if (err == 0)
{
return !(stat.f_flags & MNT_LOCAL);
}
return NO;