Skip to content

Instantly share code, notes, and snippets.

View danieleambrosino's full-sized avatar

Daniele Ambrosino danieleambrosino

View GitHub Profile
@danieleambrosino
danieleambrosino / sqlitebackup
Created May 23, 2023 08:12
Simple bash script to backup a SQLite database
#!/bin/bash
# Check if source database and destination directory are provided as command line parameters
if [ $# -ne 2 ]; then
echo "Usage: $0 <source_database> <destination_directory>"
exit 1
fi
# Get the source database and destination directory from command line parameters
source_db="$1"
@danieleambrosino
danieleambrosino / searchable-table.js
Last active May 15, 2023 16:46
Simple JavaScript function to enable full text search on a table
/**
* @param {HTMLTableElement} table
*/
export default function searchable(table) {
/** @type {Map<HTMLTableRowElement, string>} */
const map = new Map(Array.from(table.tBodies[0].rows).map((row) => [row, row.innerText.trim().replace(/\s+/g, ' ')]));
const input = document.createElement("input");
input.type = "text";
input.placeholder = "Cerca...";
input.addEventListener("input", () => {
@danieleambrosino
danieleambrosino / automagic-scene-switcher.lua
Last active January 19, 2023 03:29
Simple Lua script for switching scene automatically in OBS
local settings = {
active = false,
main_scene_index = 1,
main_scene_probability = 0.75,
main_scene_min_duration_ms = 3000,
main_scene_max_duration_ms = 5000,
secondary_scene_min_duration_ms = 2000,
secondary_scene_max_duration_ms = 3000,
}
@danieleambrosino
danieleambrosino / array_transpose.php
Created May 29, 2022 13:25
Utility function to transpose a 2-dimensional matrix implemented with a PHP array
<?php
function array_transpose(array $array): array
{
$keys = array_keys($array);
return array_map(
fn ($row) => array_combine($keys, $row),
array_map(
null,
...array_values($array),