Skip to content

Instantly share code, notes, and snippets.

@sbooth
sbooth / docc.yaml
Created May 8, 2024 15:35
DocC GitHub workflow
name: DocC
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
@sbooth
sbooth / Data+convertedTo.swift
Created June 29, 2021 11:36
A method for converting `Data` to `AVAudioPCMBuffer `
func data_AudioFile_ReadProc(_ inClientData: UnsafeMutableRawPointer, _ inPosition: Int64, _ requestCount: UInt32, _ buffer: UnsafeMutableRawPointer, _ actualCount: UnsafeMutablePointer<UInt32>) -> OSStatus {
let data = inClientData.assumingMemoryBound(to: Data.self).pointee
let bufferPointer = UnsafeMutableRawBufferPointer(start: buffer, count: Int(requestCount))
let copied = data.copyBytes(to: bufferPointer, from: Int(inPosition) ..< Int(inPosition) + Int(requestCount))
actualCount.pointee = UInt32(copied)
return noErr
}
func data_AudioFile_GetSizeProc(_ inClientData: UnsafeMutableRawPointer) -> Int64 {
let data = inClientData.assumingMemoryBound(to: Data.self).pointee
@sbooth
sbooth / NSArray+SFBFunctional.h
Created February 10, 2021 13:50
Functional methods for NSArray
//
// Copyright (c) 2020 - 2021 Stephen F. Booth <me@sbooth.org>
// MIT license
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSArray<ObjectType> (SFBFunctional)
@sbooth
sbooth / CMakeLists.txt
Last active October 15, 2018 01:19
MAC_SDK_435 CMake
cmake_minimum_required (VERSION 2.6)
project (libmac)
set(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Directory for architecture-dependent files")
set(BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" CACHE PATH "Directory for user executables")
set(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib" CACHE PATH "Ddirectory for object code libraries")
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Directory for header files")
add_definitions(-DPLATFORM_APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
@sbooth
sbooth / cloudflared
Last active April 15, 2022 18:30
dnsmasq with dnscrypt-proxy + cloudflared
# /etc/logrotate.d/cloudflared
/var/log/cloudflared/cloudflared.log {
rotate 7
daily
compress
missingok
notifempty
}
extension String {
func snake_cased() -> String {
let re = try! NSRegularExpression(pattern: "((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))")
let s = re.stringByReplacingMatches(in: self, range: NSMakeRange(0, (self as NSString).length), withTemplate: "_$1")
return s.lowercased()
}
}
@sbooth
sbooth / UnsafeMutablePointerTest.swift
Created November 3, 2016 12:06
Test the behavior of UnsafeMutablePointer.initialize(to:)
import Foundation
class Test {
init() {
print("init")
}
deinit {
print("deinit")
}
}
- (BOOL)_enumerateIndexedValuesInColumn:(NSString *)column matchingQuery:(YapDatabaseQuery *)query
usingBlock:(void (^)(id indexedValue, BOOL *stop))block
{
if (column == nil) return NO;
if (query == nil) return NO;
if (query.isAggregateQuery) return NO;
// Create full query using given filtering clause(s)
NSString *fullQueryString =
@sbooth
sbooth / gist:36f8df95ae36d56908a9
Created April 12, 2015 13:38
pointerToString
func pointerToString(objRef: AnyObject) -> String {
let ptr: COpaquePointer = Unmanaged<AnyObject>.passUnretained(objRef).toOpaque()
return "\(ptr)"
}
@sbooth
sbooth / qdEAFConvert.cpp
Created March 24, 2010 13:01
Convert to ALAC
#include <CoreFoundation/CoreFoundation.h>
#include <AudioToolbox/AudioToolbox.h>
#include "CAStreamBasicDescription.h"
#define BUFFER_SIZE_FRAMES 512
static AudioBufferList *
allocateBufferList(UInt32 channelsPerFrame, UInt32 bytesPerFrame, bool interleaved, UInt32 capacityFrames)
{