Skip to content

Instantly share code, notes, and snippets.

View chluehr's full-sized avatar

Christoph Lühr chluehr

View GitHub Profile
@chluehr
chluehr / encode_compress.php
Created November 28, 2011 08:46
PHP encode and compress
<?php
/* by pablo at compuar dot com see http://php.net/manual/de/function.base64-encode.php
*
*
*/
$string = 'Blah';
$encoded = strtr(base64_encode(addslashes(gzcompress(serialize($string),9))), '+/=', '-_,');
$string= unserialize(gzuncompress(stripslashes(base64_decode(strtr($encoded, '-_,', '+/=')))));
@chluehr
chluehr / restic-backup.sh
Created November 5, 2017 10:57
Backup via restic to Backblaze
#!/bin/bash
#
# Setup:
# wget https://github.com/restic/restic/releases/download/v0.7.3/restic_0.7.3_linux_amd64.bz2
# bunzip2 restic_0.7.3_linux_amd64.bz2
# mv restic_0.7.3_linux_amd64 /usr/local/bin/restic
# chmod a+x /usr/local/bin/restic
#
# crontab -e
# 0 1 * * * /root/bin/restic-backup.sh 2>&1 >>/var/log/restic-backup.log
@chluehr
chluehr / date_loop.sh
Created April 26, 2012 20:28
Bash: Loop over dates
#!/bin/bash
now=`date +"%Y-%m-%d" -d "05/06/2012"`
end=`date +"%Y-%m-%d" -d "05/23/2012"`
while [ "$now" != "$end" ] ;
do
now=`date +"%Y-%m-%d" -d "$now + 1 day"`;
echo $now
done
@chluehr
chluehr / pimcore.vcl
Last active March 5, 2020 08:40
Pimore Varnish Default Configuration
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
backend default {
.host = "127.0.0.1";
.port = "8000";
# health check: every 5 secs, sliding window of 5 checks of which 3 must be good
.probe = {
.url = "/";
.interval = 5s;
@chluehr
chluehr / resizecrop.sh
Created January 26, 2011 14:43
Shell Script to resize / crop images via ImageMagick (min. V6.3.8)
#!/bin/bash
#==========================================
# source size is 300x300 ..
function resizecrop {
SIZE=$1
SRCFILE=$2
DESTFILE=$3
@chluehr
chluehr / cakeagent.sh
Created June 29, 2018 12:41
Updated statuscake agent script to better deal with cpu usage and disk space reporting
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/cakeagent
# Make sure we have some auth information
if [ -f /etc/cakeagent/auth.log ]
then
Authentication=($(cat /etc/cakeagent/auth.log))
else
echo "Something has gone wrong and we can not find your auth credentials. Please reinstall"
exit 1
@chluehr
chluehr / oxid_modules_off.sql
Created October 9, 2013 17:47
Disable OXID modules
DELETE FROM oxconfig WHERE oxvarname IN ("aDisabledModules", "aLegacyModules",
"aModuleFiles", "aModulePaths", "aModules", "aModuleTemplates");
@chluehr
chluehr / Makefile
Created May 7, 2018 10:35
Makefile to fetch(sync) Cloudfront S3 Logs and analyze them with goaccess Logfile Analyzer.
all: fetch report
fetch:
aws s3 sync --exclude "*" --include "*2018-03-*" --include "*2018-04-*" --include "*2018-05-*" s3://$BUCKET/$PATH/ .
report:
find . -name \*.gz | xargs gzcat | goaccess --log-format CLOUDFRONT --date-format CLOUDFRONT --time-format CLOUDFRONT -o ./report.html
@chluehr
chluehr / toAscii.php
Created January 18, 2012 12:56
PHP clean url slug generator / converter (slug)
<?php
// source: http://cubiq.org/the-perfect-php-clean-url-generator
// author: Matteo Spinelli
// MIT License / http://creativecommons.org/licenses/by-sa/3.0/ (please re-check at source)
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
@chluehr
chluehr / php-spawn-command-check-processp-status.php
Created January 30, 2018 11:01
Spawn a shell command from PHP, check Process status, respawn if not running.
<?php
/**
* $ php p.php
* S SPAWNED! RRRRS SPAWNED! RRRRRS SPAWNED! R
*/
function spawn() {
$descriptorspec = array(