Skip to content

Instantly share code, notes, and snippets.

Being Happy

Jonathan Cardoso Machado JCMais

Being Happy
View GitHub Profile
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 / 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 /
Last active Sep 17, 2020 — forked from clarkdave/createPages.ts
TypeScript + Gatsby config and node API


  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 / 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) {
lucianomlima /
Created Jun 5, 2019
Connect to Android devices with ADB through wi-fi
function adb_connect {
# PORT used to connect. Default: 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 /
Created May 10, 2019
Reload react-native on Android from CLI
adb shell input keyevent 82 && adb shell input keyevent 19 && adb shell input keyevent 23
sibelius / Sample.tsx
Created Feb 27, 2019
useRelayPagination to be used with React Native Flatlist
View Sample.tsx
const {
} = useRelayPagination(relay, users);
const isRefreshing = isFetchingEnd || isFetchingTop;
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",

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 /
Last active Sep 27, 2020
Interaction tracing with React

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.