Skip to content

Instantly share code, notes, and snippets.

View tschifftner's full-sized avatar

Tobias Schifftner tschifftner

View GitHub Profile
@tschifftner
tschifftner / query.sql
Last active March 16, 2018 08:42
Get all products not assigned to a category (Magento)
SELECT cpe.entity_id, cpe.sku
FROM catalog_product_entity as cpe
LEFT JOIN catalog_category_product as ccp on cpe.entity_id = ccp.product_id
WHERE category_id IS NULL
@tschifftner
tschifftner / query.sql
Created March 16, 2018 08:41
Select all products with no image assigned (Magento)
SELECT sku, catalog_product_entity_media_gallery.value
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
@tschifftner
tschifftner / query.sql
Created April 5, 2018 14:13
Get products not updated by ho_import recently
SELECT cpe.sku, hie.profile, hie.updated_at FROM ho_import_entity as hie
LEFT JOIN catalog_product_entity as cpe ON cpe.entity_id = hie.entity_id
WHERE hie.updated_at < NOW() - INTERVAL 2 MONTH
@tschifftner
tschifftner / ansible-role-test.sh
Last active August 5, 2018 10:10 — forked from geerlingguy/ansible-role-test.sh
Ansible Role Test Shim Script
#!/bin/bash
#
# Ansible role test shim.
#
# Usage: [OPTIONS] ./tests/test.sh
# - distro: a supported Docker distro version (default = "centos7")
# - playbook: a playbook in the tests directory (default = "test.yml")
# - role_dir: the directory where the role exists (default = $PWD)
# - cleanup: whether to remove the Docker container (default = true)
# - container_id: the --name to set for the container (default = timestamp)
@tschifftner
tschifftner / entrypoint.sh
Created December 22, 2020 09:36
Add secrets in Docker as environment variable
# Add secrets as environment variables
export $(egrep -v '^#' /run/secrets/* | xargs)
@tschifftner
tschifftner / entrypoint.sh
Created December 22, 2020 09:39
Support for env variables ending with _FILE
# Convert all environment variables with names ending in _FILE into the content of
# the file that they point at and use the name without the trailing _FILE.
# This can be used to carry in Docker secrets.
# Source: https://github.com/grafana/grafana-docker/pull/166/files
for VAR_NAME in $(env | grep '^[^=]\+_FILE=.\+' | sed -r "s/([^=]*)_FILE=.*/\1/g"); do
VAR_NAME_FILE="$VAR_NAME"_FILE
if [ "${!VAR_NAME}" ]; then
echo >&2 "ERROR: Both $VAR_NAME and $VAR_NAME_FILE are set (but are exclusive)"
exit 1
fi
@tschifftner
tschifftner / deploy.sh
Created December 22, 2020 09:40
Load variables from .env within a bash script
# Load variables from .env
if [ -f .env ]; then
export $(cat .env | xargs)
fi
@tschifftner
tschifftner / fail2ban-cleanup.sh
Last active March 30, 2021 15:59
Clean fail2ban database from older entry - use script with cronjob!
#!/usr/bin/env bash
# Tobias Schifftner, @tschiffnter
#
# Usage:
# bash fail2ban-cleanup.php <fail2ban.sqlite3>
FILE=${1:-"/var/lib/fail2ban/fail2ban.sqlite3"}
[ -f "$FILE" ] || { echo "$FILE not found"; exit 1; }
@tschifftner
tschifftner / commit-message.txt
Created September 2, 2021 09:53
Semantic Release BREAKING CHANGE commit message example
chore: Trigger major release for previous commits
BREAKING CHANGE: Did some stuff
@tschifftner
tschifftner / loadCsvFileToArray.php
Created February 22, 2022 09:53
Helper function to load csv file into array
<?php
public function loadCsvFileToArray($filepath)
{
$resource = fopen($filepath, 'r');
$columns = fgetcsv($resource, null, ',', '"');
$collection = [];
while($data = fgetcsv($resource, null, ',', '"')) {
$row = array_combine($columns, $data);