Skip to content

Instantly share code, notes, and snippets.

View soffes's full-sized avatar

Sam Soffes soffes

View GitHub Profile
@soffes
soffes / UIFont+Monospaced.swift
Created July 27, 2021 18:17
Monospaced numbers in iOS 15 beta 4
import UIKit
extension UIFont {
public func withMonospacedNumbers() -> Self {
let monospacedFeature: [UIFontDescriptor.FeatureKey: Any]
if #available(iOS 15.0, *) {
monospacedFeature = [
.type: kNumberSpacingType,
.selector: kMonospacedNumbersSelector
@soffes
soffes / BaseTextStorage.h
Last active July 1, 2023 10:14
BaseTextStorage (Objective-C)
@import Darwin.TargetConditionals;
#if TARGET_OS_IPHONE
@import UIKit;
#else
@import AppKit;
#endif
/// Concrete text storage intended to be subclassed.
@interface BaseTextStorage : NSTextStorage
@soffes
soffes / BaseTextStorage.swift
Last active July 1, 2023 10:14
Fast, concrete text storage intended to be subclassed.
import UIKit
/// Fast, concrete text storage intended to be subclassed.
class BaseTextStorage: NSTextStorage {
// MARK: - Properties
private let storage = NSMutableAttributedString()
// MARK: - NSTextStorage
@soffes
soffes / GPUImageTextureInput+CIImage.h
Last active February 26, 2023 14:02
GPUImage + Core Image
//
// GPUImageTextureInput+CIImage.h
// GPUImage
//
// Created by Sam Soffes on 3/4/14.
// Copyright (c) 2014 Sam Soffes. All rights reserved.
//
#import "GPUImageTextureInput.h"
@soffes
soffes / Rakefile
Last active January 16, 2023 16:37
Programmatically build and sign a Developer ID macOS app
TEAM_ID = 'XXXXXXXXXX'
APP_NAME = 'My App'
SCHEME_NAME = APP_NAME
desc 'Create a beta build'
task :build do
# Ensure clean git state
unless system 'git diff-index --quiet HEAD --'
abort 'Failed. You have uncommitted changes.'
end
@soffes
soffes / WebCredential.swift
Last active November 25, 2022 08:24
Easily access Shared Web Credentials
import Foundation
import Security
struct SharedWebCredentials {
// MARK: - Types
struct Credential {
let domain: String
let account: String
@soffes
soffes / SafariActivity.swift
Created October 26, 2020 22:19
Open in Safari UIActivity
import UIKit
final class SafariActivity: UIActivity {
// MARK: - Properties
var url: URL?
// MARK: - UIActivity
@soffes
soffes / perferences.json
Created August 22, 2012 05:35
My Sublime Text 2 config
{
"bold_folder_labels": true,
"color_scheme": "Packages/User/Espresso Soda.tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store",
".gitkeep",
"dump.rdb"
],
@soffes
soffes / UIColorExtension.swift
Created July 21, 2015 15:48 — forked from asarode/UIColorExtension.swift
Swift extension to get luma value of a UIColor
import UIKit
extension UIColor {
var luminance: CGFloat {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
getRed(&red, green: &green, blue: &blue, alpha: nil)
@soffes
soffes / highlight.swift
Last active November 16, 2021 07:34 — forked from orta/highlight.swift
Swift implementation to highlight Cocoa UI elements (http://stackoverflow.com/a/25984748/316803)
// Taken from:
// https://gist.github.com/joelcox/28de2f0cb21ea47bd789
NSColor.selectedMenuItemColor.set()
NSBezierPath(rect: rect).fill()
if rect.height > 1 {
let currentControlTint = NSColor.currentControlTint
let startingAlpha: CGFloat = currentControlTint == .blueControlTint ? 0.16 : 0.09