Skip to content

Instantly share code, notes, and snippets.

@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)) {
@RyanNutt
RyanNutt / ace_themes.php
Last active December 19, 2023 21:50
Ace Editor themes in a pair of PHP arrays :: https://www.nutt.net/ace-editor-syntax-highlighting-mode-list/
<?php
$ace_light = [
'chrome' => 'Chrome',
'clouds' => 'Clouds',
'crimson_editor' => 'Crimson Editor',
'dawn' => 'Dawn',
'dreamweaver' => 'Dreamweaver',
'eclipse' => 'Eclipse',
'github' => 'GitHub',
'iplastic' => 'IPlastic',
@RyanNutt
RyanNutt / github-classroom-travis-badge.js
Created November 15, 2019 14:04
Tapermonkey script to add Travis CI badges to GitHub Classroom
// ==UserScript==
// @name GitHub Classroom Badges
// @namespace https://compsci.rocks/
// @version 0.1
// @description Add Travis build badges to repos in GitHub Classroom
// @author Ryan Nutt
// @website https://compsci.rocks/
// @include /^https?://classroom\.github\.com/classrooms/(.*)?/(group-)?assignments/(.*)?
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
@RyanNutt
RyanNutt / jQ-window-opener.js
Created October 22, 2019 13:32
Needed a way to reference a form on the window that opened a JavaScript pop-up. This seems to work, although there's probably a better way.
<script type="text/javascript">
$(window.opener.document).find('[name="assignment-name"]').val('Hello, is this thing on?');
</script>
@RyanNutt
RyanNutt / nb-jquery-ajax.js
Last active October 19, 2019 14:35
NetBeans code template for jQuery Ajax call.
jQuery.ajax(url, {
method: 'POST',
data: {
},
beforeSend: function (xhr, settings) {
},
complete: function (xhr, status) {
},
@RyanNutt
RyanNutt / readme.md
Created August 1, 2019 21:20
Get a "web safe" color based on string contents in PHP

Get color for string in PHP

I've needed to do this a couple of times, so I guess it's time to save it as a Gist for next time.

What I needed was a way to calculate a color based on string contents, where the same string would always generate the same color. I also wanted the colors generated to be part of the web safe palette. Not that there's any reason to stay in that palette for browsers now, but I wanted to keep the possible palette relatively small and have colors that generally look okay together. The math behind the web safe palette made it pretty easy.

As it works out, all of the web safe colors are multiples of 51. We'll need that bit of trivia in a second...