Skip to content

Instantly share code, notes, and snippets.

@dmcrodrigues
dmcrodrigues / observe-array-with-rac.swift
Last active November 8, 2017 07:42
Observing an array using ReactiveCocoa
import ReactiveCocoa
let a: MutableProperty<[Int]> = MutableProperty([])
a.signal.observeNext { array in
print("Array did change: \(array)")
}
a.value.append(1)
a.value.append(2)
@dmcrodrigues
dmcrodrigues / benchmark.swift
Created January 4, 2017 01:28
[Benchmark] Lock using a recursive pthread_mutex_t
import XCTest
import Foundation
let iterationCount = 10_000_000
class BenchmarksTests: XCTestCase {
func testRecursiveLock_NoRecursion() {
self.measure {
invoke(RecursiveLock<Int>(), times: iterationCount)
@dmcrodrigues
dmcrodrigues / gist:885ba38ed48aaa2e9c50bab2fa46438e
Created March 29, 2017 08:37
Xcode 8.3: Continuous Crash
Process: Xcode [37635]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 8.3 (12169)
Build Info: IDEFrameworks-12169000000000000~2
App Item ID: 497799835
App External ID: 821487965
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [37635]
@dmcrodrigues
dmcrodrigues / SomeObject.h
Last active August 12, 2016 11:47
Assigning an Objective-C block without bridging through a Swift closure crashes on invocation
#import <Foundation/Foundation.h>
typedef void (^SomeBlock)(NSString * _Nonnull someParameter);
_Nonnull SomeBlock defaultBlock();
@interface SomeObject : NSObject
@property (nonatomic, copy, nullable) SomeBlock someBlock;
@dmcrodrigues
dmcrodrigues / pattern.matching.swift
Last active March 3, 2016 12:39
Expression pattern operator ~=
import UIKit
class A {
var value: Int
init(value: Int) {
self.value = value
}
}
import UIKit
import CoreData
class SomeClass: NSManagedObject {}
class MyManagedObjectContext: NSManagedObjectContext {
override func executeFetchRequest(request: NSFetchRequest) throws -> [AnyObject] {
return [SomeClass()]
}
@dmcrodrigues
dmcrodrigues / ssh.signature.sh
Last active December 16, 2015 05:19
Verify SSH key signature
ssh-keygen -lf $1 # ex: ~/.ssh/id_rsa.pub
//
// UIDevice+DeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
#include <sys/types.h>
#include <sys/sysctl.h>
typedef enum {
@dmcrodrigues
dmcrodrigues / build.x264.sh
Created July 29, 2012 12:50
x264 on OSX 10.7
#!/bin/sh
PARALLEL_JOBS=3
### x264 ##############################################
echo "installing x264..."
if [ ! -d x264 ]; then
git clone git://git.videolan.org/x264.git x264
@dmcrodrigues
dmcrodrigues / build.ffmpeg.sh
Created July 29, 2012 12:49
FFmpeg on OSX 10.7
#!/bin/sh
PKG_CONFIG_VERSION=0.25
YASM_VERSION=1.2.0
PARALLEL_JOBS=3
### pkg-config ########################################
echo "installing pkg-config ${PKG_CONFIG_VERSION}..."