Skip to content

Instantly share code, notes, and snippets.

View osbre's full-sized avatar
🇺🇦
#StandWithUkraine

Ostap Brehin osbre

🇺🇦
#StandWithUkraine
View GitHub Profile
<?php
declare(strict_types=1);
// composer require openswoole/core:22.1.5
require_once "vendor/autoload.php";
use OpenSwoole\Core\Coroutine\Pool\ClientPool;
use OpenSwoole\Core\Coroutine\Client\PDOClientFactory;
use OpenSwoole\Core\Coroutine\Client\PDOConfig;
use OpenSwoole\Runtime;
<?php
namespace MyPlugin\Foundation;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Grammars\MySqlGrammar as QueryGrammar;
use Illuminate\Database\Query\Processors\MySqlProcessor;
use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar;
use Illuminate\Database\Schema\MySqlBuilder;
use Exception;
@osbre
osbre / Dockerfile
Created September 2, 2024 15:12
Dockerfile to run Laravel Octane with OpenSwoole
FROM php:8.3-cli-alpine
ENV SWOOLE_VERSION=5.1.1
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_HOME=/composer
RUN apk add --no-cache \
postgresql-dev \
libzip-dev \
libpng-dev \
@osbre
osbre / MySqliConnection.php
Last active August 19, 2024 10:14
Eloquent in WordPress plugin. illuminate/database with MySQLi connector.
<?php
namespace MyPlugin\Foundation;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Grammars\MySqlGrammar as QueryGrammar;
use Illuminate\Database\Query\Processors\MySqlProcessor;
use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar;
use Illuminate\Database\Schema\MySqlBuilder;
use Exception;
# Install duti
echo "Installing duti..."
brew install duti
# Set Sublime Text 4 as default for various code and config formats
echo "Setting Sublime Text 4 as default for code and config formats..."
# Sublime Text 4 bundle identifier
SUBLIME_ID="com.sublimetext.4"
<scheme name="GitHub Inspired" version="142" parent_scheme="Default">
<metaInfo>
<property name="ide">PhpStorm</property>
<property name="ideVersion">2024.2.0.0</property>
<property name="originalScheme">GitHub Inspired</property>
</metaInfo>
<colors>
<option name="CARET_ROW_COLOR" value="f5f5f5" />
<option name="GUTTER_BACKGROUND" value="ffffff" />
<option name="LINE_NUMBERS_COLOR" value="b3b3b3" />
@osbre
osbre / zero-downtime-deployment-script-for-laravel-forge.sh
Last active August 6, 2024 18:02
Ported from freek.dev's Envoy.blade.php. After first deployment with this script, set your "Web Directory" to /current/public
# Configuration
SITE_DIR="/home/forge/myapp.com"
GIT_REPO="[email protected]:myapp/myapp.git"
RELEASES_DIR="$SITE_DIR/releases"
PERSISTENT_DIR="$SITE_DIR/persistent"
CURRENT_DIR="$SITE_DIR/current"
RELEASE_NAME=$(date +"%Y%m%d-%H%M%S")
NEW_RELEASE_DIR="$RELEASES_DIR/$RELEASE_NAME"
# Ensure required directories exist
@osbre
osbre / forge-zero-downtime.sh
Last active August 6, 2024 16:32
(ported from freek.dev's envoy.blade.php setup)
# Configuration
SITE_DIR="/home/forge/staging.streampot.io"
GIT_REPO="[email protected]:StreamPot/SaaS.git"
RELEASES_DIR="$SITE_DIR/releases"
PERSISTENT_DIR="$SITE_DIR/persistent"
CURRENT_DIR="$SITE_DIR/current"
RELEASE_NAME=$(date +"%Y%m%d-%H%M%S")
NEW_RELEASE_DIR="$RELEASES_DIR/$RELEASE_NAME"
# Ensure required directories exist
# FallbackStiToBase
#
# This concern provides a customizable fallback mechanism for Single Table Inheritance (STI) in Rails.
# It allows specifying which types should raise an error when not found, while others fallback to the base class.
#
# Usage:
# class Action < ApplicationRecord
# include FallbackStiToBase
# validates :type, presence: true, inclusion: { in: %w[Value1 Value2 Value3] }
# fallback_excluded_types 'RemovedValue1', 'RemovedValue2'
module Types
class AppendSuffixType < ActiveRecord::Type::String
def initialize(suffix)
@suffix = suffix.to_s
end
def cast_value(value)
value.to_s + @suffix unless value.nil?
end