Skip to content

Instantly share code, notes, and snippets.

View YaroslavB's full-sized avatar
🏠
Working from home

YaroslavB YaroslavB

🏠
Working from home
  • Kiev/Ukraine
View GitHub Profile
@YaroslavB
YaroslavB / Sorter.php
Created June 17, 2024 15:23 — forked from oplanre/Sorter.php
Light abstraction layer for sorting arrays in php
<?php
class Sorter {
public function __construct(private array $array) {}
/**
* Sort the array by a specific key in ascending or descending order.
*
* @param string $key The key to sort by.
* @param string $order The order direction, 'asc' for ascending or 'desc' for descending. Default is 'asc'.
* @return self
@YaroslavB
YaroslavB / rector.php
Created June 13, 2024 13:14 — forked from BusterNeece/rector.php
Rector script to migrate OpenAPI specifications from PHP Annotations to Attributes
<?php
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$openApiAnnotationsRaw = [
'AdditionalProperties',
@YaroslavB
YaroslavB / Array Objects in PHP.md
Created May 27, 2024 05:43 — forked from Jeff-Russ/Array Objects in PHP.md
PHP: ArrayObject, IteratorAggregate , ArrayAccess , Serializable , Countable

Array Objects in PHP

Array are not object in PHP but PHP does give us some ways to make object that act like arrays. First, there is the ArrayObject class which is pretty close to what you have with a normal array (you can iterate it, use [] etc.) If you use it as a parent for your class you can add methods to it.

class ArrObj extends ArrayObject{
	// add methods here
@YaroslavB
YaroslavB / Instructions.sh
Created September 26, 2022 06:50 — forked from GhazanfarMir/Instructions.sh
Install PHP7.2 NGINX and PHP7.2-FPM on Ubuntu 16.04
########## Install NGINX ##############
# Install software-properties-common package to give us add-apt-repository package
sudo apt-get install -y software-properties-common
# Install latest nginx version from community maintained ppa
sudo add-apt-repository ppa:nginx/stable
# Update packages after adding ppa
@YaroslavB
YaroslavB / MyRepository.php
Created August 15, 2022 08:52 — forked from bulton-fr/MyRepository.php
Doctrine yield
<?php
namespace MyBundle\Repository;
use Doctrine\ORM\EntityRepository;
use MyBundle\Doctrine\RepositoryTrait;
class MyRepository extends EntityRepository
{
use RepositoryTrait;
@YaroslavB
YaroslavB / hellobot.php
Created December 7, 2021 11:35 — forked from ingria/hellobot.php
Simple PHP Telegram Bot
<?php
// @see https://core.telegram.org/bots/samples/hellobot
define('BOT_TOKEN', '12345678:replace-me-with-real-token');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
function apiRequestWebhook($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
<?php
ini_set('display_errors', 'On');
require 'vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\CssSelector\CssSelectorConverter;
$client = new GuzzleHttp\Client();
$url = 'https://us.fotolia.com/search?k=cats&filters%5Bcontent_type%3Aphoto%5D=1&search-submit=Search&limit=5';
$data = $client->get($url);
@YaroslavB
YaroslavB / ffmpeg.md
Created March 30, 2021 07:57 — forked from Orangestar12/ffmpeg.md
quick ffmpeg cheat sheet

These are a few quick easy ffmpeg command lines that can be used to make oft-used video formats. I use them a lot so I wrote them down in a txt file but I converted it to markdown to upload here and access on all my pcs.

Feel free to use 'em. I've gathered them through superuser posts, wiki trawls, and personal experience.

General notes

  • Add -movflags faststart to make mp4 files have their headers at the beginning of the file, allowing them to be streamed (i.e. played even if only part of the file is downloaded).
  • The MP4 container supports MP3 files, so if libfdk_aac isnt available (it's the only good AAC enc) use libmp3lame.
    • Update: unless you're uploading them to Twitter. Twitter doesn't like MP4 files with MP3 audio. Fall back to AAC and provide a higher quality alternative somewhere else.
  • For MP4 files, use -preset X to use MP4 enc presets, like slow or superfast. (veryfast or fast is ok)
<?php
/****************** удаляем из массива ******************/
//массив из которого нужно удалить
$letters = array('(', ')', '[', ']', '{', '}','h', 'r','ff');
//массив данных, которые не трогаем
$no_delete = array('(', ')', '[', ']', '{', '}');
foreach($letters_new as $key => $char){
<?php
/**************
класс чтения и записе csv файла
***************/
/**********************
Иногда при просмотре csv файла в эксель, выходит странная кодровка. Дело не в самой кодировки файла, а в отсутствие одной опции.
fprintf ( $ fp , chr ( 0xEF ). chr ( 0xBB ). chr ( 0xBF ));
В общем виде выглядит это так
$fp = fopen("путь", 'r+');