Skip to content

Instantly share code, notes, and snippets.

View interactiveRob's full-sized avatar

Rob Kirkner interactiveRob

View GitHub Profile
@interactiveRob
interactiveRob / php-sanitize-phone-number.php
Last active January 22, 2020 02:47
PHP sanitize phone number
<?php
//add +1 (USA country code) for international callers, only allow digits through
$tel_link = 'tel:+1' . preg_replace('/\D/', '', $intro_phone_number);
//for UI output replace all kinds of dashes with non-breaking dash
$intro_phone_number_text = preg_replace('/[-–—]/', '&#x2011;', $intro_phone_number);
@interactiveRob
interactiveRob / ffmpeg-mp4-to-webm.sh
Created January 1, 2020 22:42
FFmpeg mp4 to webm
ffmpeg -i source-video.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis destination-video.webm
@interactiveRob
interactiveRob / detectExceedsViewport.js
Last active February 7, 2021 00:04
Detect elements that are off the edge of the viewport
let allElements = document.querySelectorAll("body *");
let allElementsArray = Array.prototype.slice.call(allElements);
let widerThan = allElementsArray.filter(function(element) {
let elWidth = element.clientWidth;
return elWidth > window.innerWidth;
});
let offRight = allElementsArray.filter(function(element) {
let boundingBox = element.getBoundingClientRect();
@interactiveRob
interactiveRob / wordpress-state-location-sort.php
Created December 16, 2019 16:55
Wordpress Group and Sort Location Posts by U.S. State
<?php
$context['posts'] = new Timber\PostQuery([
'posts_per_page' => -1,
'post_type' => 'locations',
'post_status' => 'publish',
'order' => 'ASC',
]);
//map out the ACF data per post
$locations_data = array_map(function($location){
@interactiveRob
interactiveRob / wordpress-generate-save-zip.php
Last active December 9, 2019 21:33
Wordpress Generate a zip from several files on post update and save it to the media library
<?php
function rk_save_zip_to_wp_uploads($path, $file_name){
//handles file db entry for zip visibility in Media Library
$wordpress_upload_dir = wp_upload_dir();
$path_to_file = $wordpress_upload_dir['basedir'] . '/' . $file_name;
$mime_type = mime_content_type($path);
if(file_exists($path_to_file)){
$attachment_url = get_option('siteurl') . '/wp-content/uploads/' . $file_name;
@interactiveRob
interactiveRob / generate-assets-zip.php
Created November 28, 2019 00:55
PHP zip all files of a certain type (exclude node_modules)
<?php
$zip_file = 'package.zip';
// Get real path for our folder
// Initialize archive object
$zip = new ZipArchive();
@interactiveRob
interactiveRob / error-display-enable.php
Created November 28, 2019 00:45
PHP print all errors on page right meow
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
@interactiveRob
interactiveRob / HoverTransferES6.js
Last active November 25, 2019 21:33
Transfer hover from one element to another with vanilla JS (ES6 Module)
let HoverTransfer = (({}) => {
class HoverTransfer {
constructor(node, options = {}) {
this.node = node;
this.targetSelector = `[data-hover-id="${this.node.dataset.hoverTarget}"]`;
this.target = document.querySelector(this.targetSelector);
this.activeClass = 'js-is-hovered';
}
toggleHover(){
@interactiveRob
interactiveRob / wordpress_SQL_select.sql
Created November 25, 2019 19:10
Select all image related metadata Wordpres
SELECT * FROM `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes', '_wp_attachment_metadata', '_thumbnail_id')
@interactiveRob
interactiveRob / public-google-calendar-embed.html
Last active November 23, 2019 16:01
Public Google Calendar embed with all National Days of (e.g. National Cupcake day)
<iframe src="https://calendar.google.com/calendar/embed?height=600&amp;wkst=1&amp;bgcolor=%23ffffff&amp;ctz=America%2FNew_York&amp;src=OXU4anFwM2hsdDZwZTY3NWdpZTZsZjFkOW9AZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ&amp;color=%2322AA99&amp;mode=AGENDA" style="border-width:0" width="800" height="600" frameborder="0" scrolling="no"></iframe>