Skip to content

Instantly share code, notes, and snippets.

View skovy's full-sized avatar
🐙

Spencer Miskoviak skovy

🐙
View GitHub Profile
@skovy
skovy / audit.ts
Last active November 1, 2022 16:12
Audit the number of `any` keywords and `@ts-expect-error` directives
import * as fs from 'fs';
import * as glob from 'glob';
import { parse } from '@babel/parser';
import traverse from '@babel/traverse';
export const isExpectErrorComment = (comment: string): boolean =>
comment.trim().startsWith('@ts-expect-error TS(');
let totalAnyKeywords = 0;
let totalExpectErrorDirectives = 0;
@skovy
skovy / card-example.tsx
Last active May 9, 2022 22:41
Example Card component
<Card variant="callout">
<Stack spacing="large">
<Heading variant="small" as="h2">
This is a Card
</Heading>
<Text>Cards are ways...</Text>
<Button variant="primary" as="button">
Got it
</Button>
</Stack>
const HIGHLIGHT_WIDTH = 2;
const HIGHLIGHT_SELECTOR = '[data-component]';
function createHighlighterForElement(component: HTMLElement) {
const highlighter = document.createElement('div');
const { x, y, width, height } = component.getBoundingClientRect();
highlighter.style.cssText = `
top: ${y + window.scrollY - HIGHLIGHT_WIDTH}px;
left: ${x - HIGHLIGHT_WIDTH}px;
def current_branch
`git rev-parse --abbrev-ref HEAD`.strip
end
import { Action, calculateActions, arrayContentsEqual } from './actions';
export const useActions = (): Action[] => {
const [actions, setActions] = React.useState(calculateActions());
React.useEffect(() => {
function callback() {
const newActions = calculateActions();
if (!arrayContentsEqual(newActions, actions)) {
setActions(newActions);
// actions/index.ts
import * as name from './actions/name';
// other action imports ...
export interface Action {
name: string;
canPerform(): boolean;
perform(): void;
}
// actions/name.ts
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
export function canPerform() {
try {
return !!screen.getByLabelText(/first name/i) && !!screen.getByLabelText(/last name/i);
} catch (error) {
return false;
}
import React from 'react';
import ReactDOM from "react-dom";
function DevTools() {
return <div>You now have your own DevTools!</div>;
}
export function install() {
const devToolsRoot = document.createElement("div");
document.body.appendChild(devToolsRoot);
function loadDevtools() {
if (process.env.NODE_ENV === 'development') {
return import('dev_tools').then((devTools) => devTools.install());
}
}