Skip to content

Instantly share code, notes, and snippets.

View AndreiCalazans's full-sized avatar
🏠
Working from home

Andrei Xavier de Oliveira Calazans AndreiCalazans

🏠
Working from home
View GitHub Profile
@nodkz
nodkz / mongoose.flowtype.js
Last active June 16, 2018 20:55
Covering mongoose models with flowtype
/* @flow */
/* eslint-disable */
import mongoose from 'mongoose';
export type MongoId = typeof mongoose.Types.ObjectId | {
toString(): string,
};
export type MongoOrScalarId = MongoId | string | number;
@swyxio
swyxio / Timer fallback.js
Created November 14, 2018 01:25
Timer component for use as a Suspense fallback
function Timer() {
const startTime = React.useRef(performance.now());
const [time, setTime] = React.useState(performance.now());
React.useEffect(() => {
const id = setTimeout(() => {
ReactDOM.flushSync(() => {
setTime(performance.now());
});
}, 2);
// Example of what data masking gets us with Relay
const AdminList = createFragmentContainer(
(props) => <div>
{props.admins.map((admin) => <div>{admin.name}</div>)}
</div>,
{
admins: graphql`
fragment AdminList_admins on User @relay(plural: true) {
name
@dslounge
dslounge / lint changes.sh
Created May 13, 2019 18:31
eslint the javascript files changed on your branch
git diff master... --name-only | grep -E '.js$' | xargs ./node_modules/eslint/bin/eslint.js
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
const paths = [
{ path: 'graphql/connection/', tag: 'Connection' },
@sibelius
sibelius / MutationUtils.js
Created March 19, 2018 10:20
Helper methods for Relay Modern updater
// @flow
import { ConnectionHandler } from 'relay-runtime';
import { isObject, isArray } from 'lodash/fp';
export function listRecordRemoveUpdater({ parentId, itemId, parentFieldName, store }) {
const parentProxy = store.get(parentId);
const items = parentProxy.getLinkedRecords(parentFieldName);
parentProxy.setLinkedRecords(items.filter(record => record._dataID !== itemId), parentFieldName);
}
@axemclion
axemclion / MainApplication.java
Created August 12, 2019 18:30
Adding Flipper to ReactNative
// Call this in MainApplication.onCreate(), just after Soloader line.
private static void initialize(Context context) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
@lucianomlima
lucianomlima / adb_connect.sh
Created June 5, 2019 17:57
Connect to Android devices with ADB through wi-fi
function adb_connect {
# PORT used to connect. Default: 5555
PORT=${1:-5555}
# IP address from current device connected
IP_ADDRESS=`adb shell ip route | awk '{print $9}'`
echo "ADB connect to $IP_ADDRESS on port $PORT"
# Change connection from usb to tcpip using $PORT
@sibelius
sibelius / useEventEmitter.tsx
Created April 16, 2019 01:20
UseEventEmitter hook to work with react navigation navigationOptions buttons
import { useEffect, useRef } from 'react';
export const useEventEmitter = (eventEmitter, eventName: string, fn: () => void) => {
const subscription = useRef(null);
useEffect(() => {
subscription.current = eventEmitter.addListener(eventName, fn);
return () => {
if (subscription.current) {
@ericlewis
ericlewis / RCTNativeTestModuleSpec.h
Last active November 19, 2019 07:27
Codegen experiment
/**
* RCTNativeTestModuleSpec.h
*
* NOTE: This file is codegenerated.
*/
#import <vector>
#import <Foundation/Foundation.h>