Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Ocramius / handling-optional-input-fields-with-type-safe-abstractions.md
Last active March 17, 2023 12:06
Handling optional input parameters in PHP with `vimeo/psalm` and `azjezz/psl`

Handling optional input parameters in PHP with vimeo/psalm and azjezz/psl

I had an interesting use-case with a customer for which I provide consulting services: they needed multiple fields to be marked as "optional".

Example: updating a user

We will take a CRUD-ish example, for the sake of simplicity.

For example, in the following scenario, does a null $description mean "remove the description",

@keepitsimple
keepitsimple / bitbucket-pipelines.yml
Last active June 19, 2023 09:02
Bitbucket pipeline to sync / copy code commits to GitHub. How to sync Bitbucket repo to GitHub
image: alpine/git:1.0.26
definitions:
services:
docker:
memory: 1024
steps:
- step: &Push-to-GitHub
name: Push code changes to GitHub
@lennardv2
lennardv2 / 1. Building PHP-MAMP on Apple Silicon M1.md
Last active February 29, 2024 07:57
Native PHP development / MAMP stack on Apple silicon M1

Building the MAMP stack (php, apache & mysql) on Apple Silicon ARM (native)

Update! This tutorial is outdated. Nowadays brew installes m1 binaries just fine. Also use valet: https://laravel.com/docs/9.x/valet. It's 10x easier.

In this tutorial, we'll build the the nescessary packages for ARM via homebrew. After that we'll configure apache2 for using virtual hosts. The native php is ofcourse way faster, see the results of this benchmark below.

TEST NAME SECONDS OP/SEC
@jfcherng
jfcherng / .env
Last active July 21, 2024 20:30
Symfony 5 maintenance mode
MAINTENANCE_MODE=0
@jfcherng
jfcherng / SimpleCrypto.php
Created October 26, 2019 20:22
Yet another simple encryption/decryption wrapper.
<?php
declare(strict_types=1);
namespace App\Core;
use RuntimeException;
class SimpleCrypto
{
@grigory51
grigory51 / indexes_to_add.sql
Last active July 6, 2024 11:37 — forked from mitio/indexes_to_add.sql
OpenCart SQL profiler and indexes for improved speed and page load time
ALTER TABLE `oc_product_to_store` ADD INDEX(`store_id`);
ALTER TABLE `oc_product_description` ADD INDEX(`language_id`);
ALTER TABLE `oc_category_path` ADD INDEX(`path_id`, `category_id`);
ALTER TABLE `oc_category_path` ADD INDEX(`category_id`, `path_id`);
SET sql_mode = 'STRICT_TRANS_TABLES'; -- mysql 5.7
ALTER TABLE `oc_product` ADD INDEX(`status`);
-- Add these to speed up OpenCart
ALTER TABLE `oc_product` ADD INDEX(`date_available`, `status`);
@olimsaidov
olimsaidov / Geatest.php
Created September 8, 2016 05:24
Doctrine Greatest Function
<?php
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
class Greatest extends FunctionNode
{
@cannikin
cannikin / deploy.rb
Last active October 22, 2018 09:02
Notify Sentry of a new release via Capistrano
# This task will notify Sentry via their API[1] that you have deployed
# a new release. It uses the release timestamp as the `version`
# (like 20151113182847) and the git ref as the optional `ref` value.
#
# This task requires several environment variables be set (or just
# hardcode the values in here if you like living on the edge):
#
# ENV['SENTRY_API_ENDPOINT'] : API endpoint, https://app.getsentry.com
# ENV['SENTRY_ORG'] : the organization for this app
# ENV['SENTRY_PROJECT'] : the project for this app
@jbergler
jbergler / .gitignore
Last active April 9, 2024 19:49
Acestream on Mac
.vagrant