Skip to content

Instantly share code, notes, and snippets.

View AronNovak's full-sized avatar

Aron Novak AronNovak

View GitHub Profile
@AronNovak
AronNovak / ip.php
Created October 4, 2018 12:04
cloudflare + pantheon
<?php
// https://pantheon.io/docs/client-ip/
$remote_ip = isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"];
drush sql-dump --tables-list=`drush sqlq "show tables like '_raw_%'" | xargs | sed -e 's/ /,/g'` > /tmp/only_users.sql
@AronNovak
AronNovak / capitals-array.php
Created April 8, 2019 12:10
World capitals list - PHP array
<?php
$capital_names = [
'Kabul',
'Tirana',
'Algiers',
'Andorra la Vella',
'Luanda',
'Saint John\'s',
'Buenos Aires',
'Yerevan',
diff --git a/includes/environment.inc b/includes/environment.inc
index a4717048..a2416424 100644
--- a/includes/environment.inc
+++ b/includes/environment.inc
@@ -18,7 +18,7 @@ use Webmozart\PathUtil\Path;
* Log PHP errors to the Drush log. This is in effect until Drupal's error
* handler takes over.
*/
-function drush_error_handler($errno, $message, $filename, $line, $context) {
+function drush_error_handler($errno, $message, $filename = NULL, $line = NULL, $context = NULL) {
@AronNovak
AronNovak / RoboFile.php
Last active January 21, 2022 13:07
RoboFile with Drupal 8 / 9 bootstrapped inside
<?php
use Robo\Tasks;
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$GLOBALS['drupal_autoloader'] = require_once 'web/autoload.php';
/**
@AronNovak
AronNovak / RoboFile.php
Created August 5, 2020 11:55
Local Robo instance boostrapping
<?php
use Robo\Tasks;
/**
* Setup an ElasticSearch server locally.
*/
class RoboFile extends Tasks {
const ES_VERSION = '7.5.2';
@AronNovak
AronNovak / disk_used_alert2slack
Last active December 3, 2020 09:27 — forked from AAber/disk_used_alert2slack
Script to monitor disk space and alert via slack when disk usage is > 80% Place the script in /etc/cron.hourly
#!/bin/bash
# Parse df selected output
df -h|egrep -v 'File|tmpfs|docker|udev|snap|loop'| \
while read LINE; do
USED_NUMBER=`echo $LINE |awk '{print $5}'|sed 's/\%//'|sed 's/ //g'`
USED_PERCENT=`echo $LINE |awk '{print $5}'|sed 's/ //g'`
MOUNT_POINT=`echo $LINE |awk '{print $6}'|sed 's/ //g'`
if [ $USED_NUMBER -gt 80 ]; then
# Create message without spaces
@AronNovak
AronNovak / memory_low_alert2slack.sh
Created December 3, 2020 09:54
Memory low alert2slack
#!/bin/bash
LANG=C
MINIMUM_REQUIRED_MEM=256
FREE_MEM=$(free -mt | awk '/Total/{print $4}')
if [ $FREE_MEM -lt $MINIMUM_REQUIRED_MEM ]; then
TOP_PROCESS=$(ps aux --sort rss | tail -n1)
MESSAGE=$(echo "WARNING On $HOSTNAME, memory usage is low: $TOP_PROCESS WARNING" | sed 's/ /_/g')
# Post message
@AronNovak
AronNovak / markdown-to-email
Last active December 3, 2021 10:13 — forked from rtulke/markdown-to-email
markdown-to-emailA simple script to send beautifully formatted emails that you write in Markdown. The email will have an HTML payload and a plain-text alternative, so you'll make everyone happy, including yourself. With added table support.
#!/usr/bin/env python
'''
Send an multipart email with HTML and plain text alternatives. The message
should be constructed as a plain-text file of the following format:
From: Your Name <your@email.com>
To: Recipient One <recipient@to.com>
Subject: Your subject line
---
@AronNovak
AronNovak / file_cleanup.php
Created February 21, 2022 09:07
Drupal 9 - unused / unmanaged unsupervised file cleanup script.
<?php
/**
* @file
* File cleanup script, to be executed after the migration.
*
* Invocation:
* ddev drush scr web/modules/custom/server_migrate/file_cleanup.php .
*/