Tuesday, September 12, 2017

Nginx test && reload

sudo nginx -t && sudo nginx -s reload

Thursday, August 17, 2017

Friday, June 23, 2017

How to remove permanently last commit from git remote

To only remove commit but save current code use:

git reset --soft HEAD~1
...make new commit and then
git push origin master --force


To remove commit and remove commit's code use:

git reset --hard HEAD~1
git push origin master --force

Saturday, April 8, 2017

how to create helpers file laravel5

Simple tip for simple stuff.

create folder Helpers in app directory
create file StringHelper.php in app\Helpers

<?php
namespace App\Helpers;
class StringHelper
{
public static function getCleanString($string)
{
//remove unnecessary chars
$string = str_replace(['-', ' '], '', $string);
return str_slug($string);
}
}

add any simple function in this class as static.
when you need a different helper, create new class for example YoutubeHelper.php and add there stuff you need.

usage

\App\Helpers\StringHelper::getCleanString($name)

Tuesday, March 14, 2017

PHP format tree comments, categories, nested sets

Simple function for formatting tree. One cons - you need to pass all items (all comments of the post) to format them.

<?php

function formatTree($tree, $parent)
{
    $tree2 = array();
    foreach ($tree as $item) {
        if ($item['parent_id'] == $parent) {
            $tree2[$item['id']] = $item;
            $tree2[$item['id']]['child'] = formatTree($tree, $item['id']);
        }
    }

    return $tree2;
}


//for demo
$beforeTree = [
    ['id' => 1, 'parent_id' => 0],
    ['id' => 2, 'parent_id' => 1],
    ['id' => 3, 'parent_id' => 2],
    ['id' => 4, 'parent_id' => 0],
    ['id' => 5, 'parent_id' => 4],
    ['id' => 6, 'parent_id' => 4],
];
$afterTree = formatTree($beforeTree, 0);

var_dump($afterTree);

Wednesday, January 4, 2017

Redis stop Redis start

if you have properly installed redis as server just run
sudo systemctl restart redis

If not casually:
to stop redis
redis-cli shutdown 
to start redis
redis-server