Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Nutt RyanNutt

View GitHub Profile
@RyanNutt
RyanNutt / disable-scaled-images.php
Created May 26, 2020
WordPress plugin to turn off auto creation of scaled images
View disable-scaled-images.php
<?php
/**
* Plugin Name: Disable Scaled Images
* Plugin URI: https://www.nutt.net
* Description: One liner to turn off automatic scaled image creation for large images
* Version: 0.1.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Ryan Nutt
* Author URI: https://www.nutt.net
@RyanNutt
RyanNutt / download_videos.py
Last active Mar 2, 2020
Script to download media submissions from Canvas assignment
View download_videos.py
import json
import urllib.request
import sys
with open('submissions.json', 'r') as read_file:
data = json.load(read_file)
for sub in data:
filename = sub['user']['name'] + '.mpg4'
print(filename)
@RyanNutt
RyanNutt / readme.md
Created Feb 28, 2020
Update docker clock
View readme.md

Update Docker Clock

I switched to Docker from Virtual Box as a local web development environment a few months ago and find it much easier to work with. Except for one issue.

What I've found is that if a Docker container is running when my computer goes to sleep the clock stops and the container falls behind by however long my computer was asleep. Since the container is supposed to be in sync with my computer there didn't seem to be an easy way to update the container's clock. Lots of work arounds, but nothing quick and easy. And I couldn't find anything that worked without stopping the container first.

Stack Overflow to the rescue. I found this one liner that does exactly what I needed.

docker run --rm --privileged alpine hwclock -s
View .htaccess
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301,L]
@RyanNutt
RyanNutt / moveToTop.js
Created Jan 29, 2020
jQuery plugin to move elements to top or bottom of parent
View moveToTop.js
/**
* Move an element to the top of the stack by appending it to the end
* of its parent.
*
* The element, and its siblings, should be positioned in parent so that
* they're stacked on top of each other.
*/
(function ($) {
$.fn.moveToBottom = function () {
return this.parent().prepend(this);
@RyanNutt
RyanNutt / PostTransient.php
Last active Jan 26, 2020
Class for WordPress to store transient data with a post:: https://www.nutt.net/wordpress-posttransient-class/
View PostTransient.php
<?php
// This software is copyright 2020 Ryan Nutt - https://www.nutt.net
//
// This software is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@RyanNutt
RyanNutt / plugin.php
Created Jan 10, 2020
WordPress plugin starter with heading
View plugin.php
<?php
/**
* Plugin Name: Plugin Name
* Plugin URI: https://...
* Description: Description
* Version: 0.1.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Name
* Author URI: https://...
View Gruntfile.js
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
opts: {
/* Filename of the compiled JavaScript file */
jsName: 'project',
/* Filename of the compiled CSS file */
cssName: 'style',
companyName: 'Company Name',
@RyanNutt
RyanNutt / git-socks-proxy.md
Last active Dec 3, 2019
Needed to git push over an SSH tunnel
View git-socks-proxy.md

Going to leave this here for next time I need to push or pull to a git repo that's blocked on a network. In my case it was a self hosted Gitlab server.

I've got an SSH tunnel setup through PuTTY running on port 1234. Run this before pushing.

git config http.proxy 'socks5://127.0.0.1:1234'

And then this after to turn it back off.

View enqueue_if_hs_block.php
<?php
add_action('wp_enqueue_scripts', 'enqueue_if_has_block');
function enqueue_if_has_block() {
$block_name = 'some/block';
global $wp_query;
$post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
$has_block = false;
foreach ($post_ids as $id) {
if (has_block($block_name, $id)) {
You can’t perform that action at this time.