Skip to content

Instantly share code, notes, and snippets.

View rikmeijer's full-sized avatar

Rik Meijer rikmeijer

View GitHub Profile
npub1efz8l77esdtpw6l359sjvakm7azvyv6mkuxphjdk3vfzkgxkatrqlpf9s4
@rikmeijer
rikmeijer / Application.php
Last active February 22, 2024 15:12
Potential fix for #nextcloud/social/issues/1864
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
@rikmeijer
rikmeijer / security.sql
Created January 26, 2021 15:23
Create webdav with mysql authentication and bcrypt encryption
CREATE TABLE users (
username VARCHAR(255) NOT NULL,
password VARCHART(255) NOT NULL, -- bcrypt, column width is not optimized
realm VARCHAR(255) NOT NULL DEFAULT 'rikmeijer.nl',
PRIMARY KEY (username),
UNIQUE (username, realm)
);
@rikmeijer
rikmeijer / mysql
Created June 29, 2020 08:07
Daily mysql cron dumping all tables, except for information_schema. Writing backups to /var/backups/mysql.
#!/bin/sh
/usr/bin/find /var/backups/mysql/* -mtime +7 -exec rm {} \;
for DB in $(mysql -e 'show databases' -s --skip-column-names); do
if [ "$DB" = "information_schema" ]
then
echo Skipping $DB
continue
fi
echo -n Dumping $DB...
/usr/bin/mysqldump --add-drop-database --add-drop-table --single-transaction --routines --triggers $DB | gzip > "/var/backups/mysql/$DB-$(date '+%Y%m%e').sql.gz";
c4820dc0c242e7456a1e31ca466c815829bc85235eed13c708f20d961d1fec7ecc039aaa4ade427cf46352702ef3147c1be546fc46a3e9aa7d4e690ae178dd18
@rikmeijer
rikmeijer / Main.java
Created May 15, 2019 09:18
PROG4_Wk4b
package PROG4_WK4b;
import javafx.application.Application;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@rikmeijer
rikmeijer / Main.java
Created May 8, 2019 09:37
PROG4_Wk3b
package PROG4_WK3b;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
@rikmeijer
rikmeijer / gphotos-hq.php
Created April 15, 2019 13:08
Script to find photos/videos larger than 16MP/1080p (scale candidates when converting to Google Photos HQ)
<?php
/**
* @param $bytes
* @param int $decimals
* @return string
*/
function human_filesize($bytes, $decimals = 2) {
$sz = ['B','K','M','G','T','P'];
$factor = min(count($sz), floor((strlen($bytes) - 1) / 3));
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sz[$factor];
@rikmeijer
rikmeijer / console.php
Created March 28, 2019 13:22
Functional console IO
<?php
function console() : Closure {
$prompt = function(string $line) : Closure {
$genericDefault = function(string $default = null) {
return function(string $answer) use ($default) {
if (empty($answer)) {
return $default;
} else {
return $answer;
}
@rikmeijer
rikmeijer / rf.php
Created March 27, 2019 19:37
function to create a recursable closure
<?php
function rf(Closure $f) {
return new class($f) {
private $f;
public function __construct(Closure $f)
{
$this->f = $f;
}
public function __invoke() {