Skip to content

Instantly share code, notes, and snippets.

import { render, screen } from '@testing-library/react';
import React, { createContext } from 'react';
import { ComposeProviders } from './ComposeProviders';
const DummyContextA = createContext<string>('');
const DummyContextB = createContext<string>('');
const DummyContextC = createContext<string>('');
const DummyApp: React.FC = () => (
{
"breadcrumbs.enabled": true,
"editor.accessibilitySupport": "off",
"editor.autoClosingBrackets": "never",
"editor.autoClosingQuotes": "never",
"editor.autoSurround": "never",
"editor.cursorBlinking": "phase",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": true,
"editor.emptySelectionClipboard": false,
{
const iframe = document.createElement('iframe');
iframe.src = 'data:text/html,';
document.body.appendChild(iframe);
const guestWin = iframe.contentWindow;
const guestWinKeys = Object.keys(guestWin);
const hostWinKeys = Object.keys(window);
const diff = hostWinKeys.filter((key) => {
return !guestWinKeys.includes(key);
}).sort();
if (
typeof window.safeview !== 'undefined' &&
typeof window.safeview.feedback_bar !== 'undefined' &&
typeof window.safeview.feedback_bar.onBypassClick === 'function' &&
confirm('Safeview detected. Bypassing.')
) window.safeview.feedback_bar.onBypassClick();
@j-
j- / delete-stale-branches.sh
Created September 1, 2020 01:46
Find stale branches on your remote and delete them
#!/bin/bash
REMOTE='origin'
SINCE='1 week ago'
DRY_RUN=''
todelete=()
for arg in "$@"
do
case $arg in
@j-
j- / pubsub.test.ts
Last active July 10, 2019 01:45
Really simple pubsub
import { create } from './pubsub';
it('`create()` returns object with `publish` and `subscribe` fns', () => {
const result = create();
expect(result).toBeInstanceOf(Object);
expect(result).toHaveProperty('publish');
expect(result.publish).toBeInstanceOf(Function);
expect(result).toHaveProperty('subscribe');
expect(result.subscribe).toBeInstanceOf(Function);
});
@j-
j- / features.jsx
Last active February 11, 2019 04:27
Render content conditionally using feature flag value detection
import React from "react";
import ReactDOM from "react-dom";
// Feature flag storage
const features = new Map();
features.set('editor', true);
features.set('sandbox', true);
features.set('env', 'sit1');
// Some dummy feature
interface Permutation extends Array<number> {}
interface PermutationList extends Array<Permutation> {}
/**
* Gets all permutations of a given list of digits. Results are not guaranteed
* to be uniqe.
*/
export const getPermutations = (input: Permutation): PermutationList => (
input.length <= 1 ? [input] : input.reduce((result, n, i, arr) => ([
...result,
@j-
j- / fauxcus.html
Created November 7, 2018 04:31
Set 'focus' on any HTML element
<!doctype html>
<meta charset="utf-8">
<title>Fauxcus</title>
<nav>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</nav>
import * as React from 'react';
export interface Props {
children: number;
}
const Dollars: React.StatelessComponent<Props> = ({ children }) => (
<>
{children.toLocaleString('en-AU', {
style: 'currency',