Skip to content

Instantly share code, notes, and snippets.

View trgino's full-sized avatar
eni vici vokke

Cüneyt ÇiL trgino

eni vici vokke
View GitHub Profile
@trgino
trgino / gist:b33d95908188f6c2b20f76d17db30a8f
Last active September 10, 2023 16:07
number format without round up
<?php
function fix_number_format($num, $decimals = 2, $decimals_seperator = '.', $thousands_separator = ','){
$num = floatval($num);
$num = number_format( $num, ($decimals + 1), $decimals_seperator, $thousands_separator);
$num = substr($num, 0, -1);
return $num;
}
@trgino
trgino / gist:3a97b7223b206b2c38fdd9cf013968df
Created November 15, 2022 19:30
php rand vs mt_rand vs random_int fastest benchmark
<?php
$a1=microtime(true);
foreach(range(1,10) as $a){
echo mt_rand(0,100).PHP_EOL;
}
echo ':'.microtime(true)-$a1.PHP_EOL;
$a1=microtime(true);
foreach(range(1,10) as $a){
echo random_int(0,100).PHP_EOL;
@trgino
trgino / eczaneler.php
Created November 14, 2022 18:47
eczaneler json ornek
<?php
$file = file_get_contents('url');
$json = json_decode($file,true);
if($json && isset($json['data']) && !empty($json['data'])){
foreach($json['data'] as $data){
//sehirler tablosuna sutunlar id, CityID, CityName -> id auto increment
curl 'https://www.amazon.com/gp/delivery/ajax/address-change.html' \
-H 'authority: www.amazon.com' \
-H 'accept: text/html,*/*' \
-H 'accept-language: tr,en;q=0.9,tr-TR;q=0.8,en-US;q=0.7' \
-H 'anti-csrftoken-a2z: gM1HMlgAGTf2m5qaJpiznpPie+g9nKHA4bkQpmQAAAAMAAAAAGJU0hNyYXcAAAAA' \
-H 'content-type: application/x-www-form-urlencoded' \
-H 'contenttype: application/x-www-form-urlencoded;charset=utf-8' \
-H 'cookie: s_fid=67638D15CCE73FA7-1638BD8ECE48C82E; ubid-main=132-1108789-2932117; x-main="9wElS075UGrWc@32VaB679JQvkDfyW@Z"; at-main=Atza|IwEBIDw6odaYGY1KU25VukCGgNXLBX2o4iKaQttCRy9P1Mn5573VgzuSC6XlLN3VpIQRV5kYEG7NO_IaKiJvaGdTCtpx13_z5FebV5tqOUWNNsI7LVfLvXGPbxbK9x-DqpTBn5FUxjnzyjIQ3aOTNk_miZVPCmQTPe0Zpxk1K2hCQYBVYhNQkJ95k1OCENME1MwHivvPwWIadlI2OdOdBmqknUXuLxmo0RQ3nO5SpBBHc44u2Q; sess-at-main="SQGddGeeRfTXuIwpYqle3+3SlWAIuuVk2TzCIMKcDL0="; sst-main=Sst1|PQF0Y0K5tNpw6DbGs6USdzabCQEdXQbPYWLpEisPrP3Qy9DR1mELwQ8eAYdE_vVEtvFZaYfBXx8PsS2M07VWKvQr5nJp3cLJcZuAxem077JjZ8koa3xpC32UahloTVzNr-W5CuNxj6VzFbLEa
@trgino
trgino / nppexec php check
Created March 30, 2022 08:04
nppexec php check
set php_dir = "php.exe"
npp_console disable
NPE_CONSOLE v+
npp_console enable
cmd.exe /c "$(PHP_DIR) -l "$(FULL_CURRENT_PATH)""
npp_console disable
set linepos ~ strrfind "$(OUTPUT1)" "on line "
if $(linepos) == -1 goto Done
set linepos ~ $(linepos) + 8
set s ~ substr $(linepos) - $(OUTPUT1)
@trgino
trgino / s3_mysql_backupper.sh
Created August 1, 2021 07:25
Amazon S3 MYSQL Backupper
#! /bin/bash
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M")
BACKUP_DIR="/home/mysql_backups"
#local mysql backup folder
MYSQL_USER="root"
#mysql root user for all databases backup
MYSQL=/usr/bin/mysql
#mysql full path
MYSQL_PASSWORD="passwd"
@trgino
trgino / install.md
Created April 1, 2021 13:08 — forked from AndersonIncorp/install.md
Install any linux distro on VPS with low RAM, locked ISO boot

Overview

Scenario

  • Your VPS provider doesn't support ISO mount
  • Your VPS has low RAM and cannot load whole ISO image
  • Your current /boot is to small to contain ISO file

Workaround

  • Boot low memory ISO (CorePure64.iso ~ 14MB)
  • Create new partition ~1GB / size of your ISO
  • dd your ISO into that partition
function svg_base64($w,$h){
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="'.$w.'" height="'.$h.'" viewBox="0 0 '.$w.' '.$h.'"><rect fill="#fff" width="'.$w.'" height="'.$h.'"/></svg>';
$svg = 'data:image/svg+xml;base64,'.base64_encode($svg);
return $svg;
}
<?php
function ohub_cf7_handle_success_submission( $contact_form ) {
global $wpdb;
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
$table_name = $wpdb->prefix.'log_mail';
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$wpdb->insert(
$table_name,
@trgino
trgino / lswp_nonce.php
Created January 23, 2020 19:57
wordpress nonce lswp
<?php
if ( method_exists( 'LiteSpeed_Cache_API', 'nonce_action' ) ) {
LiteSpeed_Cache_API::nonce_action( 'nonce_name' );
}