Skip to content

Instantly share code, notes, and snippets.

View ralphschindler's full-sized avatar

Ralph Schindler ralphschindler

View GitHub Profile
@ralphschindler
ralphschindler / push-to-master-deploy.yml
Created May 1, 2025 13:54
Push To Deploy Github Action
name: Push To Master Deploy
on:
push:
branches:
- master
jobs:
deploy-to-server:
name: Deploy To Server
@ralphschindler
ralphschindler / use-ffi-to-write-to-file-via-low-level-standard-c-library-functions.php
Last active February 1, 2025 12:00
PHP Write to stdout via /proc/1/fd/1 using FFI (useful for logging inside a container)
<?php
// php can't write directly to a non-regular-file due to the php filesystem
// abstraction in place. But, we can use direct calls to the low level standard
// library to achieve this.
// normally, you should use the dio extension:
// - https://pecl.php.net/package/dio
// - https://github.com/php/pecl-system-dio/tree/master
@ralphschindler
ralphschindler / xdebug.sh
Created February 9, 2024 16:20
Enable/Disable Xdebug Via CLI Script
#!/bin/bash
QUIET=0
restart_php_fpm () {
if [ $QUIET -eq 1 ]; then
sv restart php-fpm > /dev/null
else
sv restart php-fpm
fi
@ralphschindler
ralphschindler / Dockerfile
Created September 8, 2021 13:39
Build php xdebug from scratch in a Docker container, with laravel app
FROM ubuntu:20.10
RUN mkdir /app
WORKDIR /app
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install -qqy --no-install-recommends \
ca-certificates \
valgrind \
@ralphschindler
ralphschindler / .php_cs.dist
Created April 20, 2021 14:24
Generic PHP-CS-Fixer Rules
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->notName('.php_cs.dist');
return (new PhpCsFixer\Config)
->setFinder($finder)
->setRules([
@ralphschindler
ralphschindler / Dockerfile
Last active December 15, 2020 01:39
Dockerfile for setting up PHP 8 and xdebug to demonstrate an issue
FROM ubuntu:20.10
RUN mkdir /app
WORKDIR /app
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install -qqy --no-install-recommends \
ca-certificates \
valgrind \
@ralphschindler
ralphschindler / SnapshotCommand.php
Created July 11, 2019 20:26
An example Laravel app command to create and load database snapshots using S3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class SnapshotCommand extends Command
{
@ralphschindler
ralphschindler / AuthServiceProvider.php
Last active April 5, 2019 09:04
Laravel 5.8 Policy Guesser For Using "Models" Directory
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
@ralphschindler
ralphschindler / StringIsLengthRule.php
Last active April 19, 2021 19:21
Custom Dynamic Validation Rules for Laravel 5.5+
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class StringIsLengthRule implements Rule
{
protected $length;
protected $message = 'The string must be greater than the length';
@ralphschindler
ralphschindler / database-column-ordering.md
Last active November 2, 2017 15:02
Ralph's Database Column Organization

Ralph's Database Column Organization

TLDR:

  1. primary key columns (e.g. id)
  2. foreign key columns (e.g. other_id)
  3. row qualifying columns (e.g. status)
  4. entity identification columns (e.g. name, title, slug, base_url)
  5. non-string-based entity attribute columns (e.g. rating, is_admin)
  6. string-based entity attribute columns (e.g. short_description, description, notes)