Edit file ~/.bash_aliases
For example, I make alias a. So when I press a it will produce php artisan tinker
Here file ~/.bash_aliases
alias a='php artisan tinker'
Load aliases immediately
Updated: 28th September 2021
Tags: m3u8
Updated: 15th June 2021
Tags: php
Php isset will tell false if variable is null.
//false
isset($a[1]);
$a[1] = null;
//false
isset($a[1]);
That’s why you should use array_key_exists if you need to check if it is set or not.
//false
array_key_exists($a[1]);
$a[1] = null;
//true
array_key_exists($a[1]);
Updated: 15th April 2021
Tags: laravel
DB::enableQueryLog(); // Enable query log
// use orm
dd(DB::getQueryLog()); // Show results of log
Show process list sorted by memory usage
ps aux --sort=-%mem | awk 'NR<=800{print $0}'
Show process list with full start date
Updated: 12th April 2021
Tags: git
Remove commit but save current code
git reset --soft HEAD~1
git push origin master --force
Remove commit and remove commit’s code
git reset --hard HEAD~1
git push origin master --force
Laravel queue job is caching your job php code, so after updating job code you need to:
php artisan queue:restart
Updated: 24th November 2020
Tags: nginx
Fast command to test nginx config and reload nginx if test is successful
sudo nginx -t && sudo nginx -s reload
To run some command in background, so you can close terminal, type the following:
nohup command-with-options &
TL DR; To build app on windows to linux 64 type this in powershell
$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build main.go
Updated: 6th February 2020
Tags: php
PHP server in current directory
PHP server in public directory
php -S localhost:8000 -t public
Updated: 24th December 2019
Tags: sql mysql
Updated: 24th December 2019
Tags: sql mysql
If you try to import dumped file, and there is such an error, try using mysql console with options and then import sql file
mysql -u root -p --max_allowed_packet=6400M
Troubleshoot
If you haven’t access to console or the previous doesn’t work
set global max_allowed_packet=10000000000;
Updated: 22th December 2019
Tags: sql
SELECT * FROM my_table ORDER BY id DESC LIMIT 1;
Updated: 22th December 2019
Tags: sql
SELECT MAX(id) FROM my_table;
Get random row from table in laravel 5.3+
$randomRow = DB::table('table')
->inRandomOrder()
->first();
Get random id from table in laravel 5.3+
$randomId = DB::table('table')
->inRandomOrder()
->value('id');
Updated: 22th December 2019
Tags: sql mysql
Updated: 22th December 2019
Tags: sql
SELECT * FROM my_table ORDER BY RAND() LIMIT 1;