Skip to content

Instantly share code, notes, and snippets.

View catlan's full-sized avatar

Christopher Atlan catlan

View GitHub Profile
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let referenceSize = UIFont.preferredFont(forTextStyle: .body,
compatibleWith: .init(preferredContentSizeCategory: .medium))
let newSize = UIFont.preferredFont(forTextStyle: .body)
let percentIncrease = (newSize.pointSize / referenceSize.pointSize) * 100
let js = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='\(Int(percentIncrease))%'"
webView.evaluateJavaScript(js) { _, error in
@smorr
smorr / getFSEventUUID.m
Last active June 5, 2018 17:39
Quick program to fetch the current FSEventUUID for boot device on macOS
#import <Foundation/Foundation.h>
#include <sys/param.h>
#include <sys/mount.h>
// adapted from http://www.cocoabuilder.com/archive/cocoa/203717-looking-for-sample-code-to-read-uuid-from-disk-volume.html
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
struct statfs stat;
@rnystrom
rnystrom / ViewController.swift
Created May 29, 2018 01:16
Interactive NSAttributedString link highlighting with TextKit
import UIKit
public extension CGSize {
func snapped(scale: CGFloat) -> CGSize {
var size = self
size.width = ceil(size.width * scale) / scale
size.height = ceil(size.height * scale) / scale
return size
}
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
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

@macguru
macguru / gist:b7a01e3f0e9ae6f350d5
Last active May 10, 2020 20:58
Interface sizes a regular Universal app must support with iOS 11 when supporting all devices. Starts with iPhone 5 and goes up to iPad Pro 12.9".
COMPACT WIDTH (stacked view)
- 320 x 568 pt
-> iPhone 5, 5s
- 320 x 768 pt
-> iPad 9.7" Split Landscape 2/3 right
- 320 x 834 pt
-> iPad 10.5" Split Landscape 2/3 right
- 320 x 1024 pt
-> iPad 9.7" Split Portrait right
@robjwells
robjwells / NSAppleScript+RunHandler.h
Created July 5, 2015 14:46
NSAppleScript category to make calling AppleScript handlers (functions) easier
//
// NSAppleScript+RunHandler.h
// astest
//
// Created by Rob Wells on 30/01/2014.
// Copyright (c) 2014 Rob Wells. All rights reserved.
//
#ifndef kASAppleScriptSuite
#define kASAppleScriptSuite 'ascr'
@zrxq
zrxq / .lldbinit
Last active February 7, 2024 11:21
Execute lldb command and open its output in Sublime Text
comma script import ~/lldb/subl.py
comma script add -f subl.subl subl