Skip to content

Instantly share code, notes, and snippets.

Avatar

Tim Johnsen timonus

  • Instagram
  • Bay Area, CA
  • Twitter @timonus
View GitHub Profile
@timonus
timonus / SFSafariViewController+ContextMenuBugWorkaround.m
Last active Aug 20, 2020
Workaround for SFSafariViewController preview + iOS 13 Context Menu negative interaction bug (FB7564018)
View SFSafariViewController+ContextMenuBugWorkaround.m
// Workaround for SFSafariViewController preview + iOS 13 context menu negative interaction bug (FB7564018)
// Examples: https://db.tt/hvBJOBdZwL, https://db.tt/egp20bSfS0
// With fix: https://db.tt/r5nCLNYbfs
@interface SFSafariViewController (ContextMenuBugWorkaround)
/// If this returns @c YES it's safe to present this view controller when "committing" from an iOS 13 context menu. If not, you should create a fresh @c SFSafariViewController and present that instead.
- (BOOL)canBePresentedOnContextMenuCompletion;
@end
@timonus
timonus / programmatic-dynamic-images.m
Last active Nov 11, 2021
Programmatically create iOS 13 dynamic images
View programmatic-dynamic-images.m
- (UIImage *)dynamicImage
{
UITraitCollection *const baseTraitCollection = /* an existing trait collection */;
UITraitCollection *const lightTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]]];
UITraitCollection *const purelyDarkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
UITraitCollection *const darkTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, purelyDarkTraitCollection]];
__block UIImage *lightImage;
[lightTraitCollection performAsCurrentTraitCollection:^{
lightImage = /* draw image */;
@timonus
timonus / bookmarklet.js
Created Jun 21, 2017
Redirector Bookmarklet
View bookmarklet.js
// This redirects to a page that contains a link to the page currently being viewed, which can be useful for debugging things.
// Instructions: Create a bookmark then edit its address to be this.
// Video: https://db.tt/DaXP7t66KN
javascript:location.href='https://u121985.dl.dropboxusercontent.com/u/121985/redirect-link.html?url='+encodeURIComponent(location.href);
View UITraitCollection+DarknessCompatibility.m
//
// UITraitCollection+DarknessCompatibility.h
// Tangent
//
// Created by Tim Johnsen on 6/25/16.
// Copyright © 2016 tijo. All rights reserved.
//
#import <UIKit/UIKit.h>
View UIWindow+AppSwitchScrollStopper.h
// UIWindow+AppSwitchScrollStopper.h
// Created by Tim Johnsen on 3/27/16.
#import <UIKit/UIKit.h>
@interface UIWindow (AppSwitchScrollStopper)
/// Call this early on in your app's lifecycle to avoid
/// scroll-related flashing when your app resumes from the background
- (void)installAppSwitchScrollStopper;
@timonus
timonus / TJLogoView.h
Created Sep 10, 2015
tijo Logo Objective-C Source
View TJLogoView.h
//
// TJLogoView.h
// Logo
//
// Created by Tim Johnsen on 9/7/15.
// Copyright (c) 2015 tijo. All rights reserved.
//
#import <UIKit/UIKit.h>
@timonus
timonus / kill.rb
Created Aug 20, 2015
Deletes all yer iOS simulators
View kill.rb
#!/usr/bin/env ruby
device_types_output = `xcrun simctl list devicetypes`
device_types = device_types_output.scan /(.*) \((.*)\)/
runtimes_output = `xcrun simctl list runtimes`
runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/
devices_output = `xcrun simctl list devices`
devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/
@timonus
timonus / class-hierarchy.py
Created Jan 16, 2015
Class Hierarchy Visualizer
View class-hierarchy.py
import sys
import subprocess
import re
import os
import shutil
import json
# usage
# python class-hierarchy.py *directory to scan within*
# outputs nested json
@timonus
timonus / visualize-ipa.py
Last active Jul 24, 2016
.ipa Visualizer
View visualize-ipa.py
import sys
import subprocess
import re
import os
import shutil
if len(sys.argv) < 2:
print "No path specified"
sys.exit()
@timonus
timonus / bookmarklets
Last active Aug 29, 2015
Bookmarklets
View bookmarklets
Open Tweet in Tweetbot:
javascript:var url = window.location;var tweetRegex = new RegExp('https?://(www.|mobile.)?twitter.com/.*/status/([0-9]{18})(/.*)?');var tweetIdentifier = url.match(tweetRegex)[2];window.location='tweetbot:///status/' + tweetIdentifier;