Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
RyanNutt / embed.html
Created October 20, 2015 15:36
Needed a way to embed a Gist in an Instructure Canvas page. Just paste this into when in HTML editing mode and switch out the address with your gist. CSS came from http://www.bymichaellancaster.com/blog/fluid-iframe-and-images-without-javascript-plugins/
<p style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;">
<iframe style="position: absolute; top: 0; height: 100%; width: 100%;" src="https://gist.github.com/RyanNutt/905983e76c20cf3177b7.pibb" width="300" height="150">
</iframe>
</p>
@RyanNutt
RyanNutt / download_videos.py
Last active March 2, 2020 19:06
Script to download media submissions from Canvas assignment
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 February 28, 2020 14:11
Update docker clock

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
@RyanNutt
RyanNutt / .htaccess
Created February 24, 2020 19:13
Redirect old domain to new domain root - https://stackoverflow.com/a/7578810/1561431
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301,L]
@RyanNutt
RyanNutt / moveToTop.js
Created January 29, 2020 17:06
jQuery plugin to move elements to top or bottom of parent
/**
* 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 January 26, 2020 23:16
Class for WordPress to store transient data with a post:: https://www.nutt.net/wordpress-posttransient-class/
<?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 January 10, 2020 17:07
WordPress plugin starter with heading
<?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://...
@RyanNutt
RyanNutt / Gruntfile.js
Last active January 10, 2020 14:45
Base Gruntfile for WordPress plugins - https://www.nutt.net/wordpress-gruntfile-template/
'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 December 3, 2019 16:26
Needed to git push over an SSH tunnel

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.

<?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)) {