Skip to content

Instantly share code, notes, and snippets.

View websmithcode's full-sized avatar
💻

@WSCode websmithcode

💻
View GitHub Profile
@websmithcode
websmithcode / PWCache.ts
Created August 11, 2024 00:53
managed request caching system for playwright with typescript
import type { Page, Response } from "playwright";
import fs from 'fs';
export class PWCache {
private readonly cacheDir = './.cache';
statistics: {
totalRequests: number;
totalCached: number;
totalNotCached: number;
};
@websmithcode
websmithcode / example.py
Created August 8, 2024 23:40
Async to Sync python with correct type definition
from sync_await import sync_await
class BookModel(BaseModel):
id: int
title: str
content: str
async def fetch_book(id: int) -> BookModel:
...
@websmithcode
websmithcode / URLPatternMatcher.py
Last active August 8, 2024 20:33
URL Pattern Matcher on python - no dependencies
import json
import re
class URLPatternMatcher:
def __init__(self, pattern: str):
self.pattern = pattern.rstrip('/')
def match(self, path: str) -> dict | bool:
"""Match URL pattern
@websmithcode
websmithcode / AsyncQueueRunner.py
Last active August 8, 2024 20:35
Make queue with chainable interface from async tasks, then run sequence of tasks
from typing import List, Callable
class QueueTask:
task: Callable
_args: tuple = tuple()
_kwargs: dict = dict()
def __init__(self, task: Callable):
self.task = task
@websmithcode
websmithcode / deploy-to-gh-pages.sh
Last active August 8, 2024 20:34
NuxtJs static deployment script for GithubPages to gh-pages branch
# If has not commited changes - stopr script
if [ -n "$(git status --porcelain)" ]; then
echo "Please commit your changes before deploying"
exit 1
fi
# If has no node_modules - install it
if [ ! -d "node_modules" ]; then
bun install
fi
@websmithcode
websmithcode / AddressComponent.php
Last active August 8, 2024 20:35
FilamentPHP Composite address field
<?php
namespace App\Filament\Resources\Components;
use Filament\Forms\Components;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Set;
use Illuminate\Support\Str;
use LiveWire\Component as Livewire;