Skip to content

Instantly share code, notes, and snippets.

@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 / hide-cursor.css
Created April 28, 2018 01:00
Hide Ace editor cursor when editor is not active
.ace_hidden-cursors {
opacity:0
}
// As a function
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// One liner
await new Promise(r => setTimeout(r, 2000));
// Or
const sleep = ms => new Promise(r => setTimeout(r, ms));
@RyanNutt
RyanNutt / is_odd.py
Created November 20, 2021 20:28
Recursive is_odd. Not something to actually use, but will probably talk about this in class as an example for recursion. https://www.reddit.com/r/ProgrammerHumor/comments/qyb5ut/odd/
def is_odd(num):
if k == 1:
return True
elif k == 0:
return False
elif (num < 0):
return is_odd(num * -1)
else:
return is_odd(num - 2)
@RyanNutt
RyanNutt / permutations.php
Created July 4, 2021 14:23
Get all permutations of an array in PHP - from https://stackoverflow.com/a/24517966/1561431
<?php
function computePermutations($array) {
$result = [];
$recurse = function($array, $start_i = 0) use (&$result, &$recurse) {
if ($start_i === count($array)-1) {
array_push($result, $array);
}
for ($i = $start_i; $i < count($array); $i++) {
@RyanNutt
RyanNutt / pin_it.js
Created November 1, 2014 19:46
Pin to Pinterest from command line with node
var PinIt = require('pin-it-node');
var pinIt = new PinIt({
username: 'your_pinterest_username',
password: 'your_pinterest_password'
});
var settings = {
boardId: 'Numeric_board_id',
url: process.argv[2],
@RyanNutt
RyanNutt / jquery.showif.js
Created December 18, 2020 15:40
jQuery showIf / hideIf plugin
(function ($) {
$.fn.showIf = function (check) {
if (check) {
$(this).show();
}
else {
$(this).hide();
}
};
@RyanNutt
RyanNutt / isBase64.js
Created June 16, 2017 14:53
Check if a String is base64 encoded using JavaScript - from https://stackoverflow.com/a/34068497/1561431
function isBase64(str) {
try {
return btoa(atob(str)) == str;
} catch (err) {
return false;
}
}
@RyanNutt
RyanNutt / test_example.py
Created September 20, 2020 14:43
Python unittest starter stub
import unittest
class TestClass(unittest.TestCase):
def test(self):
exp = 4
actual = 4
self.assertEqual(exp, actual, 'Some Message')
@RyanNutt
RyanNutt / disable-scaled-images.php
Created May 26, 2020 20:30
WordPress plugin to turn off auto creation of scaled images
<?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