Skip to content

Instantly share code, notes, and snippets.

View a2's full-sized avatar
🐼

Alex Akers a2

🐼
View GitHub Profile
// This is more hacky than it should be!
- (UIModalPresentationStyle)pspdf_currentPresentationStyle {
UIViewController *vc = self.presentedViewController.presentingViewController;
if ([self respondsToSelector:@selector(adaptivePresentationStyleForTraitCollection:)]) {
UIModalPresentationStyle const style = [self adaptivePresentationStyleForTraitCollection:vc.traitCollection];
return (style == UIModalPresentationNone) ? self.presentationStyle : style;
}
// Before iOS 8.3 we have to fall back on assuming adaptivity is only possible for horizontally compact environments.
@robb
robb / Example.m
Last active January 9, 2024 14:38
A macro to convert nullable references to nonnull references while triggering an assert if the expression is actually true. Think of this as unsafe unwrap for Objective-C.
NS_ASSUME_NONNULL_BEGIN
void Log(NSString *foo) {
NSLog(@"%@", foo);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *stuff = @{
@"a": @"Test"
@douglashill
douglashill / covariance.m
Last active November 25, 2016 14:53
A quick look at variance with Objective-C generics. `NSSet` is covariant on its `ObjectType`, while `NSHashTable` is invariant. Contravariance is also supported.
@import Foundation;
@interface ContravariantCollection<__contravariant ObjectType> : NSObject
@end
@implementation ContravariantCollection
@end
void stringSetThing(NSSet<NSString *> *set) {
}
http://itsliveradio.apple.com/streams/beats_one_demo_3/master.m3u8
http://itsliveradio.apple.com/streams/beats_one_demo_3/master.m3u8
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/prog_index.m3u8
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/prog_index.m3u8
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/fileSequence0.aac
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/fileSequence1.aac
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/fileSequence2.aac
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/fileSequence3.aac
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/fileSequence4.aac
http://itsliveradio.apple.com/streams/beats_one_demo_3/256/fileSequence5.aac
import Foundation
extension NSCopying {
func copied() -> Self {
let copied = copyWithZone(nil)
assert(copied is Self, "Invalid downcast while copying instance of \(Self.self), did you mean to use 'as?'")
return unsafeDowncast(copied)
}
import QuartzCore
private func demunge(@noescape fn: CGPath.Element -> Void)(ptr: UnsafePointer<CGPathElement>) {
let points = ptr.memory.points
switch ptr.memory.type {
case kCGPathElementMoveToPoint:
fn(.Move(to: points[0]))
case kCGPathElementAddLineToPoint:
fn(.Line(to: points[0]))
case kCGPathElementAddQuadCurveToPoint:
@JadenGeller
JadenGeller / Lazy Stack Programming.swift
Last active August 29, 2015 14:20
Lazy Stack Based Programming Implementation of a Calculator
// Inspired by this article: http://blogs.msdn.com/b/oldnewthing/archive/2008/01/10/7047497.aspx
// which explains the weird behavior of the percent key on calculators
// We will demonstrate using the stack like a calculator
// to calculate (150 + 1000) - 10% = (150 + 1000) * (1 - 10/100) = 1035
var stack = Stack() // []
stack.push(150) // [150]
stack.push(1000) // [150, 1000]
stack.push(add) // [150, 1000, add]
stack.push(10) // [150, 1000, add, 10]
/System/Library/AccessibilityBundles/AXSpeechImplementation.bundle/AXSpeechImplementation
/System/Library/AccessibilityBundles/AccessibilitySettingsLoader.bundle/AccessibilitySettingsLoader
/System/Library/AccessibilityBundles/MapKitFramework.axbundle/MapKitFramework
/System/Library/AccessibilityBundles/UIKit.axbundle/UIKit
/System/Library/BulletinBoardPlugins/NanoMailDataProvider.bundle/NanoMailDataProvider
/System/Library/BulletinBoardPlugins/SMSBBPlugin.bundle/SMSBBPlugin
/System/Library/Caches/com.apple.xpc//sdk.dylib
/System/Library/Caches/com.apple.xpcd/xpcd_cache.dylib
/System/Library/CoreServices/Encodings/libArabicConverter.dylib
/System/Library/CoreServices/Encodings/libCyrillicConverter.dylib
@daxadax
daxadax / burgerbot.rb
Last active April 13, 2022 09:20
burgerbot
#!/usr/bin/env ruby
# modified from https://gist.github.com/pbock/3ab260f3862c350e6b5f #
require 'watir-webdriver'
class BurgerBot
def initialize
@attempt_count = 0