Skip to content

Instantly share code, notes, and snippets.

View ronal2do's full-sized avatar

Ronaldo Lima ronal2do

View GitHub Profile
@ronal2do
ronal2do / resolvePromise.js
Created September 9, 2018 08:23 — forked from mjackson/resolvePromise.js
An easy way to do async APIs in JavaScript that support both promises *and* callbacks!
// Here is a function that I use all the time when creating public
// async APIs in JavaScript:
const resolvePromise = (promise, callback) => {
if (callback)
promise.then(value => callback(null, value), callback)
return promise
}
// Sometimes I like to use callbacks, but other times a promise is
@ronal2do
ronal2do / mapbox-custom-camera.js
Created September 26, 2018 12:25 — forked from kristfal/mapbox-custom-camera.js
Mapbox camera snippets
const cameraValid = camera =>
camera && camera.geometry && Array.isArray(camera.geometry.coordinates);
// Workaround for Mapbox issue
// https://github.com/mapbox/react-native-mapbox-gl/issues/1126
export const enforceIntegerPadding = padding =>
padding.map(value => parseInt(value, 10));
export const isValidBounds = camera =>
camera &&
@ronal2do
ronal2do / gatsby-ssr.js
Created January 29, 2019 11:17 — forked from LawJolla/gatsby-ssr.js
Apollo + Gatsby SSR
import React from 'react'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import ApolloClient, { createNetworkInterface, } from 'apollo-client'
import { ApolloProvider, getDataFromTree } from 'react-apollo'
// Apollo Setup
const networkInterface = createNetworkInterface({
uri: process.env.GRAPHCOOL_API
})
@ronal2do
ronal2do / AppStrings.js
Created February 4, 2019 11:40 — forked from BrianJVarley/AppStrings.js
Mocking react-native-localization package in jest spec
// ES6 module syntax
import LocalizedStrings from 'react-native-localization';
let AppStrings = new LocalizedStrings({
'en-US': {
settingMenuOptionOne: 'Centimeters ({0})',
},
en: {
settingMenuOptionOne: 'Centimeters ({0})',
},
// useFetch.ts
import { useEffect, useState } from 'react'
export interface IPosts {
userId: number;
id: number;
title: string;
body: string;
}
import React, { useReducer, useContext, ReactNode } from 'react'
import { Text, View, TouchableOpacity, StyleSheet } from 'react-native'
const initialArg = 0
type Action =
| { type: 'increment' }
| { type: 'decrement' }
| { type: 'set'; count: number }
import { AsyncStorage } from 'react-native'
import react, { useEffect } from "react"
import { useState } from 'react'
import { useNetInfo } from './useNetInfo';
export const getData = async (key: string) => {
try {
const value = await AsyncStorage.getItem(key)
if (value !== null) {
return JSON.parse(value)
# Fastfile
#
# Author: Ronaldo Lima <[email protected]>
#
# -----------------------------------------------------------
#
# Version bumping, the default type is `patch`
# Run:
# `fastlane ios bump`
# `fastlane ios beta [type:major|minor|patch]`