Skip to content

Instantly share code, notes, and snippets.

@AndisGrossteins
AndisGrossteins / Bibite_herding_herbivore.json
Created January 19, 2022 15:20
Modified Bibite save file from artificial life simulation The Bibites. This one is a herbivore with strong herding behavior. Place multiple nearby to observe the herding.
{
"transform": {
"_position": [-76.51986,
486.9061
],
"_rotation": 350.229431,
"_scale": 0.8118029
},
"rb2d": {
"px": -76.51986,
@AndisGrossteins
AndisGrossteins / wp-config.php
Created January 21, 2021 14:56
Run WordPress site with any given domain name by setting two constants in wp-confing.php
<?php
// Snippet [...]
// Use any provided domain name from request as the site URL without redirection
// Note: Your Apache/Nginx or whatever server has to be configured to serve any chosen domain names from same document root directory
if( isset($_SERVER['HTTP_HOST']) ) {
define('WP_HOME', "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}");
define('WP_SITEURL', WP_HOME);
}
@AndisGrossteins
AndisGrossteins / start-services.sh
Last active January 8, 2021 02:33
Start Linux daemons (services) in WSL 2 and WSL 1 using Windows Task Scheduler on Windows user logon
#!/bin/bash
# Start Linux daemons by starting WSL on user logon
#
# Usage:
# 1) Edit and save this bash shell script as /root/.bin/start-services.sh AND MAKE IT EXECUTABLE (chmod +x)
# (or wherever but remember to use the correct path in Scheduled task argumrents)
#
# 2) Set up a Windows Scheduled task to run this script via wsl.exe on user logon;
# Action - Start Program
@AndisGrossteins
AndisGrossteins / httpd.conf
Last active January 18, 2019 18:19
Custom Apache log format for better logging and reporting by @krader1961
# --- [SNIP] ---
# Special format by @krader1961
# His comment: I use a format that provides a human readable local time and a seconds since the UNIX epoch at UTC:
LogFormat "%{%Y-%m-%dT%H:%M:%S}t %{sec}t.%{usec_frac}t %>s %{error_notes}e %D %B %h %{Host}i \"%r\" \"%{Referer}i\" \"%{User-Agent}i\"" krader_custom
# I think I've removed and recreaed his original timestamp part (or something) because it caused my Apache to crash
### USAGE:
# In the global or vhost config...
# CustomLog "/var/log/apache2/krader_custom_access_%Y-%m-%d.log" krader_custom
@AndisGrossteins
AndisGrossteins / .htaccess
Last active October 11, 2019 01:54
A hack to log real IP addresses on share Apache hosting behind CloudFlare (or other) reverse proxy
# Set environment variables from request headers and add them to User-Agent header
# it's not much but it works
# Requirements:
# 1 - mod_setenvif (http://httpd.apache.org/docs/current/mod/mod_setenvif.html)
# 2 - mod_headers (http://httpd.apache.org/docs/current/mod/mod_headers.html)
<IfModule mod_setenvif.c>
# Add envirinment variables from a request header
SetEnvIf CF-Connecting-IP "^(.+)$" CF_Connecting_IP=$1
@AndisGrossteins
AndisGrossteins / iptables-multiport.conf
Last active May 22, 2021 19:53
*DEPRECATED CODE! Please read the replies before using this code or commenting* Updated correct fail2ban for permanent and persistent bans from https://wp.me/p5Ub2q-7w because WordPress.com comments suck for code snippets.
DEPRECATED CODE!!!!1!one!!1
Please read the replies before using this code or commenting!
For a better solution, use the fail2ban's persistence SQLite database with long purge time.
See this answer on Server Fault StackExchange: https://serverfault.com/a/810798/72732
[Definition]
# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
@AndisGrossteins
AndisGrossteins / image-allocate-memory.php
Last active June 30, 2018 17:44
Function to allocate memory for image processing with PHP in a smart way.
<?php
/**
* Dynamically allocate memory based on image dimensions, bit-depth and channels
* Shamelessly stolen somewhere online years ago.
* Probably from https://alvarotrigo.com/blog/allocate-memory-on-the-fly-PHP-image-resizing/
*
* @param string $filename Full path to a file supported by getimagesize() function
* @param int $tweak_factor Multiplier for tweaking required memory. 1.8 seems fine. More info: http://php.net/imagecreatefromjpeg#76968
* @param string $original_name Used purely for reporting actual file name instead of uploaded temp file (e.g. /tmp/RaNd0m.tmp)