Skip to content

Instantly share code, notes, and snippets.

View hannesoid's full-sized avatar

Hannes Oud hannesoid

View GitHub Profile
@adison
adison / outlineview.m
Last active January 14, 2022 06:14
make source list style nsoutlineview programmatically
NSScrollView* container = [[NSScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
container.hasVerticalScroller = YES;
container.hasHorizontalScroller = YES;
container.wantsLayer = YES;
container.identifier = [@(LOGVIEW_OFFSET + i) stringValue];
NSClipView* clipview = [[NSClipView alloc] init];
clipview.autoresizesSubviews = YES;
clipview.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
@mminer
mminer / getMACAddress.swift
Created February 1, 2017 19:13
Finds the machine's MAC address.
import Foundation
import IOKit
func getMACAddress() -> String {
let matching = IOServiceMatching("IOEthernetInterface") as NSMutableDictionary
matching[kIOPropertyMatchKey] = ["IOPrimaryInterface": true]
var servicesIterator: io_iterator_t = 0
defer { IOObjectRelease(servicesIterator) }
guard IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &servicesIterator) == KERN_SUCCESS else {
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active November 19, 2024 05:05
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

@hayakawa
hayakawa / run_antelope.sh
Last active January 6, 2020 23:53
[ ATTENTION!: This script will be unnecessary just now! / See also: https://en.antelopeaudio.com/2020/01/antelope-audio-product-compatibility-with-macos-catalina/ ]Little code to run Antelope Launcher and Server on MacOS Catalina
#!/bin/bash
### Get my uid
UserID=`id -u`
echo "Your UID: ${UserID}"
### Unload root process
sudo launchctl unload /Library/LaunchDaemons/com.antelopeaudio.daemon.plist
### Kill the process if it was already awaken
@smic
smic / BorderlessWindow.swift
Last active July 7, 2023 20:19
Extension to create borderless windows in SwiftUI
import SwiftUI
extension CGRect {
fileprivate func point(anchor: UnitPoint) -> CGPoint {
var point = self.origin
point.x += self.size.width * anchor.x
#if os(macOS)
point.y += self.size.height * (1 - anchor.y)
#else
point.y += self.size.height * anchor.y
@jverkoey
jverkoey / UIFont+CustomizedDynamicType.m
Created April 14, 2021 01:07
Dynamic Type system fonts with custom point sizes, weight, and italics
static const CGFloat kFontWeightEpsilon = FLT_EPSILON;
@implementation UIFont (CustomizedDynamicType)
+ (nonnull UIFont *)preferredFontWithDefaultSize:(CGFloat)size
textStyle:(nonnull UIFontTextStyle)textStyle {
return [self preferredFontWithDefaultSize:size
textStyle:textStyle
fontWeight:UIFontWeightRegular
italic:NO];
@CDRussell
CDRussell / .zshrc
Last active December 22, 2021 11:28
# Git branch in command prompts
autoload -Uz vcs_info
precmd() {vcs_info}
setopt PROMPT_SUBST
# the last part of this command dictates what is shown for git info, referenced later by the prompt command.
# here, showing branch name %b in color 38 (blue) and the repo name %r in color 226 (yellow)
zstyle ':vcs_info:git:*' formats '%F{38}%b%f %F{226}(%r)%f'
# can set both the left (PROMPT) and right (RPROMPT) prompts
@manmal
manmal / AsyncSequenceExtensions.swift
Created July 6, 2022 16:57
AsyncSequence.eraseToAsyncStream()
import Foundation
// Props to @pteasima and @MichalKleinJr:
// https://twitter.com/pteasima/status/1544723987606929408?s=21&t=JL1oIuL87Ms_VPBQBZQ7Rg
public extension AsyncSequence {
func eraseToAsyncStream() -> AsyncStream<Element> {
return AsyncStream { continuation in
let task = Task {
do {
for try await value in self {
@manmal
manmal / TaskAutoCancellation.swift
Last active July 27, 2022 20:52
Swift Structured Concurrency - Task Auto Cancellation
public extension Task {
/// Cancels this `Task` when the surrounding `Task` is cancelled.
/// This is necessary if `Task {}` and `Task.detached {}`
/// should be automatically cancelled - otherwise, such Tasks
/// just run until finished.
///
/// Usage:
///
/// await Task { await myAsyncFunc() }.autoCancel()
func autoCancel() async -> Void {
@lukaskubanek
lukaskubanek / SwiftUIListRowHighlightFix.swift
Last active March 26, 2024 17:51
A workaround for fixing SwiftUI’s list row highlighting behavior by preventing unwanted delays
import InterposeKit
import SwiftUI
/// A workaround for an issue in SwiftUI related to delayed highlighting of list rows upon user
/// interaction, rendering it inconsistent with UIKit.
///
/// This fix implements the solution proposed by Léo Natan and utilizes `InterposeKit` by Peter
/// Steinberger to modify the behavior of `UICollectionViewCell` instances used internally
/// by SwiftUI.
///