Skip to content

Instantly share code, notes, and snippets.

@jamesnocentini
jamesnocentini / example.js
Last active September 26, 2018 05:36
Conditional statement of Android SDK version
if (Build.VERSION.SDK_INT >= 23) {
/* code to run on API 23 or above */
}
@jamesnocentini
jamesnocentini / types.adoc
Last active September 26, 2018 05:42
Swift/Java Types to JS Types (Native Modules)

Swift/Objective-C

BOOL -> Bool
NSInteger -> Number
float -> Number
double -> Number
CGFloat -> Number
NSString -> String
@jamesnocentini
jamesnocentini / example.sh
Created September 26, 2018 05:49
Access Emulator Data Directory with ADB
$ adb shell
generic_x86: # su
generic_x86: # cd data/data/<PACKAGE_ID>
@jamesnocentini
jamesnocentini / example.java
Last active September 26, 2018 08:10
Read Android Asset File
public class Utils {
public static void readAsset(String filename) {
AssetManager assetManager = context.getAssets();
try {
InputStream inputStream = assetManager.open(filename);
File outFile = new File(context.getFilesDir(), filename);
FileOutputStream out = new FileOutputStream(outFile);
copyFile(inputStream, out);
} catch (IOException e) {
@jamesnocentini
jamesnocentini / example.java
Last active September 27, 2018 05:10
Convert ResultSet to WritableArray
public static WritableArray toWritableArray(ResultSet resultSet) {
WritableArray writableArray = Arguments.createArray();
for (Result result : resultSet) {
Map<String,Object> map = result.toMap();
WritableMap writableMap = Arguments.makeNativeMap(map);
writableArray.pushMap(writableMap);
}
return writableArray;
}
@jamesnocentini
jamesnocentini / example.java
Created September 26, 2018 08:19
Escape % in Java string format
String wildcardMatch = String.format("%%%s%%", location);
@jamesnocentini
jamesnocentini / example.js
Last active September 27, 2018 06:50
Initialize Navigation with React Native Navigation
import { Navigation } from "react-native-navigation";
import Hotels from './ui/Hotels';
import BookmarkedHotels from './ui/BookmarkedHotels';
Navigation.registerComponent('HotelFinder.BookmarkedHotels', () => BookmarkedHotels);
Navigation.registerComponent('HotelFinder.Hotels', () => Hotels);
export const startApp = () => {
Navigation.startSingleScreenApp({
screen: {
@jamesnocentini
jamesnocentini / example.sh
Created September 27, 2018 06:48
Bash syntax to check a CLI argument was supplied
#!/usr/bin/env bash
OUTPUT_FILE=${1}
if [[ ! -z ${1} ]]; then
fi
@jamesnocentini
jamesnocentini / HotelFinderBridge.m
Last active September 30, 2018 06:59
React Native Module Example
#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(HotelFinderNative, NSObject)
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
@end
@jamesnocentini
jamesnocentini / example.adoc
Created September 27, 2018 13:01
Installing NodeGit on clean Mac