Skip to content

Instantly share code, notes, and snippets.

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

`Sergey Ivanov Ivanitch

🏠
Working from home
View GitHub Profile
@Ivanitch
Ivanitch / markdown.md
Created March 4, 2024 09:35
Шпаргалка по Markdown
@Ivanitch
Ivanitch / json_sort.php
Created March 8, 2023 11:52
json_sort.php
<?php
function json_sort(string $json, bool $objects=true, bool $arrays=false): string
{
// uses a recursive lambda
$order = null;
$order = function ($json) use (&$order, $objects, $arrays) {
// sort sub-trees
foreach ($json as $key => $value) {
if (is_array($value) || is_object($value)) {
$tmpFile = $sourceFileName;
$fileName = $this->csvFilePath . DIRECTORY_SEPARATOR . $this->csvFileName;
$command = 'xls2csv -c\; -q0 -s cp1251 -d cp1251 ' . $tmpFile . ' > ' . $fileName;
exec($command);
unlink($tmpFile);
protected function getFilename(UploadedFile $file): string
{
$hash = sha1_file($file->tempName);
$name = substr_replace($hash, '/', 3, 0);
$name = substr_replace($name, '/', 7, 0);
return $name . DIRECTORY_SEPARATOR . $file->extension;
}
@Ivanitch
Ivanitch / remove_idea_etc
Created July 13, 2022 09:35
Как удалить любую папку, в т.ч. и .idea, и лишние файлы из Git
Как удалить любую папку, в т.ч. и .idea, и лишние файлы из Git
Создаем файл .gitignore в корне репозитария с содержимым:
.idea
logs/
------------------------------------------------------------------
Подробнее можно ознакомиться на странице: https://git-scm.com/book/ru/v1/Основы-Git-Запись-изменений-в-репозиторий
Удаляем ненужные папки и файлы при синхронизации в Git репозиторий
@Ivanitch
Ivanitch / raec_debug.php
Last active April 28, 2023 14:01
Raec debug runtime
$dataArr = [
0 => 'EF001391',
1 => 'EF000228',
2 => 'EF000227',
];
$debug_log = Yii::app()->runtimePath . '/DebugExport.log';
$dataErr = print_r($dataArr, true);
file_put_contents($debug_log, $dataErr . PHP_EOL, FILE_APPEND);
================================
@Ivanitch
Ivanitch / xmlToArray.php
Created May 26, 2022 10:19
Преобразование SimpleXMLElement в массив
/**
* Преобразует SimpleXMLElement в array
* @param SimpleXMLElement $xml
* @return array
*/
private static function xmlToArray($xml) {
$xml = (array) $xml;
if(empty($xml)) {
return null;
@Ivanitch
Ivanitch / nginx.conf
Created April 29, 2022 01:20 — forked from Kison/nginx.conf
Nginnx config for Yii 2 Advanced App Template (subdomains)
# frontend
server {
listen 80;
server_name yii2.lo;
server_tokens off;
client_max_body_size 128M;
charset utf-8;
access_log /var/log/nginx/yii2-access.log main buffer=50k;
@Ivanitch
Ivanitch / remove-all-from-docker.md
Last active September 30, 2022 00:25 — forked from tomasevich/remove-all-from-docker.md
Удалить/очистить все данные Докера (контейнеры, образы, тома и сети)

Остановить локальные сервисы!

sudo systemctl stop nginx

sudo systemctl stop mysql

sudo chown $USER:$USER /var/run/docker.sock

docker stop $(docker ps -qa)
@Ivanitch
Ivanitch / docker-compose.md
Created February 19, 2022 04:10 — forked from yesnik/docker-compose.md
Docker Guides

Docker Compose

Docker compose is a tool that is used for defining and running multi-container Docker apps in an easy way. It provides docker-compose.yml configuration file that can be used to bring up an app and the suite of services it depends on with just one command.

  • docker-compose up - start all services from docker-compose.yml
  • docker-compose up db - start only service db
  • docker-compose up --build - rebuild all images and run containers
  • docker-compose -f docker-compose.prod.yml up - start all services from docker-compose.prod.yml