Skip to content

Instantly share code, notes, and snippets.

View drodriguez's full-sized avatar

Daniel Rodríguez Troitiño drodriguez

View GitHub Profile
@drodriguez
drodriguez / preset_compare.fish
Created March 18, 2019 22:03
Testing the dry-run of the Swift presets
for pre in *.pre.txt
diff -urN \
(sed -E "s/ '--(swift|llvm)-cmake-options=[^']+'//g" $pre | psub)
(sed -E "s/ '--(swift|llvm)-cmake-options=[^']+'//g" (string replace -r '\.pre\.' '.output.' $pre) | psub)
or read
end
{
"name": "ReactiveCocoa",
"version": "4.2.1",
"summary": "A framework for composing and transforming streams of values.",
"description": "ReactiveCocoa (RAC) is an Objective-C framework for Functional Reactive Programming.\nIt provides APIs for composing and transforming streams of values.",
"homepage": "https://github.com/ReactiveCocoa/ReactiveCocoa",
"license": {
"type": "MIT",
"file": "LICENSE.md"
},
@import Foundation;
NS_ASSUME_NONNULL_BEGIN
@interface NewClass : NSObject
- (instancetype)initWithString:(NSString *)string NS_DESIGNATED_INITIALIZER;
@end
@drodriguez
drodriguez / test-array-signature.c
Created December 24, 2014 11:34
TIL about arrays in signatures in C
#include <stdlib.h>
int test1(int32_t (*array)[10]) {
return 1;
}
int test2(int32_t (*array)[5]) {
return 2;
}
@drodriguez
drodriguez / gist:64c470cf59eae85767b1
Created December 6, 2014 00:10
Computed variable to return type conforming protocol.
protocol TestProtocol {
}
class TestClass : TestProtocol {
}
class TestClass2 {
}
struct Test {
@drodriguez
drodriguez / Spec.m
Created August 14, 2014 23:47
Better Kiwi?
#import "Kiwi.h"
#define KWPasteX(x, y) x ## y
#define KWPaste(x, y) KWPasteX(x, y)
#define KWMetaMacro(...) \
if (0) \
KWPaste(finished, __LINE__): ; \
else \
for (KWVoidBlock KWPaste(block, __LINE__) = nil;;) \
@drodriguez
drodriguez / ycombinator.swift
Created June 23, 2014 22:43
Y combinator in Swift
// You can have a recursive function
func fact(n: Int) -> Int {
if n < 2 { return 1 }
return n * fact(n - 1)
}
// But you cannot have a recursive closure
// let fact2: Int -> Int = { n in
// if n < 2 { return 1 }
// return n * fact2(n - 1) // ERROR: Variable used within its own initial value
@drodriguez
drodriguez / boolean_properties.swift
Created June 22, 2014 23:50
Abusing optional syntax for better boolean properties
class MyClass {
var enabled: Bool? {
didSet {
if let v = enabled? {
self.enabled = v ? true : nil
}
}
}
init(enabled: Bool) {
import Foundation
enum Either<A, B> {
case Left(@auto_closure () -> A)
case Right(@auto_closure () -> B)
func fold<X>(fa: A -> X, fb: B -> X) -> X {
switch self {
case let .Left(a): return fa(a())
case let .Right(b): return fb(b())
@drodriguez
drodriguez / gist:6160864
Created August 6, 2013 00:17
Auto Layout equal spacing with a little math
NSMutableArray *horizontalConstraints = [NSMutableArray array];
// Fixed width, same width for all buttons (33)
[horizontalConstraints addObject:[NSLayoutConstraint constraintWithItem:left attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.f constant:33.f]];
[horizontalConstraints addObject:[NSLayoutConstraint constraintWithItem:left attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:center1 attribute:NSLayoutAttributeWidth multiplier:1.f constant:0]];
[horizontalConstraints addObject:[NSLayoutConstraint constraintWithItem:left attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:center2 attribute:NSLayoutAttributeWidth multiplier:1.f constant:0]];
[horizontalConstraints addObject:[NSLayoutConstraint constraintWithItem:left attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:right attribute:NSLayoutAttributeWidth multiplier:1.f constant:0]];
// Align baselines
[horizonta