Skip to content

Instantly share code, notes, and snippets.

View szabacsik's full-sized avatar
🖖

András Szabácsik szabacsik

🖖
View GitHub Profile
@szabacsik
szabacsik / snapshot.php
Last active December 7, 2023 15:06
MySQL Database Snapshot to CSV Exporter
<?php
/**
* This PHP script creates CSV snapshots of all tables in a specified MySQL database.
* Useful for database analysis and backup purposes. The script connects to the MySQL
* database using PDO, retrieves the list of all tables (excluding specified ones),
* and then exports each table's contents to a CSV file. The CSV files are saved in a
* directory named 'snapshots' inside the script's directory, with each run generating
* a new timestamped subdirectory for organization.
*
@szabacsik
szabacsik / triggers.php
Created November 27, 2023 07:25
MySQL Table Change Logging Trigger Generator Script
<?php
/**
* MySQL Table Change Logging Trigger Generator Script
*
* This script generates triggers for all tables in the $dbname database,
* which log INSERT, UPDATE, and DELETE operations.
* The triggers record modifications in the 'change_log' table,
* storing the name of the affected table, the type of change (INSERT, UPDATE, DELETE),
* the timestamp of the change, and the old and new data of the affected rows in JSON format.
@szabacsik
szabacsik / php-dbal-orm-query-builder.md
Last active October 18, 2022 15:03
PHP - DBAL / ORM / Query Builder

PHP - DBAL / ORM / Query Builder

Doctrine Query Builder

use Doctrine\DBAL\DriverManager;

require_once __DIR__ . '/vendor/autoload.php';

$connectionParams = [
@szabacsik
szabacsik / user-management.md
Last active May 4, 2022 12:05
User Management

Linux User Management

create group with group id

groupadd -g 1000 johndoe

create user with user id and group id

useradd -m --home /home/johndoe johndoe --uid 1000 --gid 1000 --groups group1,group2,sudo
@szabacsik
szabacsik / compare.md
Created March 22, 2022 14:00
Recursively compare two directories
diff --brief --recursive /path/to/dir1 /path/to/dir2
@szabacsik
szabacsik / centos-php8.md
Created February 17, 2022 10:52
Install or Upgrade PHP 8.1.3 on CentOS 7.9.2009
# yum remove php* -y
yum clean all
yum makecache
yum update -y
yum install dnf -y
dnf upgrade --refresh
yum-config-manager --disable remi-php74
yum-config-manager --enable remi-php81
dnf install php php-cli php-common php-pdo php-xml php-mbstring php-zip php-devel php-curl php-pear php-json php-xdebug -y
@szabacsik
szabacsik / ansible.md
Created July 7, 2021 06:13
Ansible, WSL2, Vagrant

Ansible, WSL2, Vagrant

Install

apt-get install sshpass
add-apt-repository ppa:ansible/ansible
apt-get update
apt-get install ansible
ansible --version
ansible-galaxy --version
@szabacsik
szabacsik / psr7-psr17.php
Created July 6, 2021 14:17
PHP - PSR-7 HTTP message interfaces & PSR-17 HTTP Factories
<?php
/*
* composer require guzzlehttp/psr7
* composer require laminas/laminas-diactoros
* composer require slim/psr7
* composer require nyholm/psr7
* composer require nyholm/psr7-server
*
* https://www.php-fig.org/psr/psr-7/
* https://www.php-fig.org/psr/psr-17/
@szabacsik
szabacsik / network.md
Last active October 15, 2021 19:50
Network Tools

run a basic port scan

nc -z -v 192.168.100.100 80

Connection to 192.168.100.100 80 port [tcp/http] succeeded!

run a basic port scan on ports between numbers 1 and 1000

netcat -z -v 192.168.100.100 1-1000
@szabacsik
szabacsik / csv-iterator.php
Last active June 23, 2021 14:59
PHP CSV file iterator
<?php
//https://www.linkedin.com/learning/advanced-php/create-an-iterator?u=2113185
class CsvIterator extends IteratorIterator
{
public function __construct(string $path)
{
parent::__construct(new SplFileObject($path, 'r'));
$file = $this->getInnerIterator();