Skip to content

Instantly share code, notes, and snippets.

View brenttimmermans's full-sized avatar
🏎️

Brent Timmermans brenttimmermans

🏎️
View GitHub Profile
@brenttimmermans
brenttimmermans / launch.json
Created March 26, 2020 16:06
Base launch.json for VSCode Jest debugging
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest - All",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--no-cache"],
"console": "integratedTerminal",
@brenttimmermans
brenttimmermans / token.js
Last active June 28, 2019 09:00
Extract properties from JSON Web Token body
const jwtDecode = require('jwt-decode')
const { pick } = require('lodash')
/**
* Pick properties from JWT
*
* @param {String} token JSON Web Token
* @param {String || Array} props Single property (String) or multiple properties (Array)
*
* @returns Object containing all props
@brenttimmermans
brenttimmermans / auto-refresh.js
Created October 12, 2018 13:53
Wrapper for calling a functions with fixed interval. Useful for refreshing state of a React component 👍
import randomInt from 'random-int'
const REFRESH_INTERVAL = 2 * 60 * 1000 // ms
const REFRESH_TIME_OUT = 30 * 1000 // ms
export function refresh (refreshFn, interval = REFRESH_INTERVAL) {
let intervalToken
refreshFn()
@brenttimmermans
brenttimmermans / withContext.js
Last active April 7, 2018 15:37
Wrapper for passing context to React component with new context API
import React from 'react';
export default function withContext(Context) {
return (Component) => (props) => (
<Context.Consumer>
{ context => <Component {...props} context={context} /> }
</Context.Consumer>
);
}