Skip to content

Instantly share code, notes, and snippets.

View gladx's full-sized avatar
🕺
Coding ...

Ali Yousefi gladx

🕺
Coding ...
View GitHub Profile
@gladx
gladx / human_filesize.php
Last active April 8, 2021 12:30
Human readable file size in php
<?php
// http://jeffreysambells.com/2012/10/25/human-readable-filesize-php + some edit
// https://gist.github.com/liunian/9338301
function human_filesize($bytes, $decimals = 2)
{
if ($bytes < 1024) {
return $bytes . ' B';
}
$factor = floor(log($bytes, 1024));
<?php
// http://ascii-table.com/ansi-escape-sequences.php
// http://ascii-table.com/ansi-escape-sequences-vt-100.php
// "\033[?25l" Hide the cursor.
// "\033[?25h" Show the cursor.
// "\033[K" Delete everything from the cursor to the end of the line.
// echo '1-Start Line', "\n";
sudo passwd username
------------------- hardware info
Battery Info
upower -i /org/freedesktop/UPower/devices/battery_BAT0
acpi -V
less a.txt less is show text file faster than vim or more
more a.txt text editor ?
------------------
how copy folder with content
how detect system ?
/usr/lib/systemd tells you you're on a systemd based system.
/usr/share/upstart is a pretty good indicator that you're on an Upstart-based system.
/etc/init.d tells you the box has SysV init in its history
----- OR
strings /sbin/init | grep -q "/lib/systemd" && echo SYSTEMD
strings /sbin/init | grep -q "sysvinit" && echo SYSVINIT
strings /sbin/init | grep -q "upstart" && echo UPSTART
----- OR
sudo stat /proc/1/exe
@gladx
gladx / 1-7 new php.php
Last active January 1, 2018 20:56
how get 1th and 7th day of week in persian
/**
* ورودی تابع آبجکت DateTime است
* خروجی این متد تاریخ اول و آخر هفته است
* اول هفته شنبه و آخر هفته جمعه
* خروجی نمونه
* [
* 'from' => 2018-1-6,
* 'to' => 2018-1-12
* ]
*/
@gladx
gladx / .htaccess
Created October 18, 2020 23:36
.htaccess with redirect to https
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
# php install
## apt
sudo add-apt-repository ppa:ondrej/php
## set other version
sudo update-alternatives --config php
// sudo update-alternatives --set php /usr/bin/php7.1
apt-get install -y \
php8.2-cli php8.2-dev \
@gladx
gladx / api-platform-code-coverage-help.md
Created July 13, 2021 07:50
Manual setup xdebug and phpunit coverage code in api-platform with docker
docker exec  -it  project_name_xxx_php_1 sh

apk add --no-cache --virtual .build-deps $PHPIZE_DEPS;
pecl install xdebug-3.0.2;
docker-php-ext-enable xdebug;

pecl install pcov
composer require --dev pcov/clobber
vi /usr/local/etc/php/php.ini
if(responseCode.code === 200){
var jsonData = JSON.parse(responseBody);
//postman.setEnvironmentVariable("usertoken1", jsonData.data.token);
pm.collectionVariables.set("token", jsonData.data.token)
}
sshuttle --dns -r ubuntu@130.250.10.5 -x 130.250.10.5 0/0