This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* It merges multiple HeadersInit objects into a single Headers object | |
* @param entries Any number of HeadersInit objects | |
* @returns a new Headers object with the merged headers | |
*/ | |
function mergeHeaders(...sources: HeadersInit[]) { | |
let result = new Headers() | |
for (let headersInit of sources) { | |
let headers = new Headers(headersInit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Specify<T> = T extends any ? (k: T) => void : never | |
// Real intersection: UnionToIntersection<`c${string}` | 'car'> will become `c${string}` | |
type UnionToIntersection<T> = Specify<T> extends (a: infer A) => void ? A : never; | |
// Transforms 'a' | 'b' into ((f: "a") => void) & ((f: "b") => void) | |
type UnionToOverloads<U> = UnionToIntersection<Specify<U>>; | |
// Still figuring out why this happens | |
// ((f: "a") => void) & ((f: "b") => void) will become "b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Specify<T> = T extends any ? (k: T) => void : never | |
// Real intersection: UnionToIntersection<`c${string}` | 'car'> will become `c${string}` | |
type UnionToIntersection<T> = Specify<T> extends (a: infer A) => void ? A : never; | |
// Transforms 'a' | 'b' into ((f: "a") => void) & ((f: "b") => void) | |
type UnionToOverloads<U> = UnionToIntersection<Specify<U>>; | |
// Still figuring out why this happens | |
// ((f: "a") => void) & ((f: "b") => void) will become "b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
theme: { | |
extend: { | |
// ... | |
}, | |
}, | |
plugins: [ | |
function ({ addVariant }) { | |
addVariant('children', '& > *') | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const controller = new AbortController() | |
const toBeAborted = fetch('/', { signal: controller.signal }) | |
controller.abort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const res = await fetch('/') | |
const reader = res.body.getReader() | |
const data = await reader.read() | |
new TextDecoder().decode(data.value) | |
while(!data.done) { | |
console.log(new TextDecoder().decode(data.value)) | |
data = await reader.read() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react' | |
function setState(newState, updateContext) { | |
this.state = { ...this.state, ...newState } | |
this.listeners && | |
this.listeners.forEach(([context, listener]) => { | |
updateContext === context && listener(this.state) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -F, -ane \ | |
'puts $F[15].gsub(/"/, "") unless $F[15] !~ /\w+@\w+\.\w{2,5}/' \ | |
~/Desktop/cadastros.csv > emails.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import compact from 'lodash/compact' | |
import get from 'lodash/get' | |
import head from 'lodash/head' | |
import orderBy from 'lodash/orderBy' | |
const getFirstValue = (el, path) => { | |
const paths = path.split('|') | |
const values = paths.map(path => get(el, path)) | |
return head(compact(values)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useOpenExternalLinksInNewTab = (el = typeof document === 'undefined' ? null : document) => { | |
useEffect(() => { | |
if (el && typeof window !== 'undefined') { | |
const links = el.querySelectorAll( | |
`a[href*="//"]:not([href*="${window.location.host}"])`, | |
) | |
links.forEach((link) => { | |
link.setAttribute('target', '_blank') | |
link.setAttribute('rel', 'noopener') | |
}) |
NewerOlder