Skip to content

Instantly share code, notes, and snippets.

View sstur's full-sized avatar

Simon Sturmer sstur

View GitHub Profile
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import { createRenderer } from 'react-test-renderer/shallow';
it('should render correctly', () => {
let renderer = createRenderer();
renderer.render(<App />);
import { useEffect, useState } from 'react';
let loadedScripts: Map<string, Promise<null>> = new Map();
export default function useScript(src: string) {
let [isLoaded, setLoaded] = useState(false);
useEffect(() => {
let promise = loadedScripts.get(src) || loadScript(src);
promise.then(() => {
setLoaded(true);
import { useCallback, useState, useRef } from 'react';
export function useDebounce<T>(initialValue: T, ms: number) {
let [value, setValue] = useState(initialValue);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let timeout = useRef<any>();
let debouncedSetter = useCallback(
(newValue: T) => {
clearTimeout(timeout.current);
timeout.current = setTimeout(() => {
export type JsonPrimitive = null | boolean | number | string;
export type JsonArray = Array<JsonValue>;
export type JsonObject = { [key: string]: JsonValue };
export type JsonValue = JsonPrimitive | JsonArray | JsonObject;
@sstur
sstur / package.json
Last active September 25, 2019 10:39 — forked from darcien/package.json
Jest configuration for RN with expo
{
"jest": {
"preset": "jest-expo",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
"^.+\\.tsx?$": "ts-jest"
},
"testMatch": [
"**/__tests__/**/*.ts?(x)",
"**/?(*.)+(spec|test).ts?(x)"
// node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _helperPluginUtils() {
@sstur
sstur / backup-databases.cmd
Last active February 15, 2019 13:19
MySQL and MS SQL backup scripts for Windows
@echo off
cd "%~dp0"
backup-mysql.cmd
backup-mssql.cmd
@sstur
sstur / promise-streams.js
Last active February 13, 2018 03:23
[RFC] Node Streams to Promise-based Streams
// @flow
import fs from 'fs';
import {join} from 'path';
async function main() {
let filePath = join(__dirname, '../assets/image.jpg');
// The first one uses Promise-based readable stream.
await getFileSizeOne(filePath);
// The second one uses "for await" async iterator approach.
await getFileSizeTwo(filePath);
@sstur
sstur / asyncAwait.js
Last active February 21, 2017 09:23 — forked from oshimayoan/asyncAwait.js
Fetching github users, orgs, and repos and print it.
// @flow
/* global fetch */
/* eslint-disable babel/no-await-in-loop */
type JSONData = null | string | number | boolean | {[key: string]: JSONData} | Array<JSONData>;
function handleResponseJSON(response: Response): Promise<JSONData> {
return response.json();
}
@sstur
sstur / html-parser.js
Last active February 9, 2017 19:09
Pure JS HTML Parser (ported from CKEditor 4.2)
/*!
* HTML Parser
* Ported from CKEditor 4.2 (f74e558351)
*
*/
/*global require, exports, module, define */
var HTMLParser;
(function(definition) {
if (typeof exports == 'object' && typeof module == 'object') {
// CommonJS/Node