Skip to content

Instantly share code, notes, and snippets.

View sudojunior's full-sized avatar
:shipit:
It'll be fine, let it run. 💥

Junior sudojunior

:shipit:
It'll be fine, let it run. 💥
View GitHub Profile
@sudojunior
sudojunior / nav-create-menu-patch.injector.js
Created June 15, 2023 17:49
A patch for the create entity menu for GitHub's beta navigation.
var btn = document.getElementById("global-create-menu-button");
var el = document.getElementById("global-create-menu-overlay");
function toggle() {
el.style.visibility = el.style.visibility === 'hidden' ? 'visible' : 'hidden';
console.log("toggle", el.style.visibility);
}
btn.addEventListener("click", (event) => {
event.preventDefault();
@sudojunior
sudojunior / index.ts
Created May 29, 2023 17:32
Timestamp duration conversion
// {second}.{millisecond}
// {minute}:{second}.{millisecond}
// {hour}:{...}
const unitScale = [
1000 /* millsecond -> second */,
60 /* second -> minute */,
60 /* minute -> hour */,
24 /* hour -> day */,
7 /* day -> week */
// https://stackoverflow.com/a/19277804
function getFurthestFrom(target: number, list: number[]) {
const outcome: string[] = [];
let record = 0;
for (const index in list) {
const entry = list[index];
const distance = Math.abs(entry - target);
if (distance === record) {

count-of

Count array / list occurrences... 😐

const arr = Array.from(
  { length: 10 },
  () => Math.round(Math.random() * 5)
);
countOf(3, arr);
@sudojunior
sudojunior / year-range.ts
Last active August 11, 2022 23:42
'expand' and 'shrink' year ranges, made in about an hour after an initial version in js only with the expand function
export class YearRange {
static testPattern = /[\d -,]+/g;
static splitPattern = / *[-,] */g;
private static getContext(input: string): YearRangeContext {
console.assert(this.testPattern.test(input), 'Invalid pattern match');
const fragments = input.split(this.splitPattern);
const symbols = input.match(this.splitPattern) ?? [];
using System;
using System.Collections.Generic;
namespace RoleDistribution
{
public struct Role {
// type decimal can be exchanged for double or float with their respective unit conversion, the outcome will not change
public Role(string name, decimal ratio) {
Name = name;
Ratio = ratio;
@sudojunior
sudojunior / slashCreate_wildcardComponents.ts
Created November 22, 2021 20:05
The initial idea for wildcard components, contained within a class and with self-removal (made specifically for ephemeral components at the time, https://github.com/TinkerStorm/story-engine/commit/eda121e934d8aaeb3dbec96235cd5134b32b1368#diff-c5149d754d0b17617d7ea33dad86ed50b7fd50924ef1e86be57c143f4073aa0b).
import { ComponentContext, SlashCreator } from "slash-create";
export default class ComponentWildcard {
cache: Map<string, {
eventKeys: string[],
id: string,
callback: WildcardCallback
}> = new Map();
constructor(public creator: SlashCreator) {
@sudojunior
sudojunior / ephemeral-whisper.js
Created July 19, 2021 15:22
(slash-create) Demonstrating possible use for ephemeral messages through 'whispers'. Understandably, DMs are the default and better alternative - but it was worth exploring.
const { Client } = require("discord.js");
const { GatewayServer, SlashCreator, Command, CommandOptionType, InteractionResponseFlags } = require("slash-create");
const { Endpoints } = require("slash-create/lib/constants");
const client = new Client();
const creator = new SlashCreator({
applicationID: "APP_ID",
publicKey: "PUBLIC_KEY",
@sudojunior
sudojunior / win_keybinds.md
Last active February 12, 2021 16:58
Noteworthy key combinations
  • WinSpace = Change keyboard layout

    Also noted when hovering over the taskbar applet.

  • WinV = Clipboard manager

    Requires activation before use.

  • Win. = Emoji Input Popup > Type to search the list. Select the tabs to switch between Unicode Emojis; Text Emojis and Symbols.
@sudojunior
sudojunior / duration-dynamic-polyfill.js
Last active February 12, 2021 17:33
Duration functions and polyfill
import duration from "./duration-functions.js";
for (const unit of Object.keys(duration)) {
Number[unit] = function (n) {
return Number(n)[unit]();
}
Number.prototype[unit] = function () {
return duration[unit](this);
}