Skip to content

Instantly share code, notes, and snippets.

View ZevEisenberg's full-sized avatar

Zev Eisenberg ZevEisenberg

View GitHub Profile
struct SectionedArray<GroupKey, Item> where GroupKey: Comparable & Hashable {
struct Section {
let key: GroupKey
var items: [Item]
}
var sections: [Section]
var count: Int {
@ZevEisenberg
ZevEisenberg / Find Siteswap Loops.swift
Last active February 17, 2020 18:25
Find how long it takes for an async siteswap to loop
//
// main.swift
// Swapper
//
// Created by Zev Eisenberg on 12/4/17.
// Copyright © 2017 Zev Eisenberg. All rights reserved.
//
// Code ported from https://www.reddit.com/r/juggling/comments/7839h0/find_number_of_beats_to_loop_a_given_siteswap/douuezu/
// It finds how many beats you would have to juggle an async siteswap pattern before
@ZevEisenberg
ZevEisenberg / Dictionary+Utilities.swift
Created November 29, 2017 21:57
Convert a dictionary’s keys from NSAttributedStringKey to String
extension Dictionary where Key == NSAttributedStringKey {
var withStringKeys: [String: Value] {
return reduce(into: [:], {
$0[$1.key.rawValue] = $1.value
})
}
}
@ZevEisenberg
ZevEisenberg / Files changed during macOS Security Update 2017-001 installation.txt
Created November 29, 2017 17:02
Files changed during macOS Security Update 2017-001 installation
11:55:09 AM ↗️ 0x15900 /Users/zev/Library/Preferences/com.apple.spaces.plist.P2AbRcF
11:55:09 AM ↘️ 0x10800 /Users/zev/Library/Preferences/com.apple.spaces.plist
11:55:09 AM ↗️ 0x15900 /Users/zev/Library/Preferences/com.tristan.FSMonitor.plist.cR5WRLP
11:55:09 AM ↘️ 0x10800 /Users/zev/Library/Preferences/com.tristan.FSMonitor.plist
11:55:09 AM 🆕 0x14100 /Users/zev/Library/Preferences/ByHost/com.apple.loginwindow.0922F432-94E3-55A1-8672-6B66E786F21B.plist.8jDpEFP
11:55:10 AM ↗️ 0x15900 /Users/zev/Library/Preferences/ByHost/com.apple.loginwindow.0922F432-94E3-55A1-8672-6B66E786F21B.plist.8jDpEFP
11:55:10 AM ↘️ 0x10800 /Users/zev/Library/Preferences/ByHost/com.apple.loginwindow.0922F432-94E3-55A1-8672-6B66E786F21B.plist
11:55:10 AM 🛠 0x18000 /private/var/db/diagnostics/Persist/0000000000000283.tracev3
11:55:10 AM 🆕 0x14100 /Users/zev/Library/Preferences/com.tristan.FSMonitor.plist.tbghtkX
11:55:10 AM ❌ 0x11300 /Users/zev/Library/Caches/at.obdev.LaunchBar/IndexingProgressLog.plist
@ZevEisenberg
ZevEisenberg / apple-dev.zsh
Created July 22, 2017 03:07
Utility functions for doing iOS and Mac development
# cd to the folder containing an Xcode project dragged from an Xcode window's proxy icon. If no file is provided, cd to the folder containing the current Xcode project
function xc
{
xcodeIsRunning=false
if [[ `osascript -e 'tell app "System Events" to count processes whose name is "Xcode"'` == 1 ]]; then
xcodeIsRunning=true
fi
if [[ $xcodeIsRunning == false ]]; then
echo "Xcode is not open. I don’t know what you want from me."
@ZevEisenberg
ZevEisenberg / version_copy_functions.sh
Created July 22, 2017 02:35
Functions to copy versions of Xcode, browsers, and macOS
function copySafariVersion
{
local safariVersion=$(defaults read /Applications/Safari.app/Contents/Info CFBundleShortVersionString)
local safariBuild=$(defaults read /Applications/Safari.app/Contents/Info CFBundleVersion)
local macOSVersion=$(sw_vers -productVersion)
local macOSBuild=$(sw_vers -buildVersion)
local fullString="Safari ${safariVersion} (${safariBuild}) on macOS ${macOSVersion} (${macOSBuild})"
echo "Copied \"$fullString\""
echo -n $fullString | pbcopy
}
@ZevEisenberg
ZevEisenberg / NS Prefix Finder.txt
Created March 30, 2017 15:25
Regex for finding NS prefixes in code migrated to Swift 3
[^(CONDITIO)]NS[^(Error)|^(Coder)|^(Managed)|^(Attributed)|^(LayoutConstraint)|^(Predicate)|^(FetchRequest)|^(Null)|^(KeyValue)]
@ZevEisenberg
ZevEisenberg / LICENSE
Last active February 19, 2022 02:04
Smoothly deselect table and collection view cells on dismissal, including interactive dismiss and interactively-partially-dismiss-then-cancel-then-dismiss-again
The MIT License (MIT)
Copyright (c) 2016 Zev Eisenberg
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:
@ZevEisenberg
ZevEisenberg / map float range.swift
Last active July 13, 2020 20:31
Mapping floating point numbers between two ranges in Swift
import QuartzCore
extension CGFloat {
func map(from from: ClosedInterval<CGFloat>, to: ClosedInterval<CGFloat>) -> CGFloat {
let result = ((self - from.start) / (from.end - from.start)) * (to.end - to.start) + to.start
return result
}
}
extension Double {
@ZevEisenberg
ZevEisenberg / traits.m
Created December 14, 2015 18:02
Version of a UIFont with different symbolic traits
static UIFont *versionOfFontWithSymbolicTraits(UIFont *font, UIFontDescriptorSymbolicTraits symbolicTraits)
{
UIFontDescriptor *descriptor = font.fontDescriptor;
UIFontDescriptor *descriptorToUse = [descriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
UIFont *newFont = [UIFont fontWithDescriptor:descriptorToUse size:font.pointSize];
return newFont;
}