Skip to content

Instantly share code, notes, and snippets.

alemar11 / PasteboardWatcher.swift
Created Jan 22, 2022 — forked from Daemon-Devarshi/PasteboardWatcher.swift
A class which performs polling to determine the newly copied url of desired kind in an external app
View PasteboardWatcher.swift
// PasteboardWatcher.swift
// PasteboardWatcher
// Created by Devarshi Kulshreshtha on 6/19/15.PasteboardWatcher
// Copyright © 2015 Devarshi Kulshreshtha. All rights reserved.
import Cocoa
View gist:b5dad930b133980874eaf6ec320226ff
NSVisualEffectMaterial constants, and the undocumented materials they coorespond to in various modes:
| | | | | |
| 0 - Appearance Based | 3 | 3 | 5 | 5 |
| | | | | |
| 1 - Light | 3 | 3 | 3 | 3 |
| | | | | |
| 2 - Dark | 4 | 4 | 4 | 4 |
View ConditionTester.swift
import Foundation
// Swift translation of
class ConditionTester {
typealias TestCondition = () -> (Bool)
private let condition: TestCondition
private var fulfilled: Bool { return condition() }
private var currentRunLoop: CFRunLoop {
return RunLoop.current.getCFRunLoop()
alemar11 /
Created Oct 7, 2021 — forked from tclementdev/
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

View TraitCollectionBasedAdjustments.swift
// Bigger iPhones = any Max, any Plus, iPhone XR, iPhone 11
switch (UITraitCollection.current.horizontalSizeClass, UITraitCollection.current.verticalSizeClass) {
case (.compact, .compact):
// Smaller iPhones in landscape
case (.compact, .regular):
// Bigger iPhones in portrait
// iPads in portrait during any split screen,
alemar11 / openssl-build.h
Created Jul 15, 2021 — forked from steipete/openssl-build.h
Updated script that builds OpenSSL with Bitcode enabled (tested with Xcode 7.0b3)
View openssl-build.h
# This script downlaods and builds the iOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# Peter Steinberger, PSPDFKit GmbH, @steipete.
set -e
alemar11 / gist:2a28acd1b166dd452f81e7abfd8521fc
Created Apr 27, 2021 — forked from horseshoe7/gist:e85bbb90278f626bea2f827ee5228703
Incremental MHWMigrationManager extended for optional finalDestinationURL
View gist:2a28acd1b166dd452f81e7abfd8521fc
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class MHWMigrationManager;
@protocol MHWMigrationManagerDelegate <NSObject>
- (void)migrationManager:(MHWMigrationManager *)migrationManager migrationProgress:(float)migrationProgress;
View JCMMemoryEfficientMigrationManager.h
@import CoreData;
A subclass of NSMigrationManager that is more memory efficient than
NSMigrationManager itself.
This class maintains its own source and destination instance association
tables, which store only the URI representation of the instances's object IDs,
rather than the objects themselves. This means that objects do not accumulate
alemar11 / How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

Let's say alice is a user, with 2 or more private repositories repoN. For this example we'll work with just two repositories named repo1 and repo2

You need to be to pull from these repositories without entering a passwords probably on a server, or on multiple servers.

alemar11 / AuthenticatingSceneDelegate.swift
Created Jan 3, 2021 — forked from shaps80/AuthenticatingSceneDelegate.swift
A UIWindowSceneDelegate that provides lifecycle events and an API for deferring specific tasks automatically for you. Simplifies the implementation of LocalAuthentication or some other authentication implementation.
View AuthenticatingSceneDelegate.swift
import UIKit
/// Defines a token for determining the validity of a session
public protocol AuthenticationToken: Codable {
/// The token is currently valid
var isValid: Bool { get }
/// An encoded representation for storage
var encoded: Data? { get }