Skip to content

Instantly share code, notes, and snippets.

@edwardean
edwardean / carthage.copy-frameworks.rb
Created October 14, 2017 16:59 — forked from jongraves/carthage.copy-frameworks.rb
carthage copy-frameworks conditionally Xcode build step
built_products_dir = ENV["BUILT_PRODUCTS_DIR"]
frameworks_folder_path = ENV["FRAMEWORKS_FOLDER_PATH"]
srcroot = ENV["SRCROOT"]
dest = File.join(built_products_dir, frameworks_folder_path)
platform = ENV["PLATFORM_DISPLAY_NAME"]
carthage_frameworks_dir = File.join(srcroot, 'Carthage', 'Build', platform)
input_file_count = ENV["SCRIPT_INPUT_FILE_COUNT"].to_i
env = {"SCRIPT_INPUT_FILE_COUNT" => "0"}
@edwardean
edwardean / XCDUUID.m
Created August 29, 2017 08:44 — forked from OliverLetterer/XCDUUID.m
With this gist, I, as a total assembly noob, am trying to understand the XCDUUID runtime hack (https://github.com/0xced/NSUUID/blob/1.0.1/NSUUID.m#L167-L221) to be able to use NSUUID on iOS < 6.0.
@implementation XCDUUID
+ (void) load
{
// query runtime if NSUUID class already exists, if so => done
if (objc_getClass("NSUUID"))
{
return;
}
@edwardean
edwardean / sed cheatsheet
Created August 2, 2017 02:35 — forked from cvega/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@edwardean
edwardean / combine_static_libraries.sh
Created July 25, 2017 08:20 — forked from evands/combine_static_libraries.sh
Combine multiple .a static libraries, which may each have multiple architectures, into a single static library
#!/bin/sh
# Combined all static libaries in the current directory into a single static library
# It is hardcoded to use the i386, armv7, and armv7s architectures; this can easily be changed via the 'archs' variable at the top
# The script takes a single argument, which is the name of the final, combined library to be created.
#
# For example:
# => combine_static_libraries.sh combined-library
#
# Script by Evan Schoenberg, Regular Rate and Rhythm Software
@edwardean
edwardean / KeyboardLayoutGuide.swift
Created July 20, 2017 16:16 — forked from myell0w/KeyboardLayoutGuide.swift
A UILayoutGuide that follows the Keyboard on iOS
import Foundation
import UIKit
/// Used to create a layout guide that pins to the top of the keyboard
final class KeyboardLayoutGuide {
private let notificationCenter: NotificationCenter
private let bottomConstraint: NSLayoutConstraint
@edwardean
edwardean / ThreadSafeProxy.h
Created July 16, 2017 16:03 — forked from Tricertops/ThreadSafeProxy.h
Simple and effective thread-safe proxy that forwards all method invocations inside a locked scope. Definitely not the fastest thread-safe implementation ever.
@import Foundation;
@interface NSObject (ThreadSafeProxy)
- (instancetype)threadSafe;
@end
@edwardean
edwardean / CustomURLProtocol.swift
Created April 13, 2017 01:48 — forked from aerickson14/CustomURLProtocol.swift
Custom URLProtocol monitoring URLRequests over a URLSession in Swift 3
import UIKit
class CustomURLProtocol: URLProtocol {
struct Constants {
static let RequestHandledKey = "URLProtocolRequestHandled"
}
var session: URLSession?
var sessionTask: URLSessionDataTask?
@edwardean
edwardean / gist:11ff3883e6d89d195e3cf1ae03cf0e95
Created March 2, 2017 08:15 — forked from bryanluby/gist:8773920
Resign first responder from anywhere.
// Make sure viewDidAppear has happened before sending this action to ensure that all links
// in the responder chain are connected.
// http://stackoverflow.com/a/11768282/1306872
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)
to:nil
from:nil
forEvent:nil];
if [ $CONFIGURATION == Release ]; then
echo "Bumping build number..."
plist=${PROJECT_DIR}/${INFOPLIST_FILE}
# increment the build number (ie 115 to 116)
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "No build number in $plist"
exit 2
fi
func sumRecursively(numbers: [Int], _ acc:Int = 0) -> Int {
if let head = numbers.first {
let tail = Array(dropFirst(numbers))
return sumRecursively(tail, head + acc)
} else {
return acc
}
}
let myNumbers = [1,2,3,4,5]