Skip to content

Instantly share code, notes, and snippets.

View danwood's full-sized avatar

Dan Wood danwood

View GitHub Profile
@danwood
danwood / gist:1513093
Created December 23, 2011 04:03
Scroll the the bottom if you are at the bottom
- (void) scrollToVisible:(id)unused
{
// Only show bottom if we are already scrolled down at/near the bottom.
NSScrollView *scrollView = [oLog enclosingScrollView];
NSPoint currentScrollPosition=[[scrollView contentView] bounds].origin;
float diff = oLog.frame.size.height - (scrollView.contentSize.height + currentScrollPosition.y);
if (diff < 50) // Seems like it's often 39 when we're at the bottom, so give some slack.
{
// [oLog scrollRangeToVisible:NSMakeRange([[oLog textStorage] length], 0)];
@danwood
danwood / gist:2481732
Created April 24, 2012 17:27
Base 64 Encoding/Decoding
+ (NSData *)dataWithBase64EncodedString:(NSString *)base64String
{
NSData *retVal = nil;
if([base64String canBeConvertedToEncoding:NSASCIIStringEncoding])
{
NSData *stringData = [base64String dataUsingEncoding: NSASCIIStringEncoding];
/* base64 decode
* in -- input data
- (void)ks_tryToMakeObjectsPerformSelector:(SEL)selector withObject:(id)object;
{
for (id <NSObject> anObject in self)
{
if ([anObject respondsToSelector:selector])
{
[anObject performSelector:selector withObject:object];
}
}
}
@danwood
danwood / SpotifyAPIExampleApp-PKCE.patch
Last active January 23, 2024 19:45
Patch Peter-Schorn/SpotifyAPIExampleApp to use Authorization Code Flow with PKCE, for users of Peter-Schorn/SpotifyAPI
diff -crB -x S SpotifyAPIExampleApp-main/SpotifyAPIExampleApp/Model/Spotify.swift SpotifyAPIExampleApp-PKCE/SpotifyAPIExampleApp/Model/Spotify.swift
*** SpotifyAPIExampleApp-main/SpotifyAPIExampleApp/Model/Spotify.swift Thu Feb 16 22:38:40 2023
--- SpotifyAPIExampleApp-PKCE/SpotifyAPIExampleApp/Model/Spotify.swift Tue Jan 23 11:35:44 2024
***************
*** 22,35 ****
fatalError("Could not find 'CLIENT_ID' in environment variables")
}()
- private static let clientSecret: String = {
- if let clientSecret = ProcessInfo.processInfo
@danwood
danwood / EmojiRender.swift
Last active July 3, 2024 17:18
macOS/iOS class for rendering emoji as a bitmap
//
// EmojiRender.swift
// ResponsiveDesignExamples
//
// Created by Dan Wood on 7/1/24.
//
import SwiftUI
import CoreGraphics
@danwood
danwood / gist:c53ede641cf5d95d110f3f8d480bba33
Created January 14, 2025 01:49
SwiftUI View minimumFontWidth function and testing code
//
// ContentView.swift
// ViewThatfits
//
// Created by Dan Wood on 1/13/25.
//
import SwiftUI
struct TextCondenser<Content: View>: View {
@danwood
danwood / SynchronizedScrollViews.swift
Last active March 8, 2025 15:35
SwiftUI synchronized ScrollViews — based on code from Phil Zakharchenko's blog
struct MultiColumnSyncedScrollDemo: View {
let scrollViewCount: Int = 5
@State private var scrollPositions: [ScrollPosition] = [] // Initialized in onAppear, so don't use until body prematurely!
@State private var indexScrolledByUser: Int?
@State private var colors: [Color] = [] // Initially empty
let sampleArrayCount = 40