Skip to content

Instantly share code, notes, and snippets.

View daniel-beard's full-sized avatar

Daniel Beard daniel-beard

View GitHub Profile
@stevenp
stevenp / gist:a6740694b4e23baccfab
Last active September 10, 2015 23:26
Disable App Transport Security in iOS 9
Add this to the Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
@jpr5
jpr5 / bot.rb
Created April 26, 2011 07:13
XMPP/Ruby Bot for HipChat
#!/usr/bin/env ruby
#
# Script: HipChat bot in Ruby
# Author: Jordan Ritter <jpr5@darkridge.com>
#
unless `rvm-prompt i g`.chomp == "ree@xmpp"
exec("rvm ree@xmpp ruby #{$0}")
end

Xcode loads xcspec files (ascii plists) that specify everything (tools, buildphases, compilers, rules, etc) based on a set of conditions.

To evaluate these conditions you have to load these files and simulate the build process and construct your own "environment"

The target's build settings will help to resolve most of the environment variables by taking the basics from the particular platform you are using for the target (resolved from the SDKROOT value xcrun --show-sdk-platform-path --sdk)

when you load the spec of the compiler there is a key on it called "Options" which is an array of dictionaries that have

@lucholaf
lucholaf / gist:e37f4d26e406250a156a
Last active September 5, 2016 15:06
Xcode pre-action: generate Swift FAT file to reduce compilation time, since it's faster to recompile the whole source code in a single file
> $PROJECT_DIR/merge.swift; find $PROJECT_DIR/ -iname *.swift -not -name merge.swift -exec cat {} >> $PROJECT_DIR/merge.swift \;
import Darwin
extension Int {
static func random() -> Int {
return Int(arc4random())
}
static func random(range: Range<Int>) -> Int {
return Int(arc4random_uniform(UInt32(range.endIndex - range.startIndex))) + range.startIndex
}
@nicklockwood
nicklockwood / gist:9605636
Last active December 11, 2019 15:17
Singleton Category implementation
Singleton.h
-------------
@protocol Singleton
@optional
+ (instancetype)sharedInstance;
@end
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)
}
init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern
@tonyarnold
tonyarnold / RangeReplaceableCollectionOperators.swift
Created August 25, 2020 13:29
Use this to add an operator to append items to sequences, ie: `collection += item`
extension RangeReplaceableCollection {
static func += (collection: inout Self, element: Element) {
collection.append(element)
}
static func += (collection: inout Self, element: Element?) {
if let element = element {
collection.append(element)
}
}
@nkuln
nkuln / cxa_throw_replace_backtrace.c
Created March 12, 2012 09:18
Override __cxa_throw and prints backtrace when exception is thrown (Linux)
#include <dlfcn.h>
#include <execinfo.h>
typedef void (*cxa_throw_type)(void *, void *, void (*) (void *));
cxa_throw_type orig_cxa_throw = 0;
void load_orig_throw_code()
{
orig_cxa_throw = (cxa_throw_type) dlsym(RTLD_NEXT, "__cxa_throw");
}
@amirdew
amirdew / ModifyCodable.swift
Last active March 26, 2023 06:27
Modifying private and immutable properties (let) in Codable instances
import Foundation
extension Decodable where Self: Encodable {
/// Creates a new instance and changes the value for the provided key.
///
/// - Parameters:
/// - key: The key path to the property that you want to modify.
/// Use period to separate levels and [] for indexes.
/// Examples: "id", "name.firstName", "children[2].name.firstName"
///