Skip to content

Instantly share code, notes, and snippets.

View disintegrator's full-sized avatar

Georges Haidar disintegrator

View GitHub Profile
@disintegrator
disintegrator / TypeHolesInTS.md
Last active November 3, 2021 02:45
Type holes in TypeScript

Type holes in TypeScript

In TypeScript there are a few ways you can sidestep type inference and the compiler to introduce type holes in your code. Type holes are parts of the code where we’ve lied or hid information from the compiler and can be a source of bugs that are not present in properly typed code. The common ones I see are listed below in order of really bad to bad.

Type assertions

const something = getValue() as any;
const cat = dog as Cat;
@disintegrator
disintegrator / https-during-dev.macos.sh
Last active January 8, 2024 00:40
Use Caddy, mkcert and dnsmasq to expose your development server over HTTPS
brew install caddy mkcert nss dnsmasq
mkcert -install
mkcert '*.app.test' '*.cdn.test'
# rename the certs and move them under /usr/local/etc/caddy/certs
cat <<EOF > /usr/local/etc/caddy/Caddyfile
*.app.test:443, *.cdn.test:443 {
@disintegrator
disintegrator / propTypes.ts
Created September 5, 2018 22:29
Get the prop types of a react component class, functional component or string corresponding to HTML tag name
import * as React from "react";
/**
* Given a JSX.IntrinsicElement[...], get its attributes
*/
type Attributes<E> = E extends React.DetailedHTMLProps<infer Attr, any>
? Attr
: never;
/**
@disintegrator
disintegrator / PropType.tsx
Created May 1, 2018 22:46
PropType conditional type inference in TypeScript
import { ComponentType } from "react";
/**
* For any type T that is a React.ComponentType give me the type of its Props
*
*/
export type PropType<T> = T extends ComponentType<infer P> ? P : never;
// USAGE:
import { Component, Fragment } from "react";
@disintegrator
disintegrator / Value.ts
Last active April 26, 2018 12:23
Value component
import * as React from "react";
interface Props<T> {
initial?: T;
children: (r: { value?: T; onChange: (value: T) => void }) => React.ReactNode;
}
interface State<T> {
value?: T;
}
@disintegrator
disintegrator / wdio.conf.js
Created June 9, 2017 04:13
Run Chrome Headless with WebdriverIO and selenium-standalone
exports.config = {
capabilities: [
{
browserName: 'chrome',
chromeOptions: {
args: ['headless', 'disable-gpu'],
},
},
],
services: ['selenium-standalone'],
@disintegrator
disintegrator / redux.ts
Created May 11, 2017 23:25
Redux TS boilerplate
export type ActionType = string;
export interface Action<T extends ActionType> {
type: T;
}
export interface BasicAction<T extends ActionType, P> extends Action<T> {
payload: P;
}
@disintegrator
disintegrator / main.ts
Last active November 14, 2020 06:58
RxJS + Axios
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { Observable } from 'rxjs';
const fromRequest = (request: AxiosRequestConfig) =>
new Observable<AxiosResponse>(
(o) => {
const source = axios.CancelToken.source();
o.add(() => source.cancel('Operation canceled by the user.'));

Keybase proof

I hereby claim:

  • I am disintegrator on github.
  • I am disintegrator (https://keybase.io/disintegrator) on keybase.
  • I have a public key whose fingerprint is B27D E9C9 E08C A86E F46B 84FA F60F 7D8E 4BAD 4281

To claim this, I am signing this object:

@disintegrator
disintegrator / actionhelpers.js
Last active November 10, 2015 04:01
Redux async action helpers
import * as ra from 'redux-actions'
export const {createAction} = ra
export function createAsyncAction(name, worker) {
const request = `${name}_REQUEST`
const success = `${name}_SUCCESS`
const fail = `${name}_FAIL`
const stages = {
request: createAction(request),
success: createAction(success),