Skip to content

Instantly share code, notes, and snippets.

View erdum's full-sized avatar

Erdum erdum

View GitHub Profile
@erdum
erdum / HandleUploadSaveAsWebp.php
Created May 12, 2022 20:43
Handle image upload in laravel and convert them to webp for storage.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ImageUploadController
{
public function saveToWebp($src, $destination, $extension)
{
@erdum
erdum / countries.json
Created August 18, 2023 07:06
List of countries and their mobile code
[
{
"name": "Afghanistan",
"mobile_code": "+93",
"iso_code": "AF",
"flag_emoji": "🇦🇫"
},
{
"name": "Albania",
"mobile_code": "+355",
@erdum
erdum / yt-audio.py
Last active September 14, 2023 06:53
Download highest quality audio of YouTube video
from pytube import YouTube
yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
yt.streams.get_audio_only().download(filename="test.mp3")
@erdum
erdum / yt-audio-downloader.py
Last active September 16, 2023 12:59
Youtube Audio Downloader
import os
from pytube import YouTube
import time
from urllib.parse import urlparse, parse_qs
import gradio as gr
def download_audio_from_youtube_url(url: str) -> gr.outputs.File:
filename = 'yt-audio-{timestamp}.mp4'.format(timestamp=round(time.time()))
try:
@erdum
erdum / random-string.js
Last active November 29, 2023 11:23
Generates a random string of alphanumeric characters with the specified length
btoa(Math.random()).substr(0, 10);
@erdum
erdum / request-tester.php
Created October 3, 2023 08:00
Get insight of the incoming http requests
<?php
$request_payload = !empty($_POST) ? $_POST : array();
$request_payload = empty($_POST) && !empty($_GET) ? $_GET : $request_payload;
$request_payload = isset($_SERVER['CONTENT_TYPE'])
&& $_SERVER['CONTENT_TYPE'] == 'application/json'
? json_decode(file_get_contents('php://input'), true)
: $request_payload;
$request_details = array(
@erdum
erdum / working-days.php
Created November 16, 2023 13:08
Get working days in a month
<?php
function get_working_days($year, $month, $last_day = null) {
$total_month_days = date('t', strtotime("$year-$month-01"));
if ($last_day) {
$total_month_days = $last_day;
}
$working_days;
@erdum
erdum / send_json.php
Created December 2, 2023 07:36
Send JSON response in PHP
<?php
function send_json($payload, $status_code = 200)
{
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
is_callable('http_send_status') ? http_send_status($status_code)
: header("HTTP/1.1 $status_code");
return exit(json_encode((object) $payload));
}
@erdum
erdum / input-formatter.js
Last active December 19, 2023 06:05
Format input field dynamically to add hyphens after specific length of characters
const addHyphens = (inputField) => {
inputField.addEventListener('input', (event) => {
let value = event.target.value.replace(/-/g, '');
let formattedValue = '';
for (let i = 0; i < value.length; i++) {
if (i === 5 || i === 12) {
formattedValue += '-';
}
formattedValue += value[i];
@erdum
erdum / UsaStatesList.js
Created December 30, 2023 20:41
USA States names list in javascript array
const UsaStates = [
'Alabama',
'Alaska',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
'Delaware',
'Florida',