Skip to content

Instantly share code, notes, and snippets.

View vincicat's full-sized avatar

Vinci vincicat

View GitHub Profile
@vincicat
vincicat / random-markers.js
Created December 4, 2019 05:21
Generate Random Markers
function generateMarkers(fromCoordinate) {
const result = [];
const {latitude, longitude} = fromCoordinate;
for (let i = 0; i < 10; i++) {
let id = Math.ceil(Math.random() * 10000);
const newMarker = {
coordinate: {
latitude: latitude + (Math.random() - 0.5) * (LATITUDE_DELTA / 2),
longitude: longitude + (Math.random() - 0.5) * (LONGITUDE_DELTA / 2),
},
@vincicat
vincicat / apollo-undocumented.md
Last active January 14, 2020 03:08
Apollo client notes

Rendering Cycle

Every useQuery() will cause 3 renderings after mount:

  1. with cache-data (StatusCode 1)
  2. "now loading" (StatusCode 1)
  3. with data-result, or error (StatusCode 7)

If you need some prefetching, consider using useLazyQuery()

Cache

@vincicat
vincicat / react-hooks-memo.md
Last active January 8, 2020 13:04
memo: react hooks

The Basic

import

import React, {useEffect} from 'react';

Pick your hooks

useEffect

@vincicat
vincicat / App.jsx
Created January 9, 2020 07:52
basic useContext()
import React from 'react';
import { AppProvider } from "./AppContext";
import { AppContainer } from "./AppContainer";
function App() {
return (
<AppProvider>
<AppContainer />
</AppProvider>
);
@vincicat
vincicat / core.js
Created February 17, 2020 10:19
Example for crypto-js#259
/*globals window, global, require*/
/**
* CryptoJS core components.
*/
var CryptoJS = CryptoJS || (function (Math, undefined) {
var crypto;
// Native crypto from window (Browser)
@vincicat
vincicat / parse.js
Created October 24, 2021 20:24
parsing Unity YAML
// for js-yaml 4.0, to avoid unity "YAML unknown tag" error: schema is required
import yaml from "js-yaml";
import path from "path";
import fs, { readFileSync } from "fs";
function parseAssetFile(p, assetsPath) {
// Read the File
let file = fs.readFileSync(path.resolve(assetsPath, p), { encoding: "utf-8" });
// From github: https://github.com/nodeca/js-yaml/issues/100
@vincicat
vincicat / Valheim_Decor_mod.md
Last active October 26, 2021 16:57
List of the intresting Valheim mod
@vincicat
vincicat / useScreenReaderEnabled.js
Created June 20, 2022 14:35
Hook for properly use `screenReaderEnabled` (RN 0.68+)
import React, { useEffect, useState } from 'react';
import { AccessibilityInfo } from 'react-native';
const useScreenReaderEnabled = () => {
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false);
useEffect(() => {
const screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
"screenReaderChanged",
(screenReaderEnabled) => {
setScreenReaderEnabled(screenReaderEnabled);
@vincicat
vincicat / MapExample.js
Created August 11, 2022 15:13
Bottom Sheet Example with Map (Standalone)
// @gorhom/bottom-sheet@^4
import React, {
useCallback,
useLayoutEffect,
useMemo,
useRef,
// useState,
} from 'react';
import { View, StyleSheet, Dimensions, Text } from 'react-native';
import MapView from 'react-native-maps';