Skip to content

Instantly share code, notes, and snippets.

View erdum's full-sized avatar

Erdum erdum

View GitHub Profile
@erdum
erdum / US_States_and_Cities.json
Created December 30, 2023 20:45 — forked from ahmu83/US_States_and_Cities.json
List of US States and Cities in JSON format.
{
"New York": [
"New York",
"Buffalo",
"Rochester",
"Yonkers",
"Syracuse",
"Albany",
"New Rochelle",
"Mount Vernon",
@erdum
erdum / image-preview-uploader.html
Created January 9, 2024 12:59
Image Preview Uploader
<div class="col-span-6">
<!-- <label class="block ml-2 text-sm font-medium text-gray-700"> Photo </label> -->
<div class="mt-1 flex items-center">
<span class="inline-block h-36 w-36 rounded-full overflow-hidden bg-gray-100">
<svg class="h-full w-full text-gray-300" fill="currentColor" viewBox="0 0 24 24">
<path d="M24 20.993V24H0v-2.996A14.977 14.977 0 0112.004 15c4.904 0 9.26 2.354 11.996 5.993zM16.002 8.999a4 4 0 11-8 0 4 4 0 018 0z" />
</svg>
</span>
<img src="" class="hidden h-36 w-36 rounded-full overflow-hidden object-fit">
<button onclick="handleImage(this)" type="button" class="ml-5 bg-white py-2 px-3 border border-gray-300 rounded-md shadow-sm text-sm leading-4 font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Change</button>
@erdum
erdum / extract-zip.php
Created January 13, 2024 09:18
Extract zip file with PHP
<?php
$zipFile = __DIR__ . '/web.zip';
$extractTo = __DIR__ . '/';
$zip = new ZipArchive;
if ($zip->open($zipFile) === TRUE) {
$zip->extractTo($extractTo);
$zip->close();
@erdum
erdum / extract-tar.php
Created January 13, 2024 09:27
Extract tar file with PHP
<?php
$tarFile = __DIR__ . '/file.tar';
$extractTo = __DIR__ . '/';
exec("tar -xf $tarFile -C $extractTo", $output, $returnCode);
if ($returnCode === 0) {
echo 'Extraction successful!';
} else {
@erdum
erdum / check-in-range.php
Created January 23, 2024 14:00
Check two geo-coordinate points are within a specified range
<?php
check_in_distance($lat_a, $long_a, $lat_b, $long_b, $range)
{
$dlat = ($lat_a / (180 / pi())) - ($lat_b / (180 / pi()));
$dlong = ($long_a / (180 / pi())) - ($long_b / (180 / pi()));
$c = pow(sin($dlat / 2), 2) + cos($lat_a);
$c = $c * cos($lat_b) * pow(sin($dlong / 2), 2);
$c = 2 * asin(sqrt($c));
$c = 6371 * $c;
@erdum
erdum / ip-scanner.py
Created January 29, 2024 07:41
Python IP scanner
import socket
def check_port(ip, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((ip, port))
sock.close()
return result == 0
def scan_ports(start_ip, end_ip, port):
@erdum
erdum / base64-to-webp.php
Created January 31, 2024 18:46
Convert and save image in webp from raw base64 string in Laravel
<?php
use Illuminate\Support\Str;
function save_base64_to_webp(
$string,
$file_directory,
$file_name = null,
$disk_driver = 'local'
)
@erdum
erdum / check-focus.js
Created February 5, 2024 20:12
Check if a element or its child has current focus
function hasFocus(element) {
return element.contains(document.activeElement);
}
@erdum
erdum / stripe_add_card.html
Created March 8, 2024 07:30
Stripe Add Card Form (for testing)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment Form</title>
<!-- Include Stripe.js -->
<script src="https://js.stripe.com/v3/"></script>
</head>
@erdum
erdum / FirebaseAuthService.php
Created March 12, 2024 04:45
Authentication Service Class for Laravel REST API
<?php
namespace App\Services;
use Kreait\Firebase\Factory;
use App\Jobs\ProcessEmail;
use App\Exceptions\InvalidIdTokenException;
use App\Exceptions\UserAlreadyRegisteredException;
use App\Exceptions\UserBlockedException;
use App\Exceptions\AccessForbiddenException;