Skip to content

Instantly share code, notes, and snippets.

@neilpa
neilpa / zipWith.swift
Created February 11, 2015 05:43
Signal.zipWith
private enum Either<T, U> {
case Left(Box<T>)
case Right(Box<U>)
}
public func zipWith<T, U, E>(otherSignal: Signal<U, E>)(signal: Signal<T, E>) -> Signal<(T, U), E> {
return Signal { observer in
var lock = NSRecursiveLock()
lock.name = "org.reactivecocoa.ReactiveCocoa.zipWith"
@neilpa
neilpa / Random.swift
Last active August 29, 2015 14:19
Randomness
protocol Randomizable {
static func random() -> Self
}
protocol IntervalRandomizable: Randomizable, Comparable {
static func random(interval: HalfOpenInterval<Self>) -> Self
static func random(interval: ClosedInterval<Self>) -> Self
}
extension CGFloat: Randomizable {
@jspahrsummers
jspahrsummers / transcript.md
Last active September 12, 2015 15:14
Excerpt from https://reactivex.slack.com about API design, especially as it relates to RAC

carlossless [09:50] So anyone used RxSwift? I’m wondering what are your thoughts and opinions vs RAC3.

jspahrsummers [10:00] @carlossless: https://github.com/ReactiveCocoa/ReactiveCocoa/blob/07813339d3c44aa02fb1b71777baa4ede0f0f77a/README.md#how-does-reactivecocoa-relate-to-rx

carlossless [10:13] Yeah, I was looking for a more practical point of view but even so. RxSwift has UI bindings, it follows the haskell naming for most transformation and composition functions ​map​, ​filter​ etc. rather than ​select​, ​where​.

carlossless [10:14]

@neilpa
neilpa / concatSplices.swift
Last active October 8, 2015 15:17
Building collections from signals[-of-signals] of collection mutations
//
// A half-baked approach (not thread-safe, poor disposable management) for creating
// aggregate collections from multiple signals of collection mutations. In this
// case we are concating multiple mutation streams into a single container. So for
// each inner signal we need to offset subsequent splices by the count of preceding
// items (which can be recovered by scanning previous splices).
//
// Example:
//
// let (first, sink1) = SignalProducer<Splice<Int>, NoError>.buffer()
@gnachman
gnachman / swizzle-retain-release-autorelease
Created December 8, 2012 07:56
Swizzle retain/release/autorelease to debug busted reference counting
// Use with https://github.com/rentzsch/jrswizzle
// MIT license
// After your program dies because with a zombie, examine [theBigLog objectForKey:@"0x12345"], subbing the address of the thing that died. You can get stack traces referred to in the logs by looking up the "stack-12345" numbers in the same dict. To track a particular object, add [NSValue valueWithPointer:myobject] to debugList in a @synchronized block.
@interface ClassToDebug : NSColor
@end
@interface ClassToDebug (DebugRefs)
@end
// Similar to `enumerate` but provides the collection's index type
// rather than an Int for the position
public func iterate<C: CollectionType>(collection: C) -> SequenceOf<(C.Index, C.Generator.Element)> {
var index = collection.startIndex
// type-inference doesn't want to work without this
return SequenceOf { _ -> GeneratorOf<(C.Index, C.Generator.Element)> in
return GeneratorOf {
if index == collection.endIndex {
return nil
@yjsoon
yjsoon / gist:3485271
Created August 27, 2012 03:22
vim search Dash for word under cursor, filetype-specific
" Searches Dash for the word under your cursor in vim, using the keyword
" operator, based on file type. E.g. for JavaScript files, I have it
" configured to search j:term, which immediately brings up the JS doc
" for that keyword. Might need some customisation for your own keywords!
function! SearchDash()
" Some setup
let s:browser = "/usr/bin/open"
let s:wordUnderCursor = expand("<cword>")
@chriseidhof
chriseidhof / Main.swift
Last active March 11, 2016 06:59
Protocol Extensions
protocol OptionalType {
typealias T
var optional: T? { get }
}
extension Optional : OptionalType {
var optional: T? { return self }
}
extension SequenceType where Generator.Element: OptionalType {
package com.hubspot.jersey.dropwizard.managed;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.cfg.JaxRSFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.lifecycle.Managed;
@neilpa
neilpa / ui.sh
Last active August 5, 2016 23:51
#!/bin/bash
# Universal Install Script
# https://xkcd.com/1654/
pip install "$1" &
easy_install "$1" &
brew install "$1" &
npm install "$1" &
yum install "$1" &