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
<div class="animate-fade-in"> | |
Fadein! | |
</div> |
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 fs from 'fs'; | |
export async function download(url: string, file: string): Promise<void> { | |
const response = await fetch(url); | |
if (!response.ok) { | |
return; | |
} | |
const data = Buffer.from(await response.arrayBuffer()); | |
fs.writeFileSync(file, data); | |
} |
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
def hiragana_to_katakana(src: str) -> str: | |
result = '' | |
for char in src: | |
code = ord(char) | |
result += chr(code + 96) if 12352 < code < 12439 else char | |
return result | |
print(hiragana_to_katakana('てすと')) | |
# It outputs 'テスト'. |
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
from datetime import datetime | |
from pytest_mock import MockerFixture | |
def test_your_function(mocker: MockerFixture): | |
now = datetime.strptime('2024-01-02 12:34:56', '%Y-%m-%d %H:%M:%S') | |
mock = mocker.MagicMock(wraps=datetime) | |
mock.now.return_value = now | |
mocker.patch('src.your_module.datetime', new=mock) |
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
export async function getHashByUrl(url: string): Promise<string> { | |
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest | |
const uint8 = new TextEncoder().encode(url); | |
const digest = await crypto.subtle.digest('SHA-256', uint8); | |
return Array.from(new Uint8Array(digest)).map(b => b.toString(16).padStart(2,'0')).join(''); | |
} |
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
<input type="checkbox" style="pointer-events: none" checked/>Click me! | |
<input type="checkbox" checked/>Toggle me! |