Skip to content

Instantly share code, notes, and snippets.

View piotrwitek's full-sized avatar

Piotr Witek piotrwitek

View GitHub Profile
@threepointone
threepointone / for-snook.md
Last active August 26, 2023 15:43
For Snook

https://twitter.com/snookca/status/1073299331262889984?s=21

‪“‬In what way is JS any more maintainable than CSS? How does writing CSS in JS make it any more maintainable?”

‪Happy to chat about this. There’s an obvious disclaimer that there’s a cost to css-in-js solutions, but that cost is paid specifically for the benefits it brings; as such it’s useful for some usecases, and not meant as a replacement for all workflows. ‬

‪(These conversations always get heated on twitter, so please believe that I’m here to converse, not to convince. In return, I promise to listen to you too and change my opinions; I’ve had mad respect for you for years and would consider your feedback a gift. Also, some of the stuff I’m writing might seem obvious to you; I’m not trying to tell you if all people of some of the details, but it might be useful to someone else who bumps into this who doesn’t have context)‬

So the big deal about css-in-js (cij) is selectors.

// funciona somente com v3.1.6, essa estrategia de end/continue
// era um backdoor para fazer recursao em types, recursao funcionava somente com interfaces
// antigamente pela resolucao de tipos ser lazyness e nao acabar fazendo o compiler cair
// potencialmente em um looping infinito na resolucao do tipo, por causa disto tem validacao
// no compiler agora e codigos nesse estilo sao barrados pelo compiler
type Init<T extends any[], TTail extends any[] = TailArray<T>> = CastArray<{
[K in keyof TTail]: T[keyof T & K];
}>
@piotrwitek
piotrwitek / download-link-using-blob.tsx
Last active May 27, 2019 20:54
create download link for protected resources using blob
@KiaraGrouwstra
KiaraGrouwstra / stdlib.ts
Last active March 24, 2020 03:17
Type-level standard library for TypeScript
// NOTE: code now moved to https://github.com/tycho01/typical
// older revision left here, but it no longer runs well in TS Playground
export type Obj<T> = { [k: string]: T };
export type NumObj<T> = { [k: number]: T };
// export type List = ArrayLike; // no unapplied generic types :(
export type List<T> = ArrayLike<T>;
// progress: https://github.com/Microsoft/TypeScript/issues/16392
export function force<T, V extends T>() {}
@javilobo8
javilobo8 / download-file.js
Last active April 9, 2024 12:01
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@piotrwitek
piotrwitek / tslint.json
Last active April 20, 2019 01:18
TSLint rules with ESLint/React extension based on airbnb style guide
{
"rules": {
"align": [
true,
"parameters",
"arguments",
"statements"
],
"ban": false,
"class-name": true,
@piotrwitek
piotrwitek / linting-in-typescript-react.md
Last active March 10, 2019 23:49
Investigation on linting options available for TypeScript & React

Recent TSLint v5.0 config

https://github.com/piotrwitek/react-redux-typescript-guide#tslintjson

Use TSLint with rules based on airbnb style guide and some extensions

  • TSLint airbnb style guide:
    https://github.com/excelmicro/typescript
  • TSLint React rules:
    https://github.com/palantir/tslint-react
  • Manually add missing airbnb ESLint rules for TSLint:
    https://github.com/buzinas/tslint-eslint-rules
@staltz
staltz / introrx.md
Last active April 25, 2024 04:18
The introduction to Reactive Programming you've been missing