Skip to content

Instantly share code, notes, and snippets.

Donald Pipowitch donaldpipowitch

Block or report user

Report or block donaldpipowitch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@donaldpipowitch
donaldpipowitch / example.ts
Created Jul 25, 2019
Share useState with useContext
View example.ts
import React, { createContext, useState, useContext, FC } from 'react';
type ContextValue = [boolean, (value: boolean) => void] | undefined;
const FullwidthContext = createContext<ContextValue>(undefined);
const defaultState = false;
export const FullwidthProvider: FC = ({ children }) => {
const state = useState(defaultState);
return (
@donaldpipowitch
donaldpipowitch / usePrevious.ts
Created Jun 14, 2019
React Hook to use previous value
View usePrevious.ts
import { useEffect, useRef } from 'react';
function usePrevious<T>(value: T) {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
@donaldpipowitch
donaldpipowitch / useScrollBottom.ts
Created May 29, 2019
React Hook to detect if a scrollable element reached the end.
View useScrollBottom.ts
function useScrollBottom<T extends HTMLElement>(offset?: number) {
const [atBottom, setAtBottom] = useState(false);
const scrollEl = useRef<T>(null);
useEffect(() => {
const { current } = scrollEl;
if (current) {
// by default we take the clientHeight into account, so "bottom" begins as soon as the last
// visible piece appears in the scrollable area
const withOffset = offset === undefined ? current.clientHeight : offset;
@donaldpipowitch
donaldpipowitch / README.md
Last active Mar 10, 2019
Use @ts-check for custom ESLint rules
View README.md

This is a very basic example which shows how you can create a simple ESLint rule with @ts-check support. This example features the rule and a test. The rule checks, if you pass an absolute URL to a history.push function or not.

If you want to use this rule in your ESLint configuration without publishing the rule there is a caveat. AFAIK you can't simply include the path to your rule in your .eslintrc.js (correct me if I'm wrong). You need to pass the directory of this rule to the CLI as --rulesdir "./path/to/rules" and if you use VS Code with the ESLint extension you need to set "eslint.options": { "rulePaths": ["./path/to/rules"] }, in your settings.json as well. Only then you can add the rule to your config:

module.exports = {
  // ...yourCurrentConfig,
  rules: {
    // ...yourCurrentConfig.rules,
    'some-rule': 'error'
@donaldpipowitch
donaldpipowitch / axe.js
Created Nov 26, 2018
aXe based a11y checks in your CI for Storybook
View axe.js
const puppeteer = require('puppeteer');
const chalk = require('chalk');
const { green, red, cyan, grey, bold } = chalk;
// we assume storybook can visited at http://localhost:9001
const url = 'http://localhost:9001/iframe.html';
const runAxe = () =>
new Promise((resolve, reject) =>
@donaldpipowitch
donaldpipowitch / index.js
Created May 14, 2018
async generator function: count until 5
View index.js
// works in current chrome (logs from 1 to 5 every second)
function sleep(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
async function* seconds() {
let second = 0;
while (true) {
await sleep(1000);
View xsel.strace
18154 execve("/usr/bin/xsel", ["xsel"], [/* 18 vars */]) = 0
18154 brk(NULL) = 0x1cbc000
18154 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
18154 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
18154 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
18154 fstat(3, {st_mode=S_IFREG|0644, st_size=48267, ...}) = 0
18154 mmap(NULL, 48267, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fda9d0d2000
18154 close(3) = 0
18154 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
18154 open("/usr/lib/x86_64-linux-gnu/libX11.so.6", O_RDONLY|O_CLOEXEC) = 3
View strace ping
11433 execve("/bin/ping", ["ping", "google.com"], [/* 14 vars */]) = 0
11433 brk(NULL) = 0xc9b000
11433 fcntl(0, F_GETFD) = 0
11433 fcntl(1, F_GETFD) = 0
11433 fcntl(2, F_GETFD) = 0
11433 access("/etc/suid-debug", F_OK) = -1 ENOENT (No such file or directory)
11433 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
11433 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
11433 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
11433 fstat(3, {st_mode=S_IFREG|0644, st_size=33275, ...}) = 0
@donaldpipowitch
donaldpipowitch / README.md
Created Sep 14, 2017
Relations in JSON-LD
View README.md

I don't know, if it is correct to use IANA relations in this way and to add custom relations.

But these examples are parsed in the same way.

inlined relations

{
  "http://www.iana.org/assignments/relation/self": {
    "@id": "https://api.example.com/users/1"
@donaldpipowitch
donaldpipowitch / README.md
Last active Aug 28, 2017
JSON-LD examples
View README.md

Not sure, if these are all valid.

I basically want to add links to my data. In HAL it probably would lool like this:

{
    "_links": {
        "self": {
            "href": "https://example.com/users/1"
        },
You can’t perform that action at this time.