Skip to content

Instantly share code, notes, and snippets.

View usmanx03's full-sized avatar
🎯
Focusing

Usman Zahid usmanx03

🎯
Focusing
View GitHub Profile
@usmanx03
usmanx03 / nginx_config.conf
Created May 27, 2026 03:45
Nginx configuration for Laravel applications
server {
listen 80;
listen [::]:80;
server_name your-domain.com;
# Point directly to the /public subfolder
root /var/www/your-project-folder/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
@usmanx03
usmanx03 / server-check.php
Created November 5, 2025 11:10
Simple PHP script to verify your new server is up and PHP is running fine.
<?php
header('Content-Type: text/plain');
echo "All systems operational.\n\n";
$serverIP = $_SERVER['SERVER_ADDR'] ?? gethostbyname(gethostname());
$clientIP = $_SERVER['REMOTE_ADDR'] ?? 'n/a';
$diskFree = round(@disk_free_space('/') / 1024 / 1024 / 1024, 2);
$diskTotal = round(@disk_total_space('/') / 1024 / 1024 / 1024, 2);
@usmanx03
usmanx03 / setup_laravel_app.sh
Created March 19, 2025 15:22
A shell script to setup the Laravel application for non technicals.
#!/bin/bash
echo "Installing dependencies..."
composer install --no-dev --optimize-autoloader
echo "Setting up .env..."
cp .env.example .env
echo "Generating application key..."
php artisan key:generate
@usmanx03
usmanx03 / FakeLogMaker.php
Created February 24, 2025 17:48
A PHPprogram to output fake log messages with fake information such as PIDs, timestamps and data.
<?php
function randomHex(): string {
return bin2hex(random_bytes(random_int(10, 20)));
}
$logTypes = ["INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"];
$processes = ["sshd", "cron", "init", "systemd", "bash", "php", "nginx", "mysql", "firewalld", "python3", "node"];
while (true) {
$timestamp = date("Y-m-d H:i:s");
<?php
class Node {
public string $tag;
public array $children = [];
public function __construct(string $tag) {
$this->tag = $tag;
}
public function addChild(Node $child): void {
<?php
class PricingOptionTaxHelper {
/**
* Resolve the total amount for a pricing option.
*/
public static function resolveTotal(PricingOption $pricingOption, bool $format = true): float {
$taxPlan = $pricingOption->taxPlan;
if ($taxPlan && $taxPlan->type===TaxPlanType::INCLUSIVE) {
$total = $pricingOption->price;
@usmanx03
usmanx03 / ServiceResponse.php
Last active February 22, 2025 10:31
A response object I use for communication between the services.
<?php
class ServiceResponse {
private ?string $message = null;
private ?bool $success = true;
private array $errors = [];
private ?ServiceResponse $previous = null;
private mixed $data = null;
// Getters
@usmanx03
usmanx03 / HasRoles.php
Last active February 22, 2025 10:31
This HasRoles trait provides role-based access control (RBAC) functionality for a user model in Laravel. It allows assigning and removing roles, checking role ownership, and retrieving the highest assigned role. The implementation assumes a many-to-many relationship between users and roles, requiring a roles table and a pivot table for associati…
<?php
trait HasRoles {
// Assign a role to the user
public function assignRole(string $roleName): void {
$role = Role::where('name', $roleName)->first();
if ($role && !$this->hasRole($roleName)) {
$this->roles()->attach($role->id);
}
}