Skip to content

Instantly share code, notes, and snippets.

View byaruhaf's full-sized avatar
🏄
Surfing Xcode

Franklin Byaruhanga byaruhaf

🏄
Surfing Xcode
View GitHub Profile
import UIKit
typealias JSON = [String : Any]
fileprivate let imageCache = NSCache<NSString, UIImage>()
extension NSError {
static func generalParsingError(domain: String) -> Error {
return NSError(domain: domain, code: 400, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("Error retrieving data", comment: "General Parsing Error Description")])
}
}
@ddunbar
ddunbar / xcbuild-debugging-tricks.md
Last active May 7, 2025 03:45
Xcode new build system debugging tricks

New Build System Tricks

Command Line

alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
# THIS DOESNT WORK YET: xcbuild openIDEConsole  # … then switch to Xcode ➡️
xcbuild showSpecs
xcbuild build <foo.pif> [—target <target>]
@ddunbar
ddunbar / Xcode-user-defaults
Last active September 28, 2023 17:03
Xcode user defaults
# Enable timings on build operations
defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES
# Enable extensive per-task timings
defaults write com.apple.dt.Xcode IDEBuildOperationTimingLogLevel -int 3
# Enable old build system logging for "implicit dependencies"
defaults write com.apple.dt.Xcode IDEBuildOperationDependenciesLogLevel -int 3
# Show logs from the "prebuild" step
@nyg
nyg / MemoryAddress.swift
Last active July 9, 2024 03:38
Get the memory address of both class and structure instances in Swift.
// https://stackoverflow.com/a/45777692/5536516
import Foundation
struct MemoryAddress<T>: CustomStringConvertible {
let intValue: Int
var description: String {
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size
@biggers
biggers / py_syslog_dict_config.py
Last active April 27, 2025 04:53
Python dictConfig logging example using SyslogHandler - modified from Stackoverflow answer
import logging
import sys
from logging import config
# REF, modified from:
# https://stackoverflow.com/a/19367225
if sys.platform == "darwin":
address = '/var/run/syslog'
facility = 'local1'
@marcosgriselli
marcosgriselli / AudioLoader.swift
Created October 2, 2017 04:21
Play an audio file from resources or .xcassets
import AVFoundation
var audioPlayer: AVAudioPlayer?
enum AudioLoader {
case fromResource(URL)
case fromAsset(NSDataAsset)
}
enum AudioLoaderError: Error {
case resourceNotFound
@mvnrc
mvnrc / breakpoint.png
Last active November 1, 2023 13:26
Print current UIViewController class name on viewDidAppear in debug console in Xcode (Swift/Objective-C)
breakpoint.png
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active May 9, 2025 09:50
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

@dangets
dangets / BasicRetrofitMoshiDemo.java
Last active September 25, 2023 19:39
Basic example of using Retrofit and Moshi
package com.dangets;
import com.squareup.moshi.Json;
import com.squareup.moshi.Moshi;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
@jeromy-vandusen-obs
jeromy-vandusen-obs / DockerSwarmCheatSheet.md
Last active March 3, 2025 13:29
Docker Swarm Cheat Sheet

Docker Swarm Cheat Sheet

Initialize the local Docker service as a swarm manager. As a guideline, in production you should have 3 to 5 managers. Swarm is managed through port 2377, which should be blocked from external access.

$ docker swarm init

Join an existing swarm as a worker node. Replace $SWARM_MANAGER with the IP address or domain name of a swarm manager node.