Skip to content

Instantly share code, notes, and snippets.

@geekbrit
geekbrit / animation_scheduler.js
Created July 15, 2021 15:19
Animate elements in a web page by applying a sequence of timed additions/removals of classes to elements.
// Future enhancement, make animation steps arrays, to apply multiple simultaneous transitions to multiple elements
//
// animation elements:
// 0: number of tenths of a second after previous animation element
// 1: add or remove
// 2: classname
// 3: element identifier
//
const add = 1;
const remove = -1;
@geekbrit
geekbrit / backup_databases.sh
Created September 12, 2018 17:14
Backup all mysql databases, delete duplicate dump files
#!/bin/bash
databases=`mysql -h 127.0.0.1 -u root --batch --skip-column-names -e "SHOW DATABASES;" | grep -E -v "(information|performance)_schema"`
for db in $databases; do
echo "Dumping database: $db"
mysqldump -h 127.0.0.1 -u root --databases $db | head -n -1 > /root/Backups/`date +%d%H`.$db.sql
done
fdupes -rNdqio time /root/Backups
@geekbrit
geekbrit / build_page_twig.php
Last active June 2, 2018 17:48
This gist takes json generated by yakovlevga/brickyeditor and a set of templates in an html file, and munges everything together to create a static html (or twig) file. Follows containers down to correctly fill out the container content.
<?php
// method from a CMS object
function build_page_twig(){
libxml_use_internal_errors(TRUE); // this avoids errors thrown on HTML5 tags
//
// this section is cms-specific, could just pass in the json file name
@geekbrit
geekbrit / rr_watcher.sh
Created March 2, 2018 14:09
BASH Daemon to watch for new image files, correct any rotation and resize within max dimensions
#!/bin/sh
#
# create watches for each subfolder within the specified location (1 level deep)
# renames the uploaded files to avoid infinite loop
#
for d in $(find /home/peter/Dropbox/MiniDonkies/Donkeys -maxdepth 1 -type d)
do
(
if [ '/home/peter/Dropbox/MiniDonkies/Donkeys' != $d ]; then
echo "$d"
@geekbrit
geekbrit / dedupeAddresses.sql
Created August 9, 2016 15:54
MySQL Remove duplicate addresses, fix up tables that reference the missing duplicates
create temporary table good_address (
`idAddress` int(11) NOT NULL,
`first_name` varchar(45) NOT NULL,
`last_name` varchar(45) NOT NULL,
`company_name` varchar(45) NOT NULL,
`address_1` varchar(50) NOT NULL,
`address_2` varchar(50) DEFAULT NULL,
`city` varchar(45) NOT NULL,
`state` varchar(45) DEFAULT NULL,
`country` varchar(5) NOT NULL,
@geekbrit
geekbrit / ViewSetTimeout.js
Created March 11, 2016 14:59
View all Javascript setTimeout creation and fire events in the console window
window.originalSetTimeout = window.setTimeout;
window.setTimeout=function(func,delay) {
console.log("\n\nNew timer, delay:%s\nfunc:%s",delay, func);
return window.originalSetTimeout(function(e){console.log("\nTimerFired:%s",func);func(e)},delay);
};
@geekbrit
geekbrit / LazyPDO.php
Last active May 6, 2016 10:46
Lazy PDO - allows you to group all SQL in one file, and adds data accesses as services of the DB object. It is "Lazy" because accessors are prepared only when needed.
//
// Lazy PDO - register queries at startup, but only prepare them if they are actually used
//
class LPDO extends PDO
{
private $querystrings;
public function __set($property,$value)
{