Skip to content

Instantly share code, notes, and snippets.

@roydejong
roydejong / gitlab2nas.php
Last active February 12, 2024 03:10
Script: Backup all GitLab repositories to Synology NAS
<?php
// This script will back up all your GitLab repositories to a specified location.
// I recommend creating a seperate GitLab user for backups.
// You'll need to generate a personal access token for that user with API access (in GitLab).
// Next, generate a SSH keypair for the NAS user and attach it to the GitLab user.
// Finally, create a scheduled task in your NAS config to run this script: "php /some/location/git2nas.php"
// Config -- start
@roydejong
roydejong / eu_codes.php
Created May 23, 2017 13:12
PHP: Array of EU ISO country codes (may 2017)
$codeList = [
"BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY",
"LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI",
"SE", "UK"
];
@roydejong
roydejong / map_country_to_continent.php
Created May 23, 2017 13:14
PHP: Array mapping country ISO codes to continent codes
$mapCountryToContinent = array(
"AF" => "AS",
"AX" => "EU",
"AL" => "EU",
"DZ" => "AF",
"AS" => "OC",
"AD" => "EU",
"AO" => "AF",
"AI" => "NA",
"AQ" => "AN",
@roydejong
roydejong / pouchdb-create-or-update-merge.js
Last active July 4, 2017 14:02
PouchDB: Add or update record (sync / merge)
static addOrUpdate(id, document) {
return new Promise(function (resolve, reject) {
let doStore = function (originalDocument) {
// Merge the document: First, set the ID. Then apply the existing doc on top if possible. Finally, apply the changed doc.
let mergedDoc = {
_id: id
};
if (originalDocument) {
for (let key in originalDocument) {
@roydejong
roydejong / wkhtmltopdf-setup-with-xvfb-and-php.md
Last active May 25, 2023 13:38
Set up wkhtmltopdf 0.12.6 on Ubuntu server + xvfb runtime + PHP integration

1. Install wkhtmltopdf

Find the download URL for the latest binary from the official Downloads page.

At the time of writing, this is v0.12.6, which was released on June 11, 2020.

Download the binary, and then install the package and its dependencies. For example:

wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
@roydejong
roydejong / floatval-locale-guess.php
Last active May 1, 2022 19:38
PHP: Parse raw input as a float, with best guess for the decimal character (dot or comma). Useful if you do not know original locale or when you are processing user input.
<?php
function parseFloatGuess($rawValue) {
if (!$rawValue) {
return 0;
}
$lastCommaPosition = strrpos($rawValue, ',');
$lastDotPosition = strrpos($rawValue, '.');
@roydejong
roydejong / NativeWinAlert.cs
Last active March 31, 2024 15:53
Unity: NativeWinAlert (Windows MessageBox / Alert Dialog for Unity games)
using System;
using System.Runtime.InteropServices;
/// <see>https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-messagebox</see>
public static class NativeWinAlert
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern System.IntPtr GetActiveWindow();
public static System.IntPtr GetWindowHandle()
@roydejong
roydejong / UnityDiscordRPCDebugLogger.cs
Last active January 7, 2019 05:47
Unity: Debug logger class for the DiscordRPC C# Wrapper Library
using DiscordRPC.Logging;
using System;
using UnityEngine;
public class DiscordDebugLogger : DiscordRPC.Logging.ILogger
{
/// <summary>
/// The level of logging to apply to this logger.
/// </summary>
public LogLevel Level { get; set; }
@roydejong
roydejong / is_touch_device.js
Created January 7, 2019 03:16
JavaScript: Detect touch device (react compatible)
function is_touch_device() {
try {
let prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
let mq = function (query) {
return window.matchMedia(query).matches;
};
if (('ontouchstart' in window) || (typeof window.DocumentTouch !== "undefined" && document instanceof window.DocumentTouch)) {
return true;
@roydejong
roydejong / progrids-install.md
Last active September 13, 2023 14:06
Installing ProGrids v3 in Unity 2018.3

The problem

ProGrids seems to have disappeared from the Unity Package Manager as of Unity 2018.3.

It is possible to install ProGrids v2 via the Asset Store, but it's an old and incompatible version.

The solution (new)

Per Sayama3:

In 2021, you still can use it but it's different :

  • Go to the Package Manager