preg_replace('/\.([a-z0-9$\_]+)/im', '[${1}]', $field);
// a.b.c => a[b][c]
Supervisor config for laravel queue
an config example of supervisor for laravel queue
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/laravel/artisan queue:work --sleep=5 --delay=5 --tries=3
autostart=true
autorestart=true
user=laravel
numprocs=2
redirect_stderr=true
stdout_logfile=/var/logs/laravel-queue.log
[PHP] Configuration for file upload
To upload file in PHP, there are several items to be configured. Otherwise the file not be to access in PHP or error will be return by nginx.
To upload file in PHP, there are several items to be configured. Otherwise the file not be to access in PHP or error will be return by nginx.
- Include the size limit of php
upload_max_filesize=16M
post_max_size=32M
- Increase the size limit of nginx
client_max_body_size 32M;
[PHP] xdebug
Some notes for install XDebug for php
Installation
sudo apt install php-xdebug
Configuration
/etc/php/7.2/mods-available/xdebug.ini
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart=on
xdebug.remote_connect_back=1
vscode configurations
Some of the configurations of my vscode
Fira Code: monospaced font with programming ligatures
It combim 2 or more specific character to an symbol, which is more readable.
"editor.fontFamily": "'Fira Code', Consolas, 'Courier New', monospace",
"editor.fontLigatures": true
[Nginx] Reverse proxy
snippets for nginx reverse proxy
Proxy Cache
proxy_cache_path $CACHE_PATH levels=1:2 keys_zone=CACHE_NAME:10m max_size=1g;
server {
location @proxy {
proxy_pass $PROXY_URL;
proxy_cache CACHE_NAME;
proxy_cache_valid 200 30d; // cache 200 response for 30 days
proxy_cache_valid all 5h; // cache all response for 5 hours
}
}
Git snippets
some of useful git snippets
Archiving Code
-
Pack the difference
git archive HEAD $(git diff $commit --diff-filter=d --name-only)
-
Pack the modified files
tar -cvf - $(git ls-files --m )
HotFix for bootstrap Modal
As bootstrap only support one `Modal` show as the same time. This snippets will help with close the old one.
As bootstrap only support one Modal
show as the same time. This snippets will help with close the old one.
(function () {
let deferredModal = null;
$(document.body).on('show.bs.modal', '.modal', function (e) {
let $modal = $('.modal.show').not(this);
if ($modal.length > 0) {
e.preventDefault();
e.stopPropagation();
deferredModal = this;
$modal.modal('hide');
}
})
.on('hidden.bs.modal', '.modal', function(){
if (!deferredModal) {
return;
}
$(deferredModal).modal('dispose').modal('show');
deferredModal = null;
});
})();
Mysql snippets
Some useful SQL snippets for MySQL
-
create super admin
CREATE USER 'superadmin'@'localhost' IDENTIFIED BY 'some_pass'; GRANT ALL PRIVILEGES ON *.* TO 'superadmin'@'localhost' WITH GRANT OPTION;
-
Create Database
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Pure native js copy2clipboard
snippets for copy text to clipboard
let input = document.createElement('input');
document.body.appendChild(input);
input.style.position = 'fixed';
input.style.left = 0;
input.style.right = 0;
input.value = window.location.href;
if (window.navigator.userAgent.match(/ipad|iphone|ipod/i)) {
let range = window.document.createRange();
let selection = window.getSelection();
range.selectNodeContents(input);
selection.removeAllRanges();
selection.addRange(range);
input.readOnly = true;
input.setSelectionRange(0, 999999);
input.readOnly = false;
} else {
input.select();
}
document.execCommand('copy');
input.remove();