Skip to content

Instantly share code, notes, and snippets.

View samilkorkmaz's full-sized avatar

Şamil Korkmaz samilkorkmaz

  • Ankara / Turkey
View GitHub Profile
@samilkorkmaz
samilkorkmaz / checkMX.php
Last active April 25, 2024 14:05
Display MX (Mail Exhange) records of a domain
<?php
// Online tool: https://mxtoolbox.com/
function getMXRecords($domain) {
$mxhosts = [];
$weights = [];
// Get MX records associated with the domain
if (getmxrr($domain, $mxhosts, $weights)) {
@samilkorkmaz
samilkorkmaz / dropifyPreviewFix.js
Created March 3, 2024 19:44
dropify.js does not support preview of WebP images, this JS fixes it
function displayPreviewsOfExistingWebPImages () { // Call this function when page is ready, i.e. $(document).ready(displayPreviewsOfExistingWebPImages);
// Initialize Dropify on all elements with the class .dropify
var dropifyInstances = $('.dropify').dropify();
// Iterate over each Dropify instance
dropifyInstances.each(function() {
// Get the current instance's element and defaultFile data attribute
var element = $(this);
var defaultFile = element.data('default-file');
@samilkorkmaz
samilkorkmaz / deleteUnusedImages.php
Created March 2, 2024 14:22
Delete files that are not referenced from database
<?php
// Delete image files in image/product/ folder that do not exist in database table products_photos, column photo
$directoryPath = 'c:/xampp_8_2_12/htdocs/image/product/';
$removePath = 'c:/xampp_8_2_12/htdocs';
$filesAndFolders = glob($directoryPath . '*'); // Note that some files don't have a file extension
$filesNotExistingInDatabase = array();
$counter = 0;
// Part of the path to remove
foreach ($filesAndFolders as $i => $absolutePath) {
if (is_file($absolutePath)) { // exclude directories
@samilkorkmaz
samilkorkmaz / convertToWebP.php
Last active March 2, 2024 14:22
Convert images to webp files under 250kB
<?php
//Convert PNG and JPEG images to WebP
function convertToWebp($source, $destination, $quality = 80) {
$startTime = microtime(true);
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg' || $info['mime'] == 'image/jpg' || $info['mime'] == 'image/jfif') {
echo "Original image is jpeg<br>";
// Load the JPEG file
$image = imagecreatefromjpeg($source);
@samilkorkmaz
samilkorkmaz / inflation.py
Last active February 6, 2024 13:28
Calculate inflation adjusted value
# Calculate inflation adjusted value. Generated with chatGPT4
from datetime import datetime
start_amount = 140000
start_year = 2019
end_year = 2024
# Inflation rates by year, from 2019 to the current year
# Note: These are fictional rates for demonstration purposes.
# In a real-world scenario, you would use actual inflation rates obtained from a reliable financial source.
@samilkorkmaz
samilkorkmaz / runAndCheck.bat
Last active December 29, 2023 13:29
Windows batch file to start an exe and check its result
::Test pass criteria: Exe has to finish within maxExeRunTime_s and exe output's last line must be equal to expectedLastLine
@echo off
set currentDir=%CD%
:: Set variables
set secondWindowTitle=My second window
set exeName=MyExe.exe
set exeFolder=x64/Release
set maxExeRunTime_s=5
set tempOutFile=temp_output.txt
@samilkorkmaz
samilkorkmaz / measurePageLoadTime.php
Created December 23, 2023 12:32
Measure page load time with PHP using Google PageSpeed Insights API
private static function getPageSpeedInsights($url) {
$apiUrl = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed";
/*$queryParams = http_build_query([
'url' => $url,
'key' => 'YOUR_API_KEY' // If you plan on using the API in an automated way and making multiple queries per second, you'll need an API key
]);*/
$queryParams = http_build_query([
'url' => $url
]);
@samilkorkmaz
samilkorkmaz / plot_world_map_with_raster.py
Last active December 9, 2023 19:12
plot_world_map_with_raster
#Download raster (*.tif) files from https://www.naturalearthdata.com/downloads/50m-raster-data/
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import rasterio
from rasterio.plot import show
class InteractiveMap:
def __init__(self, raster_path):
self.raster_path = raster_path
@samilkorkmaz
samilkorkmaz / plot_shapefile_with_zoom.py
Last active December 9, 2023 19:48
Pan/zoom shape file with Python
#You can download shape files (.sh and .shx) from https://www.naturalearthdata.com/downloads/
#Put .shx files into the same folder as .sh file
#Şamil Korkmaz, December 9th 2023
import geopandas as gpd
import matplotlib.pyplot as plt
def plot_shapefile(shapefile_path1, shapefile_path2, shapefile_path3):
# Load shape files
gdf1 = gpd.read_file(shapefile_path1)
@samilkorkmaz
samilkorkmaz / download.sh
Last active December 7, 2023 08:16
Download build_essential package (gcc, g++, make etc.) and all its dependencies for offline installation on Ubuntu 22.04
#!/bin/bash
#1.On online Ubuntu 22.04, create a folder, save this script as download_build_essential.sh
#2.Make script executable with chmod +x download_build_essential.sh
#3.Run script with ./download_build_essential.sh
#4.Copy downladed .deb files (~76MB) to the offline Ubuntu 22.04
#5.On offline Ubuntu, run sudo dpkg -i *.deb
#6.Verify installation with make --version
# Function to download a package and its dependencies