Skip to content

Instantly share code, notes, and snippets.

View full-sized avatar
🍕
Need fuel

Dan Jones goodevilgenius

🍕
Need fuel
View GitHub Profile
@goodevilgenius
goodevilgenius / ternary.go
Created September 25, 2023 11:20
A ternary function for go, because why doesn't it already have it?
View ternary.go
func Tern[V any](choice bool, one, two V) V {
if choice {
return one
}
return two
}
@goodevilgenius
goodevilgenius / empty-yt-playlist.js
Created August 24, 2023 18:00
Empty a YouTube playlist
View empty-yt-playlist.js
function clickRemove() {
const button = [...document.querySelectorAll('.yt-formatted-string')].find(el => el.innerText === 'Remove from ');
if (!button) {
console.log("Can't find remove button");
return;
}
button.click();
setTimeout(emptyList, 1);
}
@goodevilgenius
goodevilgenius / promise-queryable.js
Created August 21, 2023 15:16
A javascript promise that can tell you if it's been fulfilled.
View promise-queryable.js
Promise.prototype.getQueryable = function () {
if (this.isFulfilled) return this;
let isPending = true;
let isRejected = false;
let isFulfilled = false;
let value = undefined;
let error = undefined;
let result = this.then(v => {
@goodevilgenius
goodevilgenius / spy.php
Last active September 2, 2021 21:27
Class to access private/protected methods/properties without Reflections. Requires PHP 8 (could be rewritten to support 7)
View spy.php
<?php
/**
* Method for accessing private/protected properties/methods without Reflection.
*
* This is particularly useful when debugging from the command-line, for example, with psysh.
*
* Static methods/properties can be accessed by passing the class instead.
* Constants are not acccessible.
*
View OwnsMany.php
<?php declare(strict_types=1);
namespace App\Models\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Jenssegers\Mongodb\Relations\BelongsToMany;
/**
View william_fing_shatner.md

Wil Wheaton's Geek in Review: WILLIAM FUCKING SHATNER

Originally published on Sucide Girls in two parts (1 and 2). Currently accessible via archive.org at Part 1 and Part 2. This version only removed the intro to the Second Part

If you're a longtime reader of my blog, you know that I refer to the first bald captain of the Enterprise as WILLIAM FUCKING SHATNER. The origin of this charming name was first published in my book Dancing Barefoot.

Because my "Star Trek: The Experience" story from Barefoot received such a positive response back in January

@goodevilgenius
goodevilgenius / dl_json.js
Last active September 24, 2021 18:50
[Download JSON] Force browser to download a JavaScript object as a JSON file, using jQuery, or VanillaJS #webdev #browser #javascript
View dl_json.js
/* global $, data */
// data should be the object/array/etc to be JSON-ified.
// First, with jQuery
var $el = $('<a>');
$(document.body).append($el);
// If data is a jQuery selector, then do data = data.toArray()
@goodevilgenius
goodevilgenius / HangoutsOnAir.md
Last active October 26, 2017 13:53
[Hangouts On Air: HowTo] Instructions for using Hangouts on Air, as well as downloading the YouTube video (to perhaps use elsewhere) #video #media #tutorial
View HangoutsOnAir.md

First, go to ["My Live Events][1] on YouTube. Creating a new live event, or, if you want to record now, simply "Go Live Now".

Schedule a New Event

Fill in the information for your event, and press "Create Event". Make sure to choose "Unlisted" if you don't want it publicly available. It will still be accessible to anyone with the link.

Create Event

At the schedule time, go back to ["My Live Events"][1], press "Start Hangout on Air"

@goodevilgenius
goodevilgenius / notify.sh
Last active October 26, 2017 13:56
[OS X Command-line Notifier] #mac
View notify.sh
#!/usr/bin/env bash
args=()
while true; do
if [ "$1" = "-title" -o "$1" = "-t" ]; then
shift
args=( "${args[@]}" with title "\"$1\"" )
shift
elif [ "$1" = "-subtitle" -o "$1" = "-st" ]; then