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 fs from "node:fs"; | |
| import https from "node:https"; | |
| import http from "node:http"; | |
| function getFileName(url: string) { | |
| return new URL(url).pathname.split("/").pop(); | |
| } | |
| async function downloadFile(url: string): Promise<string> { | |
| const urlProtocol = new URL(url).protocol; | |
| const request = urlProtocol === "https:" ? https : http; |
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
| from pyrogram import Client, filters | |
| app = Client('CONVERSATION_EXAMPLE') | |
| conversations = {} | |
| infos = {} | |
| def conv_filter(conversation_level): | |
| def func(_, __, message): | |
| return conversations.get(message.from_user.id) == conversation_level |
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 fs from "node:fs"; | |
| import axios from "axios"; | |
| const baseUrl = "https://jlptstudy.net"; | |
| const pattern = /<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1/g; | |
| (async () => { | |
| // stop at 1 cause jlptstudy.net doesn't have the kanji n1 | |
| for (let nNumber = 5; nNumber > 1; nNumber--) { | |
| const dirname = "n" + nNumber; |
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
| var __createElement__ = document.createElement; | |
| document.createElement = function(tagName, options){ | |
| console.log(`Element <${tagName}> created.`); | |
| return __createElement__.call(this, tagName, options); | |
| }; |
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 ISchedule { | |
| homeTeam: ITeam; | |
| awayTeam: ITeam; | |
| } | |
| interface ITeam { | |
| name: string; | |
| strength: number; | |
| points: number[]; | |
| numericId: number; |
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
| yourForm.onsubmit = (event) => { | |
| event.preventDefault(); | |
| const formData = new FormData(yourForm); | |
| for (const [key, value] of formData) { | |
| console.log({ key, value }); | |
| } | |
| }; |
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 validObjectId(text: string) { | |
| const pattern = /[0-9a-fA-F]{24}/; | |
| const match = text.match(pattern); | |
| if (!match) return false; | |
| return match[0] === text; | |
| } |
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
| let teams = [ | |
| 'Tigers', | |
| 'Foofels', | |
| 'Drampamdom', | |
| 'Lakebaka' | |
| ] | |
| const roundRobin = (teams) => { | |
| let schedule = [] | |
| let league = teams.slice() |
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 useFetch = (url: string, options: any) => { | |
| const [response, setResponse] = useState<string | undefined>(undefined); | |
| const [error, setError] = useState<unknown>(undefined); | |
| const [abort, setAbort] = useState<() => void>(() => {}); | |
| useEffect(() => { | |
| const fetchData = async () => { | |
| try { | |
| const abortController = new AbortController(); | |
| const signal = abortController.signal; |