Skip to content

Instantly share code, notes, and snippets.

@zinthose
zinthose / python_inscribe_template_example.py
Created April 12, 2024 06:54
I created this template for use on the WGU inscribe forums when posting python code as the in post code sample editor doesn't allow for the use of the input() function. To address this, I overrode the build in function as shown in this example.
#┊ ⚠ Overwrite input() function to take inputs from a list ⚠
#╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
_i, _, _P, input = [], lambda v: _i.append(v.splitlines()[1::]), lambda p: print(p, end="") if p else None, lambda p=None: _i[0].pop(0) if _P(p) is None else _i[0].pop(0)
#┌──────────────────────────
#│ ✔ INPUT LINES GO HERE ✔
#└──────────────────────────
_('''
3
SOFI
AMZN
@zinthose
zinthose / ratellimit.py
Last active October 22, 2023 01:09
Simple Rate Limiter Decorator for Python
import time
def rate_limit(sec: float = 0):
"""Rate limit a function by number of seconds between calls.
Rate is time passage aware so if the last call was over the limiter, then the next call will be immediate.
Additionally if the time past since the last call was half the time limit, then the next call will be delayed
by half the time limit.
### Examples:
@zinthose
zinthose / staticinator.py
Last active October 20, 2023 05:31
Using the power of functools.partial and decorators, we can make a pseudo static variable!
import functools
def staticinator(**kwargs):
""" Dr. Heinz Doofenshmirtz Approved Staticinator
Ah, Perry the Plateaus, you're just in time to witness my latest invention, the Staticinator!
It's a device that makes things static! Behold!
Allow me to explain my evil plan.
@zinthose
zinthose / dnsexit.sh
Last active September 24, 2023 20:25 — forked from janeczku/dnsexit.sh
A custom module to use DDNS provider "DNSexit.com" with Synology's DDNS update service (HTTPS Edit)
#!/bin/sh
# dnsexit.sh - A DnsExit.com DDNS custom module for Synology DSM
#
# Author:
# Brian Schmidt Pedersen (http://blog.briped.net)
# Zinthose (https fork/edit)
#
# Version:
# 1.3.5
@zinthose
zinthose / static.py
Created September 20, 2023 03:51
An over engineered static variable solution. This method allows you to define static variables in a function. This is useful for when you want to save a value for later use in the same function. Treat this as a proof of concept and not a serious solution. It's much easier to just attach a value too the function object. This is just a fun way to …
import inspect
import re
def static(variable_or_default: any) -> any:
"""
An over engineered static variable solution
This method allows you to define static variables in a function. This is
useful for when you want to save a value for later use in the same function.
@zinthose
zinthose / purgeValues.py
Last active January 18, 2023 05:22
Python function to recursively remove all matching `purgeTest` values from dictionaries and lists, and returns the result as a new dictionary or list. By default this will remove all `None`, empty string values, and empty lists. If the `preserve_list_structure` argument is set to True, then empty lists will not be removed to preserver list struc…
from typing import Callable
def purgeValues(value: dict | list, preserve_list_structure: bool = False, purgeTest: Callable[[any], any] = lambda x: x is None or (type(x) is str and len(x) == 0) or (type(x) is list and len(x) == 0)):
"""Purge values from a dictionary or list.
--------------------
Recursively remove all matching purgeTest values from dictionaries and lists, and returns
the result as a new dictionary or list.
By default this will remove all `None`, empty string values, and empty lists.
If the `preserve_list_structure` argument is set to True, then empty lists will not be
@zinthose
zinthose / buildURL.ts
Created December 26, 2021 23:02
Simple function to build a URL with URI parameters. Function allows for default values and a mechanism to require parameters.
/**
* Simple object that requires each keyed value to be a string.
*/
interface StringObject {[key: string]: string;}
/**
* Utility function to create a URL with parameters.
* @param url Base URL to build for.
* @param uri_values URI parameters to encode add to URL
@zinthose
zinthose / nextBusinessDay.py
Created December 23, 2021 01:32
Gets the next business day taking into account holidays.
from datetime import datetime, timedelta
import holidays
def nextBusinessDay(today=None, additional_offset=0, skip_holidays = True, format=r"%m/%d/%Y", holiday_settings = {'country':'US'}):
# pip install holidays
h_days = holidays.CountryHoliday(**holiday_settings)
# Get todays date if not initially set
if today==None:
today = datetime.now().date()
@zinthose
zinthose / redtext.userscript.js
Last active November 13, 2021 20:44
Tamper Monkey UserScript to extract RedText values from WebAssign assignment pages. Just press CTRL+SPACE!
// ==UserScript==
// @name Get RedText
// @namespace https://gist.github.com/0xFireball/0b0673fd7801de9f82278725d1250cbb
// @version 0.3
// @description Get's the text text from the WebAssign assignment pages and places them into the clipboard tab delimited. This is good for pasting values directly into excel.
// @author Dane Jones
// @require https://code.jquery.com/jquery-2.1.4.min.js
// @require https://raw.githubusercontent.com/kamranahmedse/jquery-toast-plugin/bd761d335919369ed5a27d1899e306df81de44b8/dist/jquery.toast.min.js
// @match https://www.webassign.net/web/*
// @icon https://www.google.com/s2/favicons?domain=webassign.net
@zinthose
zinthose / redtext.js
Last active October 10, 2021 01:49
Simple single line Javascript command you can paste into the WebDev console of your browser to get the "Red Text" values from a webassign.net assignment page. The data is newline delimited so it can be easily pasted into excel for further analysis.
// Use this one for pasting into a single column
copy(Array.from(document.querySelectorAll("div.qws.initialized.focused font[color=red]")).map(e=>e.textContent).join("\n"));
// Use this one for pasting into a single row
copy(Array.from(document.querySelectorAll("div.qws.initialized.focused font[color=red]")).map(e=>e.textContent).join("\t"));
// OTHER: I've used this for wierd outliers but the output data is kinda suspect.
copy([...[...document.querySelectorAll('div.qws.initialized.focused *')].filter(el => (el.childElementCount === 0 && el.innerText !== "" && getComputedStyle(el).color === 'rgb(181, 33, 32)'))].map(e=>e.textContent).join("\n"));