Skip to content

Instantly share code, notes, and snippets.

View swizzlr's full-sized avatar

Thomas Catterall swizzlr

View GitHub Profile
@swizzlr
swizzlr / profiling_swift_in_linux.md
Created November 15, 2017 19:51
Profiling Swift Apps on Linux

Profiling Swift in Linux

In order to profile memory leakage/heap growth in Swift on Linux, you need to a) run it on Linux b) use a profiling tool.

Docker and Valgrind to the rescue.

Installing Valgrind in a Linux container

We're using the official Swift image here: FROM swift:4.

Keybase proof

I hereby claim:

  • I am swizzlr on github.
  • I am swizzlr (https://keybase.io/swizzlr) on keybase.
  • I have a public key ASA5tzDcY23K608c2PyNL1okwf-hhiGmpFDSlqLbTU6SOwo

To claim this, I am signing this object:

@swizzlr
swizzlr / literalcolor.swift
Created October 14, 2015 13:26
Literal Colors from hex values
public final class LiteralColor: UIColor, IntegerLiteralConvertible {
public typealias IntegerLiteralType = Int
public init(integerLiteral value: Int) {
let netHex = value
let red = (netHex >> 16) & 0xff
let green = (netHex >> 8) & 0xff
let blue = netHex & 0xff
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
@swizzlr
swizzlr / TestRealm.swift
Created September 2, 2015 14:40
Isolate those realms
// Creates a new in memory realm for testing
internal func NewTestRealm() -> Realm {
let idString = NSUUID().UUIDString
let config = Realm.Configuration(inMemoryIdentifier: idString)
return try! Realm(configuration: config)
}
import RealmSwift
import Foundation
@swizzlr
swizzlr / moya-patch.diff
Created August 22, 2015 22:02
Small patch for Moya in Swift 2.
diff --git a/vendor/Moya/Moya/ReactiveCocoa/RACSignal+Moya.swift b/vendor/Moya/Moya/ReactiveCocoa/RACSignal+Moya.swift
index faabbf4..55d0420 100755
--- a/vendor/Moya/Moya/ReactiveCocoa/RACSignal+Moya.swift
+++ b/vendor/Moya/Moya/ReactiveCocoa/RACSignal+Moya.swift
@@ -67,21 +67,20 @@ public extension RACSignal {
/// Maps data received from the signal into a JSON object. If the conversion fails, the signal errors.
public func mapJSON() -> RACSignal {
- return tryMap({ (object, error) -> AnyObject! in
+ return tryMap({ (object, retError) -> AnyObject! in
@swizzlr
swizzlr / gist:30c7de9d05b39b1da3dc
Created May 21, 2015 17:29
Swift AST Node Types
source.lang.swift.decl.function.free
source.lang.swift.ref.function.free
source.lang.swift.decl.function.method.instance
source.lang.swift.ref.function.method.instance
source.lang.swift.decl.function.method.static
source.lang.swift.ref.function.method.static
source.lang.swift.decl.function.method.class
source.lang.swift.ref.function.method.class
source.lang.swift.decl.function.accessor.getter
source.lang.swift.ref.function.accessor.getter
@swizzlr
swizzlr / CommonWarnings.xcconfig
Last active August 29, 2015 14:19
Pixable Warnings and Errors
// Warnings
WARNING_CFLAGS = -Weverything -Wno-error-auto-import -Wno-error-documentation-unknown-command -Wno-error-super-class-method-mismatch -Wno-error-incomplete-module -Wno-objc-missing-property-synthesis -Wno-gnu -Wno-error-undef -Wno-error-receiver-is-weak -Wno-error-missing-variable-declarations -Wno-error-objc-interface-ivars -Wno-error-documentation
GCC_WARN_PEDANTIC = YES
GCC_TREAT_WARNINGS_AS_ERRORS = YES
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
CLANG_WARN_EMPTY_BODY = YES
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
GCC_WARN_SHADOW = YES
CLANG_WARN_BOOL_CONVERSION = YES
@swizzlr
swizzlr / Button.swift
Created January 30, 2015 15:23
Statically typed alternatives to delegates, using the full power of Swift
struct Touch { }
struct Image { }
public final class Button {
public enum State { case Enabled, Disabled, Pressed }
public struct DynamicButtonConfiguration {
let buttonWasPressed: (button: Button, touch: Touch) -> ()
let imageForButtonState: (buttonState: State) -> (Image)
}
@swizzlr
swizzlr / LMLPlaintextResponseSerializer.m
Last active March 15, 2017 09:29
Plaintext response serializer for AFNetworking.
@interface LMLPlaintextResponseSerializer : AFHTTPResponseSerializer
@end
@implementation LMLPlaintextResponseSerializer
- (id)responseObjectForResponse:(NSURLResponse *)response data:(NSData *)data error:(NSError *__autoreleasing *)error {
[super responseObjectForResponse:response data:data error:error]; //BAD SIDE EFFECTS BAD BUT NECESSARY TO CATCH 500s ETC
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)([response textEncodingName] ?: @"utf-8")));
return [[NSString alloc] initWithData:data encoding:encoding];

#How to Generate a Self Signed SSL Server Certificate on a Mac ###Open Keychain Access and go here ###Select SSL Server and name it ###??? ###PROFIT11!!!11!1!!