Skip to content

Instantly share code, notes, and snippets.

@chaungoclong
chaungoclong / .php-cs-fixer.php
Created October 19, 2025 03:29 — forked from laravel-shift/.php-cs-fixer.php
PHP CS Fixer - Laravel Coding Style Ruleset
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
@chaungoclong
chaungoclong / vardumper.php
Created April 7, 2025 06:09
simple-vardumper
<?php
require_once __DIR__ . '/vendor/autoload.php';
function dd(...$variables)
{
// Kiểm tra nếu đang chạy trong CLI
if (PHP_SAPI === 'cli') {
foreach ($variables as $variable) {
echo formatVariableCLI($variable, 0) . "\n\n";
@chaungoclong
chaungoclong / simple-dd.php
Created April 1, 2025 22:48
simple dd method
<?php
function buildTree($data, $level = 0)
{
$html = '<ul class="tree">';
foreach ($data as $key => $value) {
$html .= '<li style="padding-left: ' . ($level * 20) . 'px;">';
if (is_array($value) || is_object($value)) {
@chaungoclong
chaungoclong / admin-layout.html
Created March 19, 2025 18:37
fuelphp admin layout
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>macOS Admin Panel</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/@phosphor-icons/web"></script>
<style>
/* Font chữ macOS */
@chaungoclong
chaungoclong / init.sh
Created March 19, 2025 00:12
FuelPHP MySQL init
#!/usr/bin/env bash
mysql --user=root --password="$MYSQL_ROOT_PASSWORD" <<-EOSQL
CREATE DATABASE IF NOT EXISTS testing;
GRANT ALL PRIVILEGES ON \`testing%\`.* TO '$MYSQL_USER'@'%';
EOSQL
@chaungoclong
chaungoclong / Dockerfile
Created March 19, 2025 00:11
FuelPHP Dockerfile
FROM php:7.4-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libpq-dev \
g++ \
@chaungoclong
chaungoclong / docker-compose.yml
Created March 19, 2025 00:10
FuelPHP Docker Compose
version: '3.8'
services:
nginx:
image: nginx:latest
container_name: nginx
restart: unless-stopped
ports:
- "8080:80"
volumes:
@chaungoclong
chaungoclong / objects_arrays.md
Last active January 31, 2025 21:17 — forked from nikic/objects_arrays.md
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@chaungoclong
chaungoclong / defer-like-go.php
Last active December 26, 2024 09:29
defer-like-go.php
<?php
class Func
{
private Closure $function;
private array $deferStack = [];
/**
* Constructor to store the main function to be executed
*
@chaungoclong
chaungoclong / auto-translate-using-free-google-translate-api.html
Created December 9, 2024 09:17
auto-translate-using-free-google-translate-api.html
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Form with Tabs</title>
<!-- Kết nối với Alpine.js 3 -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.7/dist/cdn.min.js"></script>
<!-- Kết nối với Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>