Skip to content

Instantly share code, notes, and snippets.

View saeedvir's full-sized avatar
🎯
Focusing

saeed abdollahian saeedvir

🎯
Focusing
View GitHub Profile
@saeedvir
saeedvir / app.js
Created November 12, 2025 03:12
Shuffle and Reconstruct String (3 way)
// method 1
const mystring = "abcde";
// Split into 4 sections (since string length is 5, one section will be empty)
function splitIntoFour(str) {
const sectionSize = Math.ceil(str.length / 4);
const sections = [];
for (let i = 0; i < 4; i++) {
@saeedvir
saeedvir / BenfordAnalyzer.php
Created November 7, 2025 14:32
Benford's law in php
<?php
class BenfordAnalyzer
{
protected array $data;
public function __construct(array $data)
{
$this->data = array_filter($data, function ($value) {
return is_numeric($value) && $value != 0;
@saeedvir
saeedvir / LaravelBootTimeCheck.php
Created November 5, 2025 02:10
Laravel Boot Time Check
<?php
use Illuminate\Foundation\Application;
require __DIR__ . '/vendor/autoload.php';
echo "=== Testing Optimized Module System ===\n\n";
$startTime = microtime(true);
@saeedvir
saeedvir / GistClient.php
Last active October 29, 2025 14:26
Full-featured GitHub Gist API client (pure PHP, no dependencies) and Supports: create, update, upload, download, list, delete
<?php
use RuntimeException;
use InvalidArgumentException;
/**
* Full-featured GitHub Gist API client (pure PHP, no dependencies)
* Supports: create, update, upload, download, list, delete
*
* @version 2.0
* @author saeedvir <https://github.com/saeedvir>
@saeedvir
saeedvir / CuckooFilter.php
Last active October 22, 2025 07:31
php Cuckoo Filter
<?php
class CuckooFilter
{
protected int $bucketCount;
protected int $bucketSize;
protected array $buckets;
protected int $maxKick; // برای جلوگیری از حلقه بی‌پایان
public function __construct(int $bucketCount = 64, int $bucketSize = 4, int $maxKick = 500)
@saeedvir
saeedvir / BloomFilter.php
Created October 22, 2025 07:18
php Bloom Filter
<?php
class BloomFilter
{
protected int $size;
protected int $hashCount;
protected array $bitArray;
public function __construct(int $size = 1000, int $hashCount = 3)
{
@saeedvir
saeedvir / MessengerNotifier.php
Last active October 16, 2025 05:48
Laravel Send Notification to Telegram or Bale Messenger
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
/**
* By saeedvir: https://github.com/saeedvir
@saeedvir
saeedvir / strip_tags.js
Last active September 27, 2025 03:01
secured and improved version of strip_tags php function in javascript
/*
php version : https://gist.github.com/saeedvir/f00d76c33a95c1fbecb297df4a286ebc
*/
function strip_tags(input, allowed) {
if (input == null || input === '') return '';
// Convert to string and handle non-string inputs safely
const str = String(input);
// Parse allowed tags into a Set for faster lookup
@saeedvir
saeedvir / strip_tags_secure.php
Last active September 27, 2025 03:01
secure strip_tags function
<?php
/*
javascript version : https://gist.github.com/saeedvir/d9b80ff857481dcce26b7610442dfb3f
*/
function strip_tags_secure($input, $allowed = '', $options = []) {
if ($input === null || $input === '') {
return '';
}
/*
const scripts = [
'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js', // ✅ Valid
'https://example.com/nonexistent-script.js', // ❌ 404 — THIS WILL BREAK SEQUENCE
'https://cdn.jsdelivr.net/npm/moment@2.29.4/moment.min.js' // ⛔ Won't load due to previous error
];
try {
const loadedScripts = await loadScriptsSequentiallyEnhanced(scripts, { timeout: 5000 });