Skip to content

Instantly share code, notes, and snippets.

@chockenberry
chockenberry / ql.sh
Last active March 4, 2024 23:40
QuickLook for macOS shell
#!/bin/sh
# usage:
# ql /tmp/file.jpg
# cat /tmp/file.jpg | ql
# cal -h | ql
if [ -z "$*" ]; then
cat > /tmp/ql.stdin
mime_type=$(file --brief --mime-type /tmp/ql.stdin)
@merlinmann
merlinmann / wisdom.md
Last active April 17, 2024 21:52
Merlin's Wisdom Project (Draft)

Merlin's Wisdom Project

Or: “Everybody likes being given a glass of water.”

By Merlin Mann.

It's only advice for you because it had to be advice for me.

@levitatingpineapple
levitatingpineapple / UIFont.Features.swift
Last active March 27, 2024 18:30
SFPro Font Features
import UIKit
extension UIFont {
/// Watch [WWDC Session](https://developer.apple.com/videos/play/wwdc2015/804/).
/// [Font Feature Registry](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html)
/// - Parameters:
/// - size: The size (in points) to which the font is scaled. This value must be greater than 0.0.
/// - weight: The weight of the font, specified as a font weight constant.
/// - features: Font features supported by SFPro
@NSProgrammer
NSProgrammer / Overview.md
Last active March 7, 2023 08:06
Comparing modern vs legacy graphics context rendering on iOS

legacy = UIGraphicsBeginImageContextWithOptions + UIGraphicsEndImageContext

modern = UIGraphicsImageRendererFormat + UIGraphicsImageRenderer

Take aways:

  • "modern" w/ prefersExtendedRange = NO
    • basically the same perf as "legacy"
    • probably a good idea to adopt since optimizations will likely be in "modern" first
  • "modern" w/ prefersExtendedRange = YES
@0xced
0xced / ActuallyLocalizedStringForStatusCode.m
Created November 15, 2017 15:40
Get a *localized* string for a given HTTP status code
#import <Foundation/Foundation.h>
static NSString * _Nonnull ActuallyLocalizedStringForStatusCode(NSInteger statusCode)
{
static NSBundle *cfNetworkBundle;
static dispatch_once_t once;
dispatch_once(&once, ^{
cfNetworkBundle = [NSBundle bundleForClass:NSHTTPURLResponse.class];
});
NSString *httpError = [NSHTTPURLResponse localizedStringForStatusCode:statusCode];
import Foundation
final class Sample: NSObject {
@objc dynamic var name: String = ""
}
class MyObj: NSObject {
@objc dynamic var test: String = ""
}
extension NSObjectProtocol where Self: NSObject {
@mhaseebkhan
mhaseebkhan / UDID.m
Last active January 11, 2017 05:48
Get UDID with AirWatch MDM
// UDID is no longer available in iOS 6+ due to security / privacy reasons. It can't be retreived the old way
// even when AirWatch MDM is used, because, the APIs are not available.
// However, in order to find more info from AirWatch for the enrolled device and the associated user, we need
// to have UDID, Serial Number or Mac Address which can't be accessed directly either.
// During the installation process, AirWatch pushes a profile and certificate to the user's device which
// contains the UDID.
// This operates on the assumption that AirWatch is configured to push the UDID to the device during the
@0xced
0xced / copy-reveal-dylib.sh
Last active March 15, 2016 15:11
Copy and codesign libReveal.dylib in Debug configuration (for use in a run script build phase)
#!/bin/bash -e
if [ "${CONFIGURATION}" != "Debug" ]; then
exit 0
fi
REVEAL_APP_PATH=$(mdfind -onlyin / "kMDItemCFBundleIdentifier == com.ittybittyapps.Reveal" | head -n 1)
if [ ! -d "${REVEAL_APP_PATH}" ]; then
echo "warning: Reveal.app not found."
exit 0
@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
@chriseidhof
chriseidhof / routes.swift
Created August 17, 2014 21:04
Type-safe routes in Swift
//
// main.swift
// Routes
//
// Created by Chris Eidhof on 17/08/14.
// Copyright (c) 2014 Chris Eidhof. All rights reserved.
//
import Foundation