Skip to content

Instantly share code, notes, and snippets.

diversen / install-virtualenv
Last active Feb 23, 2022
Install virtualenv locally without pip or being root or doing sudo
View install-virtualenv
# This works with e.g. python 3.7
wget -O virtualenv-16.7.10.tar.gz
tar xvfz virtualenv-16.7.10.tar.gz
rm virtualenv-16.7.10.tar.gz
mv virtualenv-16.7.10 ~/.virtualenv
echo >> ~/.bashrc
echo "alias virtualenv='python $HOME/.virtualenv/'" >> ~/.bashrc
echo 'Now run: source ~/.bashrc'
diversen / wordpress-backup-from-web.php
Last active Apr 4, 2022
Wordpress backup if you don't have SSH access but you can use mysqldump and tar
View wordpress-backup-from-web.php
// Read database configuration
include_once "wp-config.php";
// Default database
// $database = $databases['default']['default'];
$database['host'] = DB_HOST;
$database['user'] = DB_USER;
$database['pass'] = DB_PASSWORD;
diversen / drupal7-backup.php
Last active Apr 5, 2022
Druapl 7 backup if you don't have SSH access but you can use mysqldump and tar
View drupal7-backup.php
* Druapl 7 backup if you don't have SSH access but you can use mysqldump and tar
* Put this in the sites root folder and visit the script through a browser
* Fetch asdqwe-backup.sql from the server
* Fetch asdqwe-backup.tar.gz from the server
diversen /
Created Oct 24, 2021
Docker and MySQL - small guide

Docker MySQL

Install (run) a MySQL image that will work:

docker run -p 3306:3306 --name mysql-server -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7

Connect using bash and create a database:

docker exec -it mysql-server bash

mysql -uroot -ppassword

diversen /
Created Jul 15, 2021
install composer (allow_url_fopen)
# This installs when allow_url_fopen is Off (in most cases)
php -d allow_url_fopen=1 -r "copy('', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
diversen / rearrange-upload-files.php
Last active Jun 16, 2021
Snippet / function that rearrange php files when doing file uploads
View rearrange-upload-files.php
* Takes the input file element name, e.g. `$files = rearrange_files($_FILES['files']);`
* If you have a file input like this `<input type="file" name="files[]" multiple >`
* Will return an array where each element is a single file. Much more convenient thant
* Using the PHP $_FILES array
function rearrange_files($file_post) {
diversen /
Last active Jul 5, 2021
Single file wordpress backup script using rsync and mysqldump
#!/usr/bin/env php
* Wordpress backup without any configuration
* ./wordpress-backup.php path/to/basepath/of/wordpress/
View search_csv.php
// Search CSV
$csv = './Debitorer.csv';
$result = [];
$i = 0;
if (($handle = fopen($csv, "r")) !== false) {
while (($data = fgetcsv($handle, 1000, ";")) !== false) {
View non-bloated-cookie-consent.html
View Tonal test
const Tonal = require("tonal");
const Scale = Tonal.Scale
const Note = Tonal.Note
const scales = Scale.names()
const testScale = 'C major'
const major = Scale.notes(testScale)
const intervals = Scale.intervals(testScale)