π΅βπ«
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 flask import g | |
import sqlite3 | |
from typing import Dict, List | |
class Database: | |
def __init__(self, db_path: str): | |
self.db_path = db_path | |
def get_connection(self): | |
if "conn" not in g: |
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
/** | |
* Debounces a function by delaying its execution until a certain amount of time has passed | |
* since the last time it was invoked. Only the last invocation within the delay period will be executed. | |
*/ | |
export function debounce(fn: Function, time: number = 300): Function { | |
let timeoutId: ReturnType<typeof setTimeout>; | |
return function (this: any, ...args: any[]) { | |
clearTimeout(timeoutId); | |
timeoutId = setTimeout(() => { | |
fn.apply(this, args); |
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 Node: # Creating a node | |
def __init__(self, item): | |
self.item = item | |
self.next = None | |
class LinkedList: # Creating a linked list | |
def __init__(self): | |
self.head = None | |
def print_list(self): | |
cur_node = self.head |
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 MySQLDatabase: | |
def __init__(self, database, user, password, host, port): | |
self.database = database | |
self.user = user | |
self.password = password | |
self.host = host | |
self.port = port | |
def connect(self): | |
return MySQLDatabase(self.database, self.user, self.password, self.host, self.port) |
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 { z } from "zod"; | |
import { PostSchema } from "@/schema/posts"; | |
import { CommentsSchema } from "@/schema/comments"; | |
export function createAPIClient() { | |
async function _fetch<T extends z.ZodTypeAny>( | |
input: RequestInfo, | |
init: RequestInit, | |
type: T | |
): Promise<z.infer<T>> { |
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
type DeepReadonly<T extends Record<string, unknown>> = { | |
readonly [K in keyof T]: T[K] extends Record<string, any> | |
? T[K] extends (...args: Array<unknown>) => unknown | |
? T[K] | |
: DeepReadonly<T[K]> | |
: T[K]; | |
}; | |
type ReadonlyArray<T> = DeepReadonly<Array<T>>; |
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 Memoize: | |
def __init__(self, func: Callable) -> None: | |
self.func = func | |
self.cache = {} | |
def __call__(self, *args, **kwargs) -> Any: | |
if args not in self.cache: | |
self.cache[args] = self.func(*args, **kwargs) | |
return self.cache[args] |
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 puppeteer from "puppeteer"; | |
import axios from "axios"; | |
export const scraper = async (url: Readonly<string>): Promise<string[]> => { | |
const browser = await puppeteer.launch({ headless: true }); | |
const page = await browser.newPage(); | |
await page.goto(url, { | |
timeout: 0, | |
waitUntil: "domcontentloaded" |
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 binarySearch = (source_text: string, target: string): [number, string] | null => { | |
const source_text_segments: string[] = (source_text.match(/[^.!?]+[.!?]+/g) || [source_text]).map(s => s.trim()); | |
const target_segment = target.trim(); | |
let result: [number, string] | null = null; | |
let left: number = 0; | |
let right: number = source_text_segments.length - 1; | |
while (left <= right) { | |
const mid = left + Math.floor((right - left) / 2); | |
const segment = source_text_segments[mid]; |
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 puppeteer from 'puppeteer-extra'; | |
import { LaunchOptions } from 'puppeteer'; | |
import fs from 'fs/promises'; | |
import path from 'path'; | |
import { fileURLToPath } from 'url'; | |
import StealthPlugin from 'puppeteer-extra-plugin-stealth'; | |
import AdblockerPlugin from 'puppeteer-extra-plugin-adblocker'; | |
interface Row { | |
text: string; |
OlderNewer