Skip to content

Instantly share code, notes, and snippets.

View benjamin-dk's full-sized avatar

Benjamin Christensen benjamin-dk

  • Aarhus Universitetshospital
View GitHub Profile
@benjamin-dk
benjamin-dk / php
Created September 11, 2024 10:08
Drupal 10 - persisting values in forms when validation fails (SimpleForm.php from the Examples module)
<?php
namespace Drupal\form_api_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements the SimpleForm form controller.
*
@benjamin-dk
benjamin-dk / delete_dir.php
Last active June 22, 2017 08:21
How to delete directory with PHP on FreeBSD
<?php
/* Its been a while since I used this so please use at your own risk */
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
@benjamin-dk
benjamin-dk / set_locale.sh
Created September 19, 2016 09:42
Fix perl locale issue on ubuntu 14.04
#!/bin/bash
# credits: https://jee-appy.blogspot.dk/2016/02/set-locale-on-ubuntu-permanent-solution.html
# Set locales in /etc/default/locale file
echo "Setting locale..."
echo "# Locale settings
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile
@benjamin-dk
benjamin-dk / setup_letsencrypt_domain.sh
Last active May 25, 2016 10:54
Setup Letsencrypt SSL for domain on Virtualmin GPL server setup
# Warning: use this script at your own risk - work in progress. Tested on Ubuntu 14.04 server.
# Note: Now that the letsencrypt feature is in place in Virtualmin, this script is obsolete.
# Before running the script, be sure to have Letsencrypt installed in /opt/ as descripted in the guide below:
# https://www.virtualmin.com/node/38853
# Running Drupal on the site? Remember to adjust .htaccess as described in the link below:
# https://community.letsencrypt.org/t/drupals-defualt-htaccess-file-breaks-webroot-authentication/3014
# Other resources:
# https://joealdeguer.com/how-to-install-and-setup-letsencrypt-for-virtualmin/
@benjamin-dk
benjamin-dk / fix-htaccess.sh
Last active November 10, 2015 08:37
Fix default Drupal .htaccess settings to comply with new Apache (2.4) standards
#!/bin/bash
# Searches the current working directory recursively and replaces old symlink-setting with the new
read -p "This script should be run from the Drupal root folder to work properly. Is this our current location?" -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
curdir=$(pwd)
@benjamin-dk
benjamin-dk / wp.sh
Last active August 29, 2015 14:13 — forked from bgallagh3r/wp.sh
Wordpress installation script, customized for FreeBSD
#!/bin/sh
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Database Name: "
read -e dbname
echo "Database User: "
read -e dbuser
echo "Database Password: "
@benjamin-dk
benjamin-dk / prefix-dcx.php
Created January 14, 2015 23:44
Add prefix to MYSQL tables
<?php
/**
* MySQL Table Prefix Changer DXC Version
* By deuxcode.com
* Version 10.6.3
*
* This is a modified version of R.Dunham's script. Original details below.
*
* New in this version:
* Possibility to specify current prefix which gives us the power to
@benjamin-dk
benjamin-dk / wordpress_setup.sh
Last active August 29, 2015 13:57
Wordpress site setup
#!/bin/bash
#
# By http://www.rosehosting.com/blog/script-install-wordpress-on-a-debianubuntu-vps/
# Install WordPress on a Debian/Ubuntu VPS
#
 
# Create MySQL database
read -p "Enter your MySQL root password: " rootpass
read -p "Database name: " dbname
read -p "Database username: " dbuser
@benjamin-dk
benjamin-dk / Wordpress permissions
Last active March 7, 2023 18:52
Script for setting up correct Wordpress permissions by Mike Conigliaro http://www.conigliaro.org/2010/05/06/script-to-configure-proper-wordpress-permissions/
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=changeme # <-- wordpress owner
WP_GROUP=changeme # <-- wordpress group
WP_ROOT=/home/changeme # <-- wordpress root directory
@benjamin-dk
benjamin-dk / setup_vhost.sh
Last active December 18, 2015 01:29
Linux bash script for setting up a virtual host on an Apache web server
#! /bin/bash
#
# =======================
# Siteup Script 0.1
# Written by Command Line Idiot
# http://commandlineidiot.com
# You may use, modify, and redistribute this script freely
# Released: August 2007
# =======================