Skip to content

Instantly share code, notes, and snippets.

// https://wadetregaskis.com/swiftui-main-thread-hang-detector/
var body: some View {
SomeRootView {
}.task {
let approximateGranularity = Duration.milliseconds(10)
let threshold = Duration.milliseconds(50)
let clock = SuspendingClock()
@jessesquires
jessesquires / pages-to-pdf.scpt
Created December 6, 2023 06:48
AppleScript to export a Pages document as a PDF
-- Prompt to select the invoice
set theInvoice to choose file with prompt "Please select an invoice:"
-- Get enclosing folder name
tell application "Finder" to set destinationFolder to container of theInvoice
log "Destination folder: " & destinationFolder
tell application "Pages"
activate
open theInvoice
import Cocoa
protocol Shape { }
struct Triangle: Shape { }
// Function signature requires a concrete type T, it is specialized by T
// Think of it as having a unique function per type:
// - `protoflip(_ s: Triangle) -> Shape`
// - `protoflip(_ s: Square) -> Shape`
@jessesquires
jessesquires / detweet.swift
Created January 15, 2019 17:56 — forked from mxcl/detweet.swift
Delete all tweets and favorites older than two months ago. Instructions in comment.
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@jessesquires
jessesquires / keybase.md
Last active September 13, 2019 01:23
keybase.md

Keybase proof

I hereby claim:

  • I am jessesquires on github.
  • I am jsq (https://keybase.io/jsq) on keybase.
  • I have a public key whose fingerprint is BBAE BA80 7CF2 7BC2 5E5C FB43 1537 66AC 1FA1 A758

To claim this, I am signing this object:

@jessesquires
jessesquires / gist:8781c86206dfb70e78eb7f1aa4fc6fac
Created January 10, 2018 00:40
Delete all local git branches
git config --global alias.trim '!f() { git branch | grep -v "\*" | xargs -n 1 git branch -D; }; f'
@jessesquires
jessesquires / feed.json
Last active August 22, 2022 05:21
Jekyll JSON Feed
---
layout: null
---
{
"version": "https://jsonfeed.org/version/1",
"title": "{{ site.title }}",
"home_page_url": "{{ site.url }}",
"feed_url": "{{ site.url }}/feed.json",
"description": "{{ site.description }}",
@jessesquires
jessesquires / gitsl.sh
Last active August 9, 2024 13:43
git "smartlog" / "pretty log"
# blog post
#
# https://www.jessesquires.com/blog/customizing-git-log/
git log --graph --pretty=format:'commit: %C(bold red)%h%Creset %C(red)<%H>%Creset %C(bold magenta)%d %Creset%ndate: %C(bold yellow)%cd %Creset%C(yellow)%cr%Creset%nauthor: %C(bold blue)%an%Creset %C(blue)<%ae>%Creset%n%C(cyan)%s%n%Creset'
@jessesquires
jessesquires / FCPrivateBatteryStatus.m
Created March 18, 2016 16:18
How to get raw battery info (mAh remaining, etc.) from iOS using private APIs. For internal testing only, NOT APP STORE DISTRIBUTION!
#import <Foundation/Foundation.h>
#include <dlfcn.h>
NSDictionary *FCPrivateBatteryStatus()
{
static mach_port_t *s_kIOMasterPortDefault;
static kern_return_t (*s_IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options);
static mach_port_t (*s_IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching CF_RELEASES_ARGUMENT);
static CFMutableDictionaryRef (*s_IOServiceMatching)(const char *name);