Skip to content

Instantly share code, notes, and snippets.

View diversen's full-sized avatar

Dennis Iversen diversen

View GitHub Profile
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@diversen
diversen / print_primitive_values.html
Created April 18, 2023 08:01
jinja2 recusive print dict
{% macro print_primitive_values(data) %}
{% if data is mapping %}
{% for key, value in data.items() %}
{% if value is mapping or value is iterable %}
<strong>{{ key }}</strong>: {{ print_primitive_values(value) }}
{% else %}
<strong>{{ key }}</strong>: {{ value }}
{% endif %}
{% endfor %}
{% elif data is iterable and data is not string %}
// Mathematics. The problem of Hannibal's organs
// https://twitter.com/pickover/status/1618030222246580224
let JAR = []
let BRAIN = 0
let KIDNEY = 1
// Random add a brain or a kidney
function init() {
JAR = []
@diversen
diversen / drupal7-backup.php
Last active April 5, 2022 07:48
Druapl 7 backup if you don't have SSH access but you can use mysqldump and tar
<?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 / wordpress-backup-from-web.php
Last active April 4, 2022 12:42
Wordpress backup if you don't have SSH access but you can use mysqldump and tar
<?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 / install-virtualenv
Last active February 23, 2022 08:18
Install virtualenv locally without pip or being root or doing sudo
# 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 / docker-mysql-5.7-guide.md
Created October 24, 2021 08:18
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
diversen / install-php-composer.sh
Created July 15, 2021 09:11
install composer (allow_url_fopen)
#!/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 / backup-wordpress-single-file.sh
Last active July 5, 2021 10:38
Single file wordpress backup script using rsync and mysqldump
#!/usr/bin/env php
<?php
/**
* Wordpress backup without any configuration
*
* USAGE:
*
* ./wordpress-backup.php path/to/basepath/of/wordpress/
*
@diversen
diversen / rearrange-upload-files.php
Last active June 16, 2021 08:40
Snippet / function that rearrange php files when doing file uploads
<?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) {