This file contains hidden or 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 delayedPrint = (content) => new Promise(r => setTimeout(() => r() & console.log(content), 1000)); | |
| await ["João", "Maria", "todo mundo"].reduce( | |
| (chained, n) => chained.then(() => delayedPrint(`Oi, ${n}!`)), | |
| Promise.resolve() | |
| ); |
This file contains hidden or 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
| defmodule BalancedOctopus do | |
| @opening_to_closing %{"(" => ")", "[" => "]", "{" => "}"} | |
| @closing_to_opening %{")" => "(", "]" => "[", "}" => "{"} | |
| def balanced?(text, stack \\ []) | |
| def balanced?("", []), do: true | |
| def balanced?(_text, :error), do: false | |
| def balanced?("", _pending_stack), do: false | |
| def balanced?(text, stack) do |
This file contains hidden or 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
| defmodule Comp do | |
| def equals?(same, same), do: true | |
| def equals?(one, another), do: false | |
| end | |
| IO.inspect Comp.equals?(4, 2) | |
| # false | |
| IO.inspect Comp.equals?(42, 42) | |
| # true |
This file contains hidden or 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
| class Maybe: | |
| condition_fn = None | |
| then_fn = None | |
| otherwise_fn = None | |
| def __init__(self, condition_fn): | |
| self.condition_fn = condition_fn | |
| def then(self, then_fn): | |
| self.then_fn = then_fn |
This file contains hidden or 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
| interface OpfsAdapter<T> { | |
| persist: (data: T) => Promise<void>; | |
| retrieve: () => Promise<T | null>; | |
| } | |
| export async function makeOpfsAdapter<T>(filename: string): Promise<OpfsAdapter<T>> { | |
| const opfsRoot = await navigator.storage.getDirectory(); | |
| const directoryHandle = await opfsRoot.getDirectoryHandle("my_pretty_stuff", { | |
| create: true, |
This file contains hidden or 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
| # Run 'nvm use' automatically every time there's | |
| # a .nvmrc file in the directory. Also, revert to default | |
| # version when entering a directory without .nvmrc | |
| # | |
| enter_directory() { | |
| if [[ $PWD == $PREV_PWD ]]; then | |
| return | |
| fi | |
| PREV_PWD=$PWD |
This file contains hidden or 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
| find . -name 'node_modules' -type d -prune |
This file contains hidden or 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
| function getBgColor(variant) { | |
| if (variant === "primary") { | |
| return "blue"; | |
| } | |
| if (variant === "danger") { | |
| return "red"; | |
| } | |
| if (variant === "warning") { |
This file contains hidden or 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
| interface User { | |
| name: string; | |
| age: number; | |
| } | |
| interface AuthorizedUser extends User { | |
| token: string; | |
| } | |
| type UserDisplayProps = { user: User }; |
This file contains hidden or 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 } from "react"; | |
| export default function App() { | |
| const [people, setPeople] = useState([]); | |
| const handleSubmit = (event) => { | |
| event.preventDefault(); | |
| setPeople([...people, event.target.person.value]); | |
| event.target.reset(); | |
| }; |
NewerOlder