Skip to content

Instantly share code, notes, and snippets.

View diversen's full-sized avatar

Dennis Iversen diversen

View GitHub Profile
@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) {
@diversen
diversen / php-recaptcha.php
Last active July 14, 2020 20:10
php verify google recaptcha version 2
<?php
/**
* Will make it work if server does not have
* allow_url_fopen
*/
function fileGetContentsCurl($url)
{
$ch = curl_init();
<?php
// Search CSV
$csv = './Debitorer.csv';
$result = [];
$i = 0;
if (($handle = fopen($csv, "r")) !== false) {
while (($data = fgetcsv($handle, 1000, ";")) !== false) {
$i++;
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)
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 September 24, 2017 14:30
shell script which show percentage of battery left
#!/bin/sh
upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"
@diversen
diversen / serv.sh
Created September 23, 2017 09:33
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
#!/bin/sh
if [ -z "$1" ]
then
PORT=8080
fi
if [ "$1" ]
then
PORT=$1
<?php
// composer require symfony/css-selector
// Easy to use CSS selectors on XML and HTML docs.
use Symfony\Component\CssSelector\CssSelectorConverter;
include_once "vendor/autoload.php";
// $xml = simplexml_load_file('test.xml');
@diversen
diversen / modify-bootstrap-button.php
Created June 29, 2017 08:15
Quick modify of bootstrap buttons using php
<?php
header('Content-type: text/css');
function buttonColor($class = '.myBtn' , $c = '#ffffff', $bg = '#0099cc', $cHover = '#C0C0C0', $bgHover = '#C0C0C0') {
$str = <<<EOF
$class {
background: $bg;
color: $c;