Skip to content

Instantly share code, notes, and snippets.

Avatar

Kaspars Dambis kasparsd

View GitHub Profile
@kasparsd
kasparsd / uptime.sh
Last active Feb 9, 2021
Basic uptime monitor
View uptime.sh
#!/bin/bash
NOTIFY_FROM="no-reply@example.com"
NOTIFY_TO="hi@example.com"
URLS=(
"https://example.com"
"https://google.com"
)
View term-helper.php
<?php
/**
* Map all categories to the new category tree.
*
* - Create a list of new categories by their path of slugs.
*/
class Terms {
/**
View ad-manager.min.js
! function(s) {
function e(e) {
for (var t, n, r = e[0], i = e[1], a = 0, o = []; a < r.length; a++) n = r[a], Object.prototype.hasOwnProperty.call(d, n) && d[n] && o.push(d[n][0]), d[n] = 0;
for (t in i) Object.prototype.hasOwnProperty.call(i, t) && (s[t] = i[t]);
for (u && u(e); o.length;) o.shift()()
}
var n = {},
d = {
0: 0
};
View wp-list-widget-classes.php
<?php
add_action(
'widgets_init',
function() {
global $wp_widget_factory;
$widget_classes = array_map(
function ( $widget ) {
return get_class( $widget );
View virtualbox.rb
cask 'virtualbox' do
version '6.0.14,133895'
sha256 'ea3ebf2457908495128178f9b6676a77b120fa7878fd626d2baf0a8c45921370'
url "https://download.virtualbox.org/virtualbox/#{version.before_comma}/VirtualBox-#{version.before_comma}-#{version.after_comma}-OSX.dmg"
appcast 'https://download.virtualbox.org/virtualbox/LATEST.TXT'
name 'Oracle VirtualBox'
homepage 'https://www.virtualbox.org/'
conflicts_with cask: 'virtualbox-beta'
View mysql-5.7-upgrade.md

Updating to mysql-server-5.7 (5.7.28-0ubuntu0.18.04.4) on Ubuntu produces the following error:

mysql_upgrade: [ERROR] 1833: Cannot change column 'table_name': used in a foreign key constraint 'innodb_index_stats_ibfk_1' of table 'mysql.innodb_index_stats'

The update appears to be changing the varchar length of the table_name column:

Important Change; Partitioning: After creating partitioned InnoDB tables with very long names, the table_name columns in the corresponding entries in the mysql.innodb_index_stats and mysql.innodb_table_stats system tables were truncated. To fix this issue, the length of the table_name column in each of these tables has been increased from 64 to 199 characters. In both cases, this is now the same as the lengths of these columns in MySQL 8.0.

So I ended deleting that constraint:

@kasparsd
kasparsd / esp32-cam-pseudocode.js
Created Oct 12, 2019
Main logic behind a battery powered esp32 timelapse camera
View esp32-cam-pseudocode.js
onInteruptInterval( MINUTEINSECONDS, function() {
takePicture()
goToSleep()
} )
onInteruptInterval( DAYINSECONDS, function() {
connectWifi()
.then( () => uploadImages( getNewPhotos() ) )
.finally( () => disconnectWifi() )
@kasparsd
kasparsd / db-dump.sh
Last active Feb 15, 2019
Must-use plugin for WordPress plugin and theme demo sites
View db-dump.sh
#!/usr/bin/env bash
# Dump specific DB tables to a file.
mysqldump -u sqluser dbname wp_posts wp_postmeta > dump.sql
View wp-wishlist.md

My WordPress Development Wishlist

  • Standardize saving post meta attributes. The state of save_post is a mess. Is autosave, has nonce, has permissions, is cron, ir WP-API? See https://github.com/xwp/wp-safe-input

  • Introduce templating for building configuration screens in the admin. Probably as an abstraction over the Settings API that is actually friendlier and easier to use. Decouple data store from where and how the settings are presented to a user.

View icon-map.scss
$token-symbols: (
adx: '<svg xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><circle cx="16" cy="16" r="16" fill="#1B75BC"/><path fill="#FFF" d="M11.587 8.602L16 13.208l4.305-4.606L23 11.36 18.604 16 23 20.603l-2.695 2.793L16 18.792l-4.413 4.604L9 20.68l4.36-4.706L9 11.36l2.587-2.757zm.355-.376L15.982 4l4.04 4.226-2.126 2.265-1.914-2.114-1.914 2.114-2.126-2.265zm0 15.548l2.126-2.265 1.914 2.114 1.914-2.114 2.126 2.265L15.982 28l-4.04-4.226z"/></g></svg>',
ae: '<svg xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><circle cx="16" cy="16" r="16" fill="#DE3F6B"/><path fill="#FFF" fill-rule="nonzero" d="M9.752 11h.904c1.413.134 2.72.821 3.687 1.81 2.009 2.039 3.113 4.916 5.67 6.433 1.848 1.097 4.433.2 5.341-1.654.462-.008.927-.008 1.389-.006-.636 1.883-2.489 3.236-4.515 3.417h-.746c-1.247-.1-2.46-.564-3.403-1.366-1.37-1.123-2.25-2.664-3.315-4.036-.916-1.213-1.85-2.577-3.366-3.128-1.873-.679-4.16.383-4.843 2.187-.6 1.486-.112 3.328 1.23 4.28 1.006.752 2.407 1.033 3.615.