Skip to content

Instantly share code, notes, and snippets.

@piecyk
piecyk / List.jsx
Created April 14, 2021 18:12
useVirtual wrap with Profiler
import * as React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import { useVirtual } from "../../../";
function RowVirtualizerDynamic({ rows }) {
const parentRef = React.useRef();
@piecyk
piecyk / useMeasurements.tsx
Created May 29, 2020 09:52
React hook wrapping ResizeObserver
import React, { useReducer, useRef, useCallback, useLayoutEffect } from 'react'
import _ from 'lodash'
import ResizeObserver from 'resize-observer-polyfill'
import { assertNever } from 'lib/misc/Assert'
type DOMRectKeys = keyof DOMRectReadOnly
interface State<T extends DOMRectKeys> {
keys: T[]
value: Pick<DOMRectReadOnly, T> | undefined
/** Used by Flavor to mark a type in a readable way. */
export interface Flavoring<FlavorT> {
_type?: FlavorT;
}
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;
/** Used by Brand to mark a type in a readable way. */
export interface Branding<BrandT> {
_type: BrandT;
@piecyk
piecyk / sds011
Created November 25, 2017 15:51 — forked from kadamski/sds011
SDS011 dust sensor reading
#!/usr/bin/python
# coding=utf-8
# "DATASHEET": http://cl.ly/ekot
from __future__ import print_function
import serial, struct, sys, time
DEBUG = 1
CMD_MODE = 2
CMD_QUERY_DATA = 4
CMD_DEVICE_ID = 5
@piecyk
piecyk / sds011
Created November 25, 2017 15:51 — forked from kadamski/sds011
SDS011 dust sensor reading
#!/usr/bin/python
# coding=utf-8
# "DATASHEET": http://cl.ly/ekot
from __future__ import print_function
import serial, struct, sys, time
DEBUG = 1
CMD_MODE = 2
CMD_QUERY_DATA = 4
CMD_DEVICE_ID = 5
import {React} from 'lib/vendor/react';
import _ from 'lib/vendor/lodash';
import {withContentRect} from 'lib/vendor/react-measure/Measure';
import {pure, compose} from 'lib/vendor/recompose';
type ComponentType<P = {}> = React.ComponentClass<P> | React.StatelessComponent<P>;
export type Breakpoint =
| 'small'
@piecyk
piecyk / HOCBaseRender.tsx
Created August 28, 2017 13:57 — forked from tejacques/HOCBaseRender.tsx
React Higher Order Components in TypeScript
import * as React from 'react';
import { Component } from 'react';
export default function HOCBaseRender<Props, State, ComponentState>(
Comp: new() => Component<Props & State, ComponentState>) {
return class HOCBase extends Component<Props, State> {
render() {
return <Comp {...this.props} {...this.state}/>;
}
}
import React from 'react';
import TimePicker from 'rc-time-picker';
import _ from 'lodash';
import 'rc-time-picker/assets/index.css';
import './CustomTime.scss';
function maybe(fn, value) {
if (_.isFunction(fn)) {
fn(value);
import {React} from 'lib/vendor/react';
import _ from 'lib/vendor/lodash';
import Tooltip from 'lib/ui/Tooltip/Tooltip';
import hashCode from 'lib/algorithms/hashCode';
const EmptyString = '';
const WhiteSpace = ' ';
const Dots = '...';
import path from 'path';
import webpack from 'webpack';
import autoprefixer from 'autoprefixer';
import CleanWebpackPlugin from 'clean-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import devPlugins from './devPlugins';
import prodPlugins from './prodPlugins';
const basePlugins = (isDev, projectRootDir, outPath, srcPath) => [