Skip to content

Instantly share code, notes, and snippets.

@nd3w
nd3w / php-snippets.md
Last active March 15, 2024 15:45
PHP Snippets

Dump all PHP variables

$all_vars = get_defined_vars();
print_r($all_vars);

Create an array for a range (e.g: array with number from 1 to 9)

$number = 9;

for ($i = 1; $i <= $number; ++$i) {

@nd3w
nd3w / gist:ff2b06464121d1aabec7287f37f00d1a
Last active August 19, 2019 03:01
Linux Aliases to Switch Amongs PHP Versions
Assuming I have three different PHP versions on my system:
1. PHP 5.6
2. PHP 7.1
3. PHP 7.2
To switch two between versions, add these aliases into your ~/.bashrc file:
alias php5671='sudo a2dismod php5.6 ; sudo a2enmod php7.1 ; sudo service apache2 restart ; echo 2 | sudo update-alternatives --config php'
alias php5672='sudo a2dismod php5.6 ; sudo a2enmod php7.2 ; sudo service apache2 restart ; echo 3 | sudo update-alternatives --config php'
@nd3w
nd3w / linux-commands.txt
Last active April 2, 2024 07:40
A Collection of Useful Linux Commands
Backup with bunzip
tar cvfj file.tar.bz2 *
tar cvfj file.tar.bz2 /path/to/directory_to_backup/
Extract from bunzip to directory 'archive'
tar -xvf archive.tar.bz2 ./
Compress multi directories into each own compressed files
for i in */; do zip -r "${i%/}.zip" "$i"; done
for i in */; do tar -czvf "${i%/}.tar.gz" "$i"; done
@nd3w
nd3w / php.ini for development
Created April 27, 2019 23:22
PHP configuration for development machine
; For dev only
expose_php=Off
log_errors=On
error_log=/var/log/httpd/php_scripts_error.log
file_uploads=On
;open_basedir="/var/www/html/"
error_reporting = E_ALL
; Should be 'off' on prod server
allow_url_fopen=On
@nd3w
nd3w / gist:dde9fa08b51b3b64c23c30c16038c125
Created August 3, 2019 09:12
Important query for MySQL
Get how many rows in whole database
SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'db_name';
@nd3w
nd3w / install-wine4-ubuntu18.04.txt
Last active October 29, 2019 09:00
Installing Wine 4.0 on Ubuntu 18.04 and Linux Mint 19
$ sudo dpkg --add-architecture i386
$ sudo apt update
$ wget -qO- https://dl.winehq.org/wine-builds/Release.key | sudo apt-key add -
$ sudo apt-add-repository 'deb http://dl.winehq.org/wine-builds/ubuntu/ bionic main'
$ sudo apt update
@nd3w
nd3w / Binding_params.php
Last active October 24, 2019 06:04
Dynamically binding params in prepared statment
<?php
$array = [1,2,3,4,5,6,7];
$count_array = count($array);
$placeholders = implode(',', array_fill(0, $count_array, '?'));
$query = $DB->Prepare('
SELECT id, name
FROM table_name
WHERE id IN (' . $placeholders . ')
');
@nd3w
nd3w / horizontal-vertical-center.html
Last active December 5, 2019 01:06
Horizontally and vertically center div in a page
<!DOCTYPE html>
<html>
<head>
<title>The Center </title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet">
<style>
html, body {
height: 100%;
}
@nd3w
nd3w / mysql-queries.md
Last active April 3, 2023 08:23
Collection of useful MySQL queries

List of table's names only

SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='db name' 
    AND `TABLE_NAME`='table name';

Select all rows with the same value

SELECT e1.*

@nd3w
nd3w / install-nginx-mariadb-phpfpm-on-ubuntu-20.04.md
Last active April 8, 2024 10:28
How to Install Nginx, MariaDB, PHP-FPM on Ubuntu 20.04

How to Install Nginx, MariaDB, PHP-FPM on Ubuntu 20.04

This is a way to install and set up Nginx, MariaDB and PHP-FPM on Ubuntu 20.04.

NOTE: This has been prepared for ease of use in mind, not security, mostly in development machine. Please do not use these instructions to setup on a public server environment. Use other proper manuals instead.

$ sudo apt update

Nginx