Skip to content

Instantly share code, notes, and snippets.

View OliverLetterer's full-sized avatar
👨‍💻
Happy coding :)

Oliver Letterer OliverLetterer

👨‍💻
Happy coding :)
View GitHub Profile
@arturgrigor
arturgrigor / Podfile
Created September 10, 2018 09:55
Sample Podfile for silencing warnings for CocoaPods dependencies
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target '%TargetName%' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for %TargetName%
# pod 'FBSDKCoreKit'
end
@sjoerdvisscher
sjoerdvisscher / minimal.swift
Created June 28, 2017 14:42
Using Decodable to generate a minimal value
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
@mayoff
mayoff / FormatOptions.swift
Last active February 10, 2017 05:16
Avoiding duplication of property names
// For https://twitter.com/nicklockwood/status/819938181483233285
protocol Withable {
init()
}
extension Withable {
func with(_ body: (inout Self) -> ()) -> Self {
var copy = self
body(&copy)
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@modocache
modocache / gist:2ef5e3916b97b97a1aa9e0126208aea9
Created March 30, 2016 01:05
Attaching LLDB to a Debug build of Swift
$ lldb -- ../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc -dump-parse ~/GitHub/tmp/hello.swift
(lldb) target create "../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc"
Current executable set to '../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc' (x86_64).
(lldb) settings set -- target.run-args "-dump-parse" "/Users/bgesiak/GitHub/tmp/hello.swift"
(lldb) process launch --stop-at-entry
Process 91478 stopped
* thread #1: tid = 0x1bd329, 0x00007fff5fc01000 dyld`_dyld_start, stop reason = signal SIGSTOP
frame #0: 0x00007fff5fc01000 dyld`_dyld_start
dyld`_dyld_start:
-> 0x7fff5fc01000 <+0>: popq %rdi
@steventroughtonsmith
steventroughtonsmith / main.m
Created March 24, 2016 08:08
Load Mach-O executable at runtime and execute its entry point
void callEntryPointOfImage(char *path, int argc, char **argv)
{
void *handle;
int (*binary_main)(int binary_argc, char **binary_argv);
char *error;
int err = 0;
printf("Loading %s…\n", path);
handle = dlopen (path, RTLD_LAZY);
//Given this:
NSArray *objects = @[@1, @2, @3]
//These are equivalent in behavior
NSNumber *first = [objects objectAtIndex:0]
NSNumber *second = (NSNumber *)CFArrayGetValueAtIndex(objects, 0)
//But is the code that runs the same? Not so much… in the first one we do…
objc_msgSend(objects, <selector reference>, 0)
-> http://sealiesoftware.com/msg/x86-mavericks.html
@felix-schwarz
felix-schwarz / openssl-build.sh
Last active March 19, 2024 03:16 — forked from steipete/openssl-build.h
Updated script that builds OpenSSL for OS X, iOS and tvOS. Bitcode enabled for iOS, tvOS. Updated to build for tvOS, use the latest SDKs, skip installing man pages (to save time), download the OpenSSL source over HTTPS, patch OpenSSL for tvOS to not use fork(). Currently requires Xcode7.1b or later (for the tvOS SDK).
#!/bin/bash
# This script downloads and builds the iOS, tvOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
# https://gist.github.com/foozmeat/5154962
# Peter Steinberger, PSPDFKit GmbH, @steipete.
# Felix Schwarz, IOSPIRIT GmbH, @felix_schwarz.
@steipete
steipete / NSData+PSPDFFoundation.m
Last active March 21, 2017 16:00
Haven't done much with dispatch_io yet so I'd appreciate a few more eyeballs on this. Am I closing things correctly in all error conditions? Are there other knobs I could change to make things even faster? (I know I've been lazy on the NSError's)
static NSData *PSPDFCalculateSHA256FromFileURL(NSURL *fileURL, CC_LONG dataLength, NSError **error) {
NSCParameterAssert(fileURL);
dispatch_queue_t shaQueue = dispatch_queue_create("com.pspdfkit.sha256-queue", DISPATCH_QUEUE_SERIAL);
__block dispatch_io_t readChannel;
void (^processIntError)(int intError) = ^(int intError) {
if (intError != 0) {
PSPDFLogWarning(@"Stream error: %d", intError);
if (error) *error = [NSError errorWithDomain:@"SHA256Error" code:100 userInfo:@{NSLocalizedDescriptionKey: @"failed to open file for calculating SHA256."}];
@carlfish
carlfish / gist:6b9761670a131f821ad5
Last active February 3, 2018 23:21
Why understanding monads is important.

Either and Promises/Futures are useful and I’ll use them next time they’re appropriate. But outside Haskell does their monad-ness matter?

(All code below is written in some made-up Java-like syntax, and inevitably contains bugs/typos. I'm also saying "point/flatMap" instead of "return/bind" because that's my audience. Any correspondance with anything that either be programatically or mathematically useful is coincidental)

What is a monad? A refresher.

A monad is something that implements "point" and "flatMap" correctly.