Skip to content

Instantly share code, notes, and snippets.

View felixvisee's full-sized avatar

Felix Visée felixvisee

View GitHub Profile
@beccadax
beccadax / NSAttributedString+format.m
Created May 5, 2014 20:28
Do simple +stringWithFormat:-type operations with NSAttributedString.
//
// NSAttributedString+format.m
// Chatterbox
//
// Created by Brent Royal-Gordon on 2/7/14.
// Copyright (c) 2014 Architechies. All rights reserved.
//
#import "NSAttributedString+format.h"
@quellish
quellish / Foo.m
Created August 29, 2014 05:58
UIResponder Informal Protocol
/**
Informal protocol that traverses the responder chain until a concrete class provides
an instance of NSManagedObjectContext. If no responder provides on, UIApplication is extended to forward
the request to it's delegate. We extend the UIApplicationDelegate to add this new behavior.
Concrete responders can provide optional implementations of managedObjectContext. For example, a responder such as
a view may call [self managedObjectContext], which would start walking up the responder chain. When it gets to the view controller that owns the view, the view controller may have a concrete implementation of managedObjectContext. This can be a property, or a method that creates a new context, etc. The instance vended by the view controller method is what the view that called [self managedObjectContext] gets as a response from that method.
Both the responder chain and informal protocols are incredible powerful concepts that are often under utilized by developers outside of Apple.
@DerLobi
DerLobi / pre-commit
Last active May 9, 2022 09:45
Don't commit focused tests. Use this as a pre-commit hook and the commit won't succeed if you have staged changes that contain `fdescribe`, `fcontext`, `fit`, `fspecify` or `fexample`. Copy this file as `pre-commit` into the `.git/hooks` folder of your repository (create it if neccessary) and chmod +x the file.
#!/bin/sh
#
# This pre-commit hook looks for `fdescribe`, `fcontext`, `fit`, `fspecify` and `fexample` in the
# staged files and exits with an error code of 1 if there are such changes.
#
STATUS=0
DESCRIBEFILES=$(git diff --staged -G"^\s*fdescribe\(" --name-only | wc -l)
if [ $DESCRIBEFILES -gt 0 ]
@zwaldowski
zwaldowski / Activity.swift
Last active June 10, 2024 15:22
os_activity_t for Swift 3
//
// Activity.swift
//
// Created by Zachary Waldowski on 8/21/16.
// Copyright © 2016 Zachary Waldowski. Licensed under MIT.
//
import os.activity
private final class LegacyActivityContext {
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 12, 2024 03:33
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