Skip to content

Instantly share code, notes, and snippets.

View cododel's full-sized avatar
💻

@cododelia cododel

💻
View GitHub Profile
@cododel
cododel / 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;
@cododel
cododel / 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
@cododel
cododel / 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
@cododel
cododel / 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
@cododel
cododel / 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:
...
@cododel
cododel / 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;
};
@cododel
cododel / networkidle.js
Last active October 9, 2024 13:48
Network IDLE listener
function useNetworkidleEvents(){
let activeRequests = 0;
let idleTimeout = null;
// Функция для проверки состояния сети
function checkNetworkIdle() {
if (activeRequests === 0) {
idleTimeout = setTimeout(() => {
const event = new CustomEvent('network-idle');
window.dispatchEvent(event);
@cododel
cododel / toCallable.ts
Created October 14, 2024 20:45
Helper to make class instance callable
type hasCallMethod = { call: (...args: any[]) => any };
export default function toCallable<T extends hasCallMethod>(instance: T) {
type argsType = Parameters<T["call"]>
const fn = (...args: argsType) => {
return instance.call(...args);
};
return new Proxy(fn.bind(instance), {
apply: (target, _thisArg, argsList: argsType) => target(...argsList),
<?php
namespace App\Services\HTML\Modules\Tailwind;
trait InteractsWithTailwind
{
abstract public function class(string $class): static;
// Text utilities
@cododel
cododel / Cell.php
Created October 27, 2024 15:44
PHP HTML Dom Static Builder
<?php
namespace App\Services\Table;
use App\Services\HTML\HTMLElement;
class Cell extends HTMLElement
{
public static function getTagName(): string
{