Monthly Archive: January 2016

Create a React Native custom module (with Swift)

Here is a quick and dirty example of how one can expose a custom module to React Native using Swift. Product-Bridging-Header.h – Bridge header file [code language=”C”] #import "RCTBridgeModule.h" [/code] MySwiftThingy.m – Register Swift code with the React Native Bridge [code language=”C”] #import "RCTBridgeModule.h" @interface RCT_EXTERN_MODULE(MySwiftThingy, NSObject) RCT_EXTERN_METHOD(callbackMethod:(RCTResponseSenderBlock)callback) RCT_EXTERN_METHOD(simpleMethod:(NSString *)message) @end [/code] MySwiftThingy.swift – Custom Swift component [code language=”Scala”] import Foundation @objc(MySwiftThingy) class MySwiftThingy: NSObject { @objc func callbackMethod(callback: RCTResponseSenderBlock)...

Create a self signed certificate with OpenSSL

To create a self signed cert with OpenSSL, execute the following: openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 100 In some cases its useful to remove the passphrase from the key. This way you will not be prompt for the passphrase every time it starts. Removing the passphrase is easy, simply run this following command: openssl rsa -in key.pem -out newkey.pem && mv newkey.pem key.pem

Adapt jQuery.getJSON to an Rx.Observable with RxJs

Rx provides an incredible and fluent API to help untangle your asynchronous JavaScript code. Here we’ll see how to adapt jQuery’s getJSON method to an Rx Observable with only a small bit of code. [code language=”JavaScript”] function getJSON(url, data) { return Rx.Observable.create(observer => { var canceled = false; if (!canceled) { jQuery.getJSON(url, data). done(data => { observer.onNext(data); observer.onCompleted(); }). fail(err => observer.onError(err)); } return () => canceled = true; });...