TIL is my collection of short, technical daily learnings. 236 and counting.
Light Bulb Series Encoding
I needed to replace an “A19” light bulb. What does “A19” mean? ...
TIL is my collection of short, technical daily learnings. 236 and counting.
I needed to replace an “A19” light bulb. What does “A19” mean? ...
In Vim Normal mode, * searches forward for the next occurrence of word. But what goes back? ...
If I’ve defined a function in the Python REPL, I can read its definition with inspect.getsource. ...
In the Python REPL, the help function provides a help message about its argument. ...
Jira does have a “Start Standup” button, but it’s hidden and not well documented. ...
I have a cron job that opens a program every day at a certain time. How can I also close it with a cron job? ...
My friend Josh recently wrote about a common mistake using pbcopy, Apple’s pasteboard utility. ...
Anytime Chrome loads a webpage, you can pause script execution without a debugger. ...
Sometimes in TypeScript we’d like to say a function can either have one typed prop, or the other, never both and never neither. This can be achieved with a union type and type never: type Props = { markdown: string, copy?: never } | { markdown?: never, copy: string} }; const component = ({ markdown, copy }: Props) => markdown ? parseMarkdown(markdown) : <>copy</>; console.log(component({ markdown: "### Important" })) // <h3>Important</h3> console.log(component({ copy: "Just information" })) // <>Just information</> console.log(component({ copy: "Just information", markdown: "### That conflicts })) // ❌ Type error console.log(component({})) // ❌ Type error Our component can receive a string of markdown, which it will parse, or raw copy, which it will not parse. Always just one, never both, and never neither.
If you’re creating a hyperlink with query params, and those param values can have plus signs, it’s important to encode them values. We do this with encodeURIComponent: const email = `jake+testing@example.com` const loginLink = `https://example.com/login?email=${encodeURIComponent(email)}` window.open(loginLink) If you skip this step and try to read the query parameters received by ’example.com’ your email param value may be interpreted as with spaces instead of pluses, i.e. jake testing@example.com. Per the docs: Within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must be encoded. This method was used to make query URIs easier to pass in systems which did not allow spaces. ...