Skip to content

Instantly share code, notes, and snippets.

@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)
@diversen
diversen / php-recaptcha.php
Last active Jul 14, 2020
php verify google recaptcha version 2
View php-recaptcha.php
<?php
/**
* Will make it work if server does not have
* allow_url_fopen
*/
function fileGetContentsCurl($url)
{
$ch = curl_init();
View wavesurfer.js
var samplePromise = require('get-audio-sample-promise');
var rand = require('random-float');
var waveSurfer = require('wavesurfer.js')
// let [foo, bar] = await Promise.all([getFoo(), getBar()]);
// let audiobuf = await samplePromise(ctx, 'raven.mp3');
function randomDoubleFromInterval(min, max){
return Math.random()*(max-min);
@diversen
diversen / battery.sh
Created Sep 24, 2017
shell script which show percentage of battery left
View battery.sh
#!/bin/sh
upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"
@diversen
diversen / serv.sh
Created Sep 23, 2017
Tiny bash wrapper around built-in PHP-server in order to serv current dir. Usage: Place in a global bin dir and run serv.sh
View serv.sh
#!/bin/sh
if [ -z "$1" ]
then
PORT=8080
fi
if [ "$1" ]
then
PORT=$1