Skip to content

Instantly share code, notes, and snippets.

View andreacipriani's full-sized avatar

Andrea Cipriani andreacipriani

  • New York
View GitHub Profile
@kopiro
kopiro / defaults_diff.sh
Last active May 16, 2022 17:06
Get notification when preference from `defaults` change
cmd="defaults read"; left=$(eval $cmd); while true; do right=$(eval $cmd); diff <( printf '%s' "$left") <( printf '%s' "$right"); left="$right"; sleep 1; done
@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

# No results from tests or mocks files:
Workspace - None of the following conditions are met - Filename - matches regex
(.*(Spec|Test|Mock)s?\.)|(Mock).*
# Only search in swift files:
Workspace - All of the following conditions are met - File Extension - is Equal to
swift
@JohnSundell
JohnSundell / Perform.swift
Last active December 21, 2019 14:43
A function that enables you to easily wrap throwing APIs, to provide a custom error
/**
* Perform a throwing expression, and throw a custom error in case the expression threw
*
* - parameter expression: The expression to execute
* - parameter error: The custom error to throw instead of the expression's error
* - throws: The given error
* - returns: The return value of the given expression
*/
func perform<T>(_ expression: @autoclosure () throws -> T, orThrow errorExpression: @autoclosure () -> Error) throws -> T {
do {
@kgn
kgn / AppReviews
Created June 9, 2015 23:02
App Reviews - Python script to retrieve App Store reviews and save them to a CSV file
#!/usr/bin/env python
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import json
@MugunthKumar
MugunthKumar / NSURLRequest+cURL
Created May 5, 2015 04:05
NSURLRequest cURL description
- (NSString *)description {
__block NSMutableString *displayString = [NSMutableString stringWithFormat:@"curl -v -X %@", self.HTTPMethod];
[displayString appendFormat:@" \'%@\'", self.URL.absoluteString];
[self.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop) {
[displayString appendFormat:@" -H \'%@: %@\'", key, val];
}];
@mbinna
mbinna / podforceupdate.sh
Created December 4, 2012 09:43
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update