Skip to content

Instantly share code, notes, and snippets.

@kuhnroyal
kuhnroyal / TableDataViewModel
Created March 25, 2014 12:09
Example usage of ReactiveCocoa in a ViewModel for a UITableView(Controller) holding data in a mutable array with a command to load and reload data.
#import <Objection/Objection.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
#import <ReactiveCocoa/RACEXTScope.h>
#import "TableDataViewModel.h"
#import "RestApiConnector.h"
const NSUInteger kPageSize = 30;
@interface TableDataViewModel ()
//
// View Controller
//
- (void) viewDidLoad {
[super viewDidLoad];
RAC(self.viewModel, username) = [myTextfield rac_textSignal];
RACSignal *usernameIsValidSignal = RACObserve(self.viewModel, usernameValid);
@chriseidhof
chriseidhof / presentation.md
Created June 28, 2014 13:00
MobileOptimized Presentation

[fit] Functional Programming in

[fit] Swift

Chris Eidhof - objc.io - June 28, Minsk



@benjchristensen
benjchristensen / ObservableMethod.groovy
Created January 30, 2013 18:39
Observable Method that optionally uses a thread to fetch data if not available in memory. Either way the response type is an Observable callback that can be composed using Rx operators.
/**
* Non-blocking method that immediately returns the value
* if available or uses a thread to fetch the value and
* callback via `onNext()` when done.
*/
def Observable<T> getData(int id) {
if(availableInMemory) {
// if data available return immediately with data
return Observable.create({ observer ->
observer.onNext(valueFromMemory);
@rjchatfield
rjchatfield / types.md
Last active December 13, 2015 20:15
Types are Coming

Types are coming

Last week I had a crash course in PureScript - a Haskell-like language that compiles to JavaScript. I’m not about to preach that you should write your web apps in Haskell (though I strongly recommend learning Haskell), however, I do wish to explore an important part of any Functional Programming language that has eluded Javascript...

Types.

There is a lot to be said about Javascript and its lack of static typing. We’ve built the whole web with it! But this post will explore the benefits of a compile-time strong static type system.

“But Javascript does have types!?”

@jdewind
jdewind / DelegateExample.m
Last active January 4, 2016 17:19
ReactiveCocoaDelegateExample
- (void)viewDidLoad {
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame: CGRectZero];
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchController.delegate = self;
// Place it in view
searchBar.delegate = self;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {
self.searchResults = [self search: text];

Elm 0.15.1 vs 0.16 on Chrome

Result of running these benchmarks on Chrome 45.0.2454.101

These numbers seem to be pretty consistent on Blink-based browsers (Chrome and Opera) but are more like 20% to 50% improvements on FireFox, Safari, and IE. I am not sure how to explain that, so take these numbers more as an indicator of “Elm is generating faster code across the board” as opposed to “Elm is 10x faster!”

business logic from examples

extension Selector {
static let coffeeMadeNotification = #selector(Customer.drink(_:))
}
class Customer {
@objc func drink(notification: NSNotification) {
print("Mmm... Coffee")
}
}
defmodule HealthComponent do
use GenEvent
### Public API
def get_hp(entity) do
:gen_event.call(entity, HealthComponent, :get_hp)
end
def alive?(entity) do
:gen_event.call(entity, HealthComponent, :alive?)
@avh4
avh4 / LightButton.elm
Last active July 29, 2016 08:44
Intro to Elm - SF Elm meetup 2016-07-27
module LightButton exposing (view)
import Html
import Html.Attributes
import Html.Events
colorForBool : Bool -> String
colorForBool bool =
if bool then