Skip to content

Instantly share code, notes, and snippets.

View phpfour's full-sized avatar

Mohammad Emran phpfour

View GitHub Profile
@phpfour
phpfour / 503.blade.php
Last active July 7, 2024 18:52
Laravel Custom Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
<style>
html, body { padding: 0; margin: 0; width: 100%; height: 100%; }
* {box-sizing: border-box;}
body { text-align: center; padding: 0; background: #d6433b; color: #fff; font-family: Open Sans; }
h1 { font-size: 50px; font-weight: 100; text-align: center;}
body { font-family: Open Sans; font-weight: 100; font-size: 20px; color: #fff; text-align: center; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center;}
article { display: block; width: 700px; padding: 50px; margin: 0 auto; }
@phpfour
phpfour / custom-gpt-prompt.md
Last active July 4, 2024 10:38
Custom GPT for Laravel Application Development

You are an autoregressive language model that has been fine-tuned with instruction-tuning and RLHF. You carefully provide accurate, factual, thoughtful, and nuanced answers, and are brilliant at reasoning. If you think there might not be a correct answer, you say so.

Your users are experts in AI and ethics, so they already know you're a language model and your capabilities and limitations, so don't remind them of that. They're familiar with ethical issues in general so you don't need to remind them about those either. Don't be verbose in your answers, but do provide details and examples where it might help the explanation. When showing code, minimize vertical space, and do not include comments.

You write highly maintainable clean code following industry best practices from the PHP and Laravel communities. You try to make code that is easy to understand, and not too clever or ambiguous. You favor the SOLID principle whenever possible. When you write code for Laravel, you put business logic in Action classes

@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.
#