Skip to content

Instantly share code, notes, and snippets.

View andyarvanitis's full-sized avatar

Andy Arvanitis andyarvanitis

View GitHub Profile
@andyarvanitis
andyarvanitis / typed_collections.eero
Created January 15, 2013 07:07
Eero supports (as an experimental feature) 'instancetype' for method parameter types. Inspired by Jonathan Sterling's blog: http://www.jonmsterling.com/posts/2012-02-05-typed-collections-with-self-types-in-objective-c.html
protocol OrderedCollection <FastEnumeration>
at: UInteger index, return instancetype
put: instancetype object
end
protocol MapCollection <FastEnumeration>
at: id key, return instancetype
@andyarvanitis
andyarvanitis / only_dots.eero
Last active December 18, 2015 02:18
A snippet of code showing "global dot-notation" for Eero message sending (currently under evaluation).
parseQueue = OperationQueue.new
NotificationCenter.defaultCenter.addObserver: self,
selector: |addEarthquakes:|,
name: kAddEarthquakesNotif,
object: nil
...
self.parseQueue.addOperation: parseOperation
parseOperation.release // once added to the NSOperationQueue it's retained, we don't need it anymore
@andyarvanitis
andyarvanitis / tiny_reactive.eero
Last active December 18, 2015 09:19
Trivial example of using ReactiveCocoa with Eero.
#import <Foundation/Foundation.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
interface Reactive
property (retain)
String name
String address
registerProperties
@andyarvanitis
andyarvanitis / tiny_reactive_before_after.txt
Last active December 18, 2015 09:29
Another little eero ReactiveCocoa example. This one is from one of the official examples from GitHub.
// Only log names that start with "j".
// Objective-C version...
[[RACAble(self.username)
filter:^(NSString *newName) {
return [newName hasPrefix:@"j"];
}]
subscribeNext:^(NSString *newName) {
NSLog(@"%@", newName);
@andyarvanitis
andyarvanitis / reactive_cocoa_macros_eero.h
Last active February 6, 2020 23:52
A couple ReactiveCocoa macro un/defines needed for Eero, and used for these examples.
#undef _RACAbleObject
#define _RACAbleObject(object, property) (object.rac_signalForKeyPath:@keypath(object, property), observer:self)
#undef keypath1
#define keypath1(PATH) \
(((void)(NO && ((void)PATH, NO)), strchr(# PATH, *".") + 1))
import Data.Foldable
-- perform a very large foldr to test tail recursion
addAll :: (Foldable t, Num a) => t a -> a
addAll = Data.Foldable.foldr (+) 0
n :: Integer
n = 1500000
numbersList :: [Integer]
pcre *pcre_compile(const char *pattern,
int options,
const char **errptr,
int *erroffset,
const unsigned char *tableptr);
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Data.Either (Either(..))
import Data.Tuple (Tuple)
foreign import data PCREOption :: *
foreign import data PCRECode :: *
#ifndef MainFFI_HH
#define MainFFI_HH
#include <pcre.h>
#include "PureScript/PureScript.hh"
namespace Main {
using namespace PureScript;
#include <cstring>
#include "Main.hh"
namespace Main {
static auto bitor_all( const any::array& opts ) -> int {
int combined_opts = 0;
for (auto it = opts.cbegin(), end = opts.cend(); it != end; it++) {
combined_opts |= static_cast<int>(*it);
}