Skip to content

Instantly share code, notes, and snippets.

View tezvi's full-sized avatar

Andrej Vitez tezvi

  • /dev/null
View GitHub Profile
@tezvi
tezvi / CsvReader.php
Last active August 2, 2023 11:57
CSV reader class that supports mapping columns with custom names.
<?php
/**
* CSV reader class that supports mapping columns with custom names.
*
* @author Andrej Vitez <andrejvitez@gmail.com>
*/
class CsvReader implements Iterator {
private string $filePath;
private array $columns = [];
# Bash prompt for LXC prompty detection
#
# Author: Andrej Vitez <contact@andrejvitez.com>
#
# Add this file to your homedir .bash_profile file or create a new one under
# /etc/profile.d/lxc.sh
#
# This script will add LXC tag to your PS prompt to hint user that is using lxc container.
# Skip all for noninteractive shells.
@tezvi
tezvi / git-symfony-bash-prompt.sh
Last active March 29, 2020 17:53
Add current GIT branch and Symfony environment identifier to your Bash prompt
# Bash prompt for GIT and Symfony support
#
# Author: Andrej Vitez <contact@andrejvitez.com>
#
# Add this file to your homedir .bash_profile file or create a new one under
# /etc/profile.d/git-symfony.sh
# This script will add current git branch to your Bash prompt. Also it will try to extract
# Symfony APP_ENV environment variable and add it to Bash prompt.
#
# If no GIT or Symfony data is available in current directory context a default Bash prompt
@tezvi
tezvi / DefaultOrderExtensionDecorator.php
Created May 20, 2019 20:34
Prevent duplicate SQL order when combining ApiPlatform default resource order and order filters
<?php
/**
* @author Andrej Vitez <andrejvitez@gmail.com>
* @licence MIT
*/
declare(strict_types=1);
namespace Acme\ApiPlatform\Extension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\ContextAwareQueryCollectionExtensionInterface;
#!/bin/bash
# Author Andrej Vitez
# Utility script for printing very simple Apache and PHP process statistics based on netstat and ps output
function usage() {
echo -e "usage: $0 toolname\n
Available options:
proc - count apache processes
php - count php processes
port80 - Connections to port 80
@tezvi
tezvi / f2banlog.sh
Last active July 3, 2017 17:50
Output unique banned IP addresses from fail2ban service log file
#!/bin/bash
# output unique ip addresses banned by fail2log
grep "Ban " /var/log/fail2ban.log \
| grep `date -d "1 day ago" +%Y-%m-%d` \
| awk '{print $NF " ("$NF") "$6""}' \
| sort \
| uniq -c \
| awk '{print $2" "$3" "$4" "$1}' \
| logresolve \
@tezvi
tezvi / myip.php
Created July 2, 2017 10:47
PHP script to automatically update NO-IP hostname WAN IP address
<?php
/**
* Script that returns client IP address back to the client.
*/
// this password should be used in original script that calls this one via HTTP request.
$configPassword = 'PASSWORD_TO_USE_THIS_SCRIPT';
// check credentials
if (empty($_POST['passwd']) || $_POST['passwd'] != $configPassword) {
@tezvi
tezvi / idle-cleanup.sh
Last active February 8, 2018 06:02
This script periodically kills firefox or chromium processes when idle timeout occurs in order to prevent device overheat or overuse of NUC resources (memory)
#!/bin/bash
# author Andrej Vitez
# This script is used as a cronjob on Ubuntu 16 on Intel NUC / Compute Stick connected to TV
# as a media center. The idea is to periodically kill firefox or chromium processes in order to prevent device
# overheat or overuse of NUC resources (memory). In case if someone is watching a long movie script
# will show a GUI timeout dialog so the user can abort. Similar to when a TV goes to sleep.
#
# IMPORTANT!
# run the script by dbus-launch to configure dbus session needed by script
# EXAMPLE: $ dbus-launch --sh-syntax --exit-with-session SCRIPT_PATH