Skip to content

Instantly share code, notes, and snippets.

View lezhnev74's full-sized avatar
🐘
Eating the elephant in pieces

Dmitry Lezhnev lezhnev74

🐘
Eating the elephant in pieces
View GitHub Profile
@lezhnev74
lezhnev74 / slices.go
Last active December 28, 2023 16:02
Go slices lib
// slicePutAt is an efficient insertion function that avoid unnecessary allocations
func slicePutAt[V any](dst []V, pos int, v V) []V {
dst = append(dst, v) // could grow here
copy(dst[pos+1:], dst[pos:])
dst[pos] = v
return dst
}
// sliceFilterInPlace does not allocate
func sliceFilterInPlace[T any](input []T, filter func(elem T) bool) []T {
@lezhnev74
lezhnev74 / observability_client.php
Created December 23, 2023 16:49
Observability PHP client
<?php
declare(strict_types=1);
namespace notes;
/**
* ObservabilityClient can throw upon instantiation, but sending does not block.
*/
class ObservabilityClient
@lezhnev74
lezhnev74 / emojy_detect.php
Created December 5, 2023 16:04
checks if a string contains emojies (PHP)
<?php
/**
* Emoji detects unicode emojis based on:
* "Unicode Emoji" https://www.unicode.org/reports/tr51/
* @see emoji sequences: https://unicode.org/Public/emoji/latest/emoji-sequences.txt
* @see emoji sequences: https://unicode.org/Public/emoji/latest/emoji-zwj-sequences.txt
*/
class Emoji
{
@lezhnev74
lezhnev74 / validator.php
Last active March 9, 2021 03:53
Replace custom placeholder in Validation message (Laravel)
<?php
// When I create a validation rule, I can set my one replacer which helps replace different special placeholders
// For example if validator message is "Problem with :some", then my replacer will handle it
Validator::extend('testrule', function($attribute, $value, $parameters, $validator) {
$validator->addReplacer('testrule', function($message, $attribute, $rule, $parameters){
return str_replace(":some", "whatever", $message);
});
@lezhnev74
lezhnev74 / MysqlCollection.php
Last active November 28, 2017 08:49
Cache in a collection implementation
<?php
class MysqlCollection implements CollectionInterface
{
// .. other stuff
/** @var CacheInterface */
private $cache;
@lezhnev74
lezhnev74 / KnownProblem.php
Created April 8, 2017 17:16
Trait for translatable exceptions
<?php
namespace VideoPublisher\Foundation\Exception;
/**
* This trait will add message translation to any exception.
* The goal of this is to support every exception with string problem code and possible message
*/
trait KnownProblem
{
/** @var string code to look up in documentation like "112_EMAIL_INVALID" */
public function rules()
{
$user = User::find($this->users);
switch($this->method())
{
case 'GET':
case 'DELETE':
{
return [];
So I am facing an Issue - how do I run dedicated Vagrant Virtual Machine with Homestead Box in it?
https://docs.vagrantup.com/ shows how to run the box. But what about settings?
So I did:
vagrant init in folder
then installed Homstead via
composer require laravel/homestead --dev
php vendor/bin/homestead make
Then edited Homestead.yaml
and then did vagrant reload --provision so changes took effect
URL?ZRayDisable=1