Skip to content

Instantly share code, notes, and snippets.

@diversen
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 https://github.com/pypa/virtualenv/archive/refs/tags/16.7.10.tar.gz -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/virtualenv.py'" >> ~/.bashrc
echo 'Now run: source ~/.bashrc'
@diversen
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
<?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
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
<?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
diversen / docker-mysql-5.7-guide.md
Created Oct 24, 2021
Docker and MySQL - small guide
View docker-mysql-5.7-guide.md

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
diversen / install-php-composer.sh
Created Jul 15, 2021
install composer (allow_url_fopen)
View install-php-composer.sh
#!/bin/sh
# This installs when allow_url_fopen is Off (in most cases)
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -d allow_url_fopen=1 -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
@diversen
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
<?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
diversen / backup-wordpress-single-file.sh
Last active Jul 5, 2021
Single file wordpress backup script using rsync and mysqldump
View backup-wordpress-single-file.sh
#!/usr/bin/env php
<?php
/**
* Wordpress backup without any configuration
*
* USAGE:
*
* ./wordpress-backup.php path/to/basepath/of/wordpress/
*
View search_csv.php
<?php
// Search CSV
$csv = './Debitorer.csv';
$result = [];
$i = 0;
if (($handle = fopen($csv, "r")) !== false) {
while (($data = fgetcsv($handle, 1000, ";")) !== false) {
$i++;
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()
console.log(scales)
const testScale = 'C major'
const major = Scale.notes(testScale)
const intervals = Scale.intervals(testScale)