Skip to content

Instantly share code, notes, and snippets.

View jspahrsummers's full-sized avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
@airspeedswift
airspeedswift / GenericInfProb.swift
Last active August 29, 2015 14:07
Swift for…in generic inference prob
// original version with problem
struct A<T> {
func f<S: SequenceType where S.Generator.Element == T>(s: S) {
// error: cannot convert expression's type S to type S
for v in s {
print(v)
}
}
}
@landonf
landonf / bind-protocol-types.swift
Last active March 28, 2018 08:14
An attempt to use the type inferencer to explicitly bind a protocol's typealias.
protocol TypeBinder {
typealias BoundT
}
class TypeEvidence<T> : TypeBinder {
typealias BoundT = T
func array () -> Array<BoundT> { return [] }
}
class ObserverTyper<T> {
// FILED: rdar://17240493
// Type constraint ignored on function type parameter
//
protocol BoolT {}
class TrueT : BoolT {}
class FalseT : BoolT {}
protocol Nat {
typealias IsZero
@mchambers
mchambers / reflect.swift
Last active March 5, 2021 09:20
Basic Reflection in Swift.
// Let's define a basic Swift class.
class Fruit {
var type=1
var name="Apple"
var delicious=true
}
// We can get at some info about an instance of an object using reflect(), which returns a Mirror.
reflect(Fruit()).count
reflect(Fruit())[1].0
@bradmontgomery
bradmontgomery / python_projects.md
Last active January 22, 2021 20:27
How I start and manage my python projects.

How I organize my python projects

This is applicable to both OS X and Linux. I use the same tools on both systems. In this guide, I'm going to set up an environment for a Flask app.

Setup

  1. I start by installing pip, virtualenv, then virtualenvwrapper. I seldom use virtualenv directly; I use the wrapper tools instead.
  2. I create a virtualenv for my project:
@JaviSoto
JaviSoto / ReactiveCocoa.md
Last active August 29, 2015 13:56
ReactiveCocoa

ReactiveCocoa

A lot is being written these days about ReactiveCocoa and the paradigms it introduces. In my opinion, there are only two sides giving their opinion: the ones that know a lot about it and are therefore obviously biased, and the ones that refuse to learn it.

I decided to write something myself because I think I'm right in the middle. Some months ago I knew nothing about it, and now I know enough to want to use it every day. I hope that by not being an expert, I can actual introduce a few really simple ideas in a much easier way to pick up by new-commers, to show why I think ReactiveCocoa is an incredibly powerful tool to help us write better, cleaner, and more maintainable code.

It's signals all the way down

The base of everything that happens in ReactiveCocoa is signals. I'm going to try to explain what they represent and why they fit in the way we think about what happens on an app. A lot of the things you may read about Functional Reactive Programming end up confusing you when

@landonf
landonf / xcode-gripes.md
Last active August 21, 2020 09:06
Every time I hit something that annoys me in Xcode, I add the feature/UX improvement/change I'd like to the list.

Xcode Wish List:

Legacy Support

  • Additional optional downloads:
    • Older SDKs, eg, for building ancient projects.
    • Older compilers (for same).
  • Either ship gcc/llvm-gcc or don't. Don't ship clang and call it 'gcc', that just breaks anyone who actually needs GCC and finds your not-gcc in the PATH.

UX

Project/File Navigation

@lukehefson
lukehefson / uninstall-GHfM.sh
Created November 27, 2013 13:48
Completely uninstall GitHub for Mac
#!/bin/bash
function remove_dir () {
rm -rf "$1_"
if [ -d "$1" ]
then
mv "$1" "$1_"
fi
}
RACCommand *example = [[RACCommand alloc] initWithSignalBlock:^(id input) {
return [RACSignal createWithBlock:^(id<RACSubscriber> subscriber){
[subscriber sendCompleted];
return nil;
}];
];
// Now, how will I know when each task has completed?
// I certainly cannot tell from `example.executionSignals.flatten`.
@jonsterling
jonsterling / gist:7001562
Last active December 25, 2015 15:49
Rethinking commands as Kleisli arrows with a bit more stuff. This show the basics of how to start with Kleisli arrows (of signals) which are interesting and useful in their own right. I often need to compose monadic pipelines `a -> Signal a`, and it's nice to be able to reify these rather than thread everything through (very pointy) flatmaps. Ne…
typedef RACSignal *(^RACSignalKleisliBlock)(id input);
@interface RACSignalKleisli : NSObject
- (id)initWithSignalBlock:(RACSignalKleisliBlock)block;
- (instancetype)compose:(RACSignalKleisli *)kleisli;
- (RACSignal *)execute:(id)input;
@end
@implementation RACSignalKleisli {
RACSignalBlock _signalBlock;