Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Being Happy

Jonathan Cardoso Machado JCMais

🚀
Being Happy
View GitHub Profile
@sibelius
sibelius / useSWReg.tsx
Created May 26, 2020
use Service Worker Registration hook
View useSWReg.tsx
import firebase from 'firebase/app';
import 'firebase/messaging';
import { useEffect, useRef } from 'react';
import config from '../config';
import firebaseConfig from './firebaseConfig';
import { PushTokenAddMutation } from './__generated__/PushTokenAddMutation.graphql';
import { PushTokenAdd, USER_PUSHENDPOINT_TYPE } from './PushTokenAddMutation';
@sibelius
sibelius / applyMiddleware.ts
Created Apr 7, 2020
trace resolver to generate span for each GraphQL resolver
View applyMiddleware.ts
import { addMiddleware } from 'graphql-add-middleware';
addMiddleware(schema, traceResolveMiddleware);
@JohnAlbin
JohnAlbin / _README.md
Last active Sep 17, 2020 — forked from clarkdave/createPages.ts
TypeScript + Gatsby config and node API
View _README.md

README

  1. When Gatsby starts up, it will read gatsby-config.js first.
  2. As you can see below, we use that file to require('ts-node').register() which registers a TypeScript evaluator that will be used when Gatsby reads all other API Javascript files. In other words, we only need to do this once in our entire codebase and not in other Gatsby files like gatsby-node.js.
  3. Our gatsby-config.js re-exports all the exported variables available in gatsby-config.ts.
@sibelius
sibelius / safeGoBack.tsx
Created Jul 19, 2019
Safe goBack helper to avoid leaving the site
View safeGoBack.tsx
export const safeGoBack = (
history: History,
alternativeRoute: string,
) => {
if (history.length > 2) {
history.goBack();
return;
}
history.push(alternativeRoute);
@lucianomlima
lucianomlima / adb_connect.sh
Created Jun 5, 2019
Connect to Android devices with ADB through wi-fi
View adb_connect.sh
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
@lucasbento
lucasbento / reload.sh
Created May 10, 2019
Reload react-native on Android from CLI
View reload.sh
adb shell input keyevent 82 && adb shell input keyevent 19 && adb shell input keyevent 23
@sibelius
sibelius / Sample.tsx
Created Feb 27, 2019
useRelayPagination to be used with React Native Flatlist
View Sample.tsx
const {
isFetchingEnd,
isFetchingTop,
onRefresh,
onEndReached,
} = useRelayPagination(relay, users);
const isRefreshing = isFetchingEnd || isFetchingTop;
<FlatList
@JCMais
JCMais / k8s-cluster.json
Created Jan 4, 2019
Grafana dashboards from kubernetes app but using prometheus metrics instead of the datasource from the plugin
View k8s-cluster.json
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
View save-load.md

Deterministic save load in Factorio

One of the key parts of the save/load process in Factorio is that it must be deterministic. This means that for a given save file (when no external factors change) saving, exiting, and loading the save shouldn't change any observable behavior.

There are a few reasons and benefits for this strict requirement:

  • Without it: You couldn't join a running multiplayer game (and by proxy save, exit, and resume one)
  • Without it: the replay system wouldn't work if you ever saved, exited, and resumed playing.
  • With it: we can easily test that saving and loading produces no observable change letting us know we implemented save/load correctly.
  • With it: you won't see things change randomly as a result of "reloading" like you do in so many other games.
@bvaughn
bvaughn / index.md
Last active Sep 27, 2020
Interaction tracing with React
View index.md

Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

This Gist provides some high-level docum

You can’t perform that action at this time.