Skip to content

Instantly share code, notes, and snippets.

View simPod's full-sized avatar
💥
Trying to BC break your OSS

Simon Podlipsky simPod

💥
Trying to BC break your OSS
View GitHub Profile
@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",

@ciaranmcnulty
ciaranmcnulty / notes.md
Last active March 25, 2024 06:36
Notes on using Docker on ARM Macs (November 2021)

Docker for Mac

On M1 machines, Docker for Mac is running a lightweight linux ARM VM, then running containers within that, so containers are essentially running natively. Don't be fooled by the fact the UI or binary CLI tools (e.g. docker) might require Rosetta.

Within that VM is an emulation layer called QEmu. This can be used by docker to run Intel containers. This does not use Rosetta at all, and has a roughly 5-6X performance penalty. (If you just upgraded your CPU this may result in a similar performance to your old machine!)

Pulling and running with Docker

Many images in public registries are multi-architecture. For instance at the time of writing on Docker Hub the php:8.0-cli image has the following digests:

@Ocramius
Ocramius / psalm-compendium.php
Last active November 9, 2023 07:27
A small compendium of what is possible with `vimeo/psalm` 3.9.x to add some decent type system features to PHP
<?php
// -- types are a compile-time propagated concept
// https://psalm.dev/r/338f74a96c
class TheType
{
/** @var string */
public $foo = 'bar';
}
#!/usr/bin/env php
<?php
declare(strict_types=1);
namespace WaitForElasticsearch;
use InvalidArgumentException;
use UnexpectedValueException;
use function curl_close;
@nikolaposa
nikolaposa / rich_domain_model.php
Created August 19, 2019 07:56
Demonstrates the use of Method Injection technique to capture key bussiness logic in the entity itself.
<?php
declare(strict_types=1);
final class AnonymizeData
{
private $payload;
public function __construct(array $payload)
{
@jiripudil
jiripudil / README.md
Created November 19, 2018 07:52
Running and compiling a PhpStorm plugin
  1. Open File | Project Structure.
  2. In Platform Settings | SDK, add an Intellij Platform Plugin SDK pointing to an installation of PhpStorm.
  3. In Project Settings | Libraries, add a Java library with two files from the installation of PhpStorm: plugins/php/lib/php.jar and plugins/php/lib/php-openapi.jar.
  4. In Project Settings | Modules, set the Module SDK to the SDK created in step 2.
  5. At the same place, add the library created in step 3 to the module if it's not there already. Then set its Scope to Provided and make sure the Export checkbox is unchecked.

Now you should be able to create a Plugin-type run configuration and run the plugin. To build a final jar file, use Build | Prepare Plugin Module For Deployment.

@den-crane
den-crane / CH-argMin-vs-Limit
Last active September 8, 2020 07:28
CH argMin vs Limit
create table test (p Int64, t Int64, x String, y Int64) engine=MergeTree order by (p,t)
insert into test select intDiv(number,10000), rand() r, toString(r), number from numbers(10000000);
select count(), min(x) from (
select * from test order by p, t limit 1 by p
)
┌─count()─┬─min(x)─┐
│ 1000 │ 100420 │
└─────────┴────────┘
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active June 1, 2024 22:47
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@ueokande
ueokande / benchmark-commands.md
Last active January 22, 2024 12:38 — forked from jkreps/benchmark-commands.txt
Kafka Benchmark Commands

Benchmark commands

Producer

Setup

bin/kafka-topics.sh \
  --zookeeper zookeeper.example.com:2181 \
  --create \
@jonathantneal
jonathantneal / README.md
Last active March 19, 2024 23:31
Local SSL websites on macOS Sierra

Local SSL websites on macOS Sierra

These instructions will guide you through the process of setting up local, trusted websites on your own computer.

These instructions are intended to be used on macOS Sierra, but they have been known to work in El Capitan, Yosemite, Mavericks, and Mountain Lion.

NOTE: You may substitute the edit command for nano, vim, or whatever the editor of your choice is. Personally, I forward the edit command to Sublime Text:

alias edit="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"