Skip to content

Instantly share code, notes, and snippets.

View thephucit's full-sized avatar

Thế Phúc thephucit

View GitHub Profile
@thephucit
thephucit / extractNamespace.php
Created July 27, 2020 02:09
Get namespace from file path
<?php
/**
* Extract namespace from a PHP file
*
* @param string $file
* @return string
*/
public function extractNamespace(string $file) : string
{
@thephucit
thephucit / tips.php
Created July 16, 2020 07:44
Some tips for PhpSpreadsheet
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
const FORMAT_CODE = '_(* #,##0_);_(* (#,##0);_(* "-"??_);_(@_)';
# set row auto height
$worksheet->getRowDimension($rowDetail)->setRowHeight(-1);
@thephucit
thephucit / help.md
Last active June 24, 2020 05:05
increase upload octobercms backend

sudo nano /etc/php/7.2/fpm/php.ini

sudo nano /etc/php/7.2/cli/php.ini

sudo service php-fpm restart

sudo service php7.2-fpm restart

sudo service nginx restart

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hoá đơn {{ invoice.code }}</title>
<style>
.clearfix:after {
content: "";
display: table;
@thephucit
thephucit / BaseMutation.php
Last active May 15, 2020 08:01
AuthMiddleware for octobercms
<?php namespace;
use BackendAuth, Exception, ValidationException;
use Rebing\GraphQL\Support\Mutation;
class BaseMutation extends Mutation
{
/**
* Permission required access to mutation
* @var array
@thephucit
thephucit / index.php
Created May 15, 2020 07:56
create code from id or No
<?php
$code = 'OD.' . str_pad($this->count() + 1, 10, '0', STR_PAD_LEFT);
@thephucit
thephucit / add_cloudflare_ips.sh
Created May 8, 2020 03:23 — forked from dduvnjak/add_cloudflare_ips.sh
Add CloudFlare IP addresses to an EC2 Security Group using awscli
# first we download the list of IP ranges from CloudFlare
wget https://www.cloudflare.com/ips-v4
# iterate over the lines in the downloaded file
# make sure to set `--group-id` and `--port`; more details at http://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html
while read p; do aws ec2 authorize-security-group-ingress --group-id sg-e0000000 --protocol tcp --port 80 --cidr $p; done< ips-v4
@thephucit
thephucit / bash.sh
Created May 7, 2020 06:29
Remote server database from local
ssh username@server-ip -L 5434:127.0.0.1:5434
@thephucit
thephucit / bash.sh
Created May 7, 2020 03:10
Mấy lệnh để cài odoo 13
psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'postgres';"
createuser odoo –pwprompt
createdb odoo -O odoo
pip3.7 install psycopg2 --upgrade
@thephucit
thephucit / _form_toolbar.htm
Last active May 7, 2020 02:25
Override các method mặc định của octobercms, thay đổi giao diện form create, update
<?php
$isCreate = $this->formGetContext() == 'create';
$pageUrl = isset($pageUrl) ? $pageUrl : null;
?>
<div class="form-buttons loading-indicator-container">
<!-- Save -->
<a
href="javascript:;"
class="btn btn-primary oc-icon-check save"