Skip to content

Instantly share code, notes, and snippets.

@infix func == <T:ScalarArithmetic, U:ScalarArithmetic> (lhs:T,rhs:U) -> Bool {
return (lhs.toDouble == rhs.toDouble)
}
@infix func != <T:ScalarArithmetic, U:ScalarArithmetic> (lhs:T,rhs:U) -> Bool {
return (lhs == rhs) == false
}
@infix func <= <T:ScalarArithmetic, U:ScalarArithmetic> (lhs:T,rhs:U) -> Bool {
return (lhs.toDouble <= rhs.toDouble)
}
@infix func < <T:ScalarArithmetic, U:ScalarArithmetic> (lhs:T,rhs:U) -> Bool {
// Some global place
class CollisionMapping
{
enum Layer : Uint32 {
Terrain,
Actors,
}
// Maps individual collision types (bird, pipe etc) to a smaller set of
// more generic types to make them more manageable
const touchStart = Rx.Observable.fromEvent(window, 'touchstart').timestamp();
const touchMove = Rx.Observable.fromEvent(window, 'touchmmove');
const touchEnd = Rx.Observable.fromEvent(window, 'touchend').timestamp();
const touchAndHold = touchStart
.flatMap(() => touchEnd.takeUntil(touchMove), (x, y) => { start: x.timestamp, end: y.timestamp })
.filter(ts => (ts.end - ts.start) / 1000 > 2);
const subscription = touchAndHold.subscribe(
() => console.log('touch and hold!')
@prabirshrestha
prabirshrestha / TextFieldChanges.m
Created August 2, 2012 13:53
Reactive Cocoa examples
@synthesize firstName = _firstName;
@synthesize txtFirstName = _txtFirstName;
[RACAbleSelf(self.firstName) subscribeNext:^(id x) { [self firstNameChanged:x]; }];
[self rac_bind:RAC_KEYPATH_SELF(self.firstName) to:self.txtFirstName.rac_textSubscribable];
- (void) firstNameChanged:(id)firstName {
NSLog(@"changed: %@", firstName);
}
@seivan
seivan / assets.rake
Created March 15, 2013 01:39 — forked from sj26/assets.rake
# Stick this in lib/tasks/assets.rake or similar
#
# A bug was introduced in rails in 7f1a666d causing the whole application cache
# to be cleared everytime a precompile is run, but it is not neccesary and just
# slows down precompiling.
#
# Secondary consequences are the clearing of the whole cache, which if using
# the default file cache could cause an application level performance hit.
#
# This is already fixed in sprockets-rails for rails 4, but we patch here for
/*
* BPGeometry.h
*
* Created by Jon Olson on 11/30/09.
* Copyright 2009 Ballistic Pigeon, LLC. All rights reserved.
*
*/
#import <Foundation/Foundation.h>
// http://stackoverflow.com/a/19277383
//
- (void)textViewDidChange:(UITextView *)textView
{
CGRect line = [textView caretRectForPosition:textView.selectedTextRange.start];
CGFloat overflow = line.origin.y + line.size.height
- ( textView.contentOffset.y + textView.bounds.size.height
- textView.contentInset.bottom - textView.contentInset.top );
if (overflow > 0) {
// We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it)
@michaelochurch
michaelochurch / hackernews-banned-post
Created January 9, 2014 18:43
This is the reply I can't write on Hacker News, because PG is a fucking child and I get the "submitting too fast" error after ~3 posts per day.
In reply to: https://news.ycombinator.com/item?id=7031552
*People, as a group, really aren't interested in learning any more than the bare minimum they need to
get what they want. That's what MOOCs are really up against.*
True, and the people who are motivated tend to rely on each other, if not for support, at least to have
peers who are similarly interested. It's like the fact that people whose friends are obese are more likely
to gain weight.
If your motivation/work ethic/freedom-from-external-distraction level is 9-10, then you're fine working

The most obvious example is linking of dependent libraries. When you add a framework to your project, that framework already has encoded the libraries it depends on; simply drop the framework in, and no further changes are required to the list of libraries your project itself links to.

People/companies do this with static libraries as well, whereas it should be “the application developer's responsibility to add all required libraries in addition to the one they actually want to use”.

Of course, if ‘the one [library] they actually want to use’ is the only library they care about, then having a single ‘drop-in’ solution is preferable. However, once you depend on multiple libraries that might have common dependencies, there’s no way around having to have a dependency (versions) manager. Because while you can pull-off various symbol tricks with C libraries, you cannot with Objective-C. As in, there can only ever be one class/method registered for a given name in the runtime.

I feel like this was

@rnapier
rnapier / gist:dbffbf54274a880a6ac7
Last active July 12, 2016 01:29
More exploration of guard/try and crazy operator idea
// This is pretty clean, but I often dislike chains of temporary variables
// They tend to lead to little bugs when you use the wrong one. Swift's warnings
// and 'let' reduce problems, though.
func pagesFromOpenSearchData(data: NSData) throws -> [Page] {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions())
guard let array = json as? [JSON] else { throw JSONError.BadArray(json) }
guard case let value = array[1] where array.count >= 2 else { throw JSONError.OutOfRange }
guard let titles = value as? [String] else { throw JSONError.BadStringList(json) }