Skip to content

Instantly share code, notes, and snippets.

View Tythos's full-sized avatar
🐧
Coding

Brian Kirkpatrick Tythos

🐧
Coding
View GitHub Profile
@Tythos
Tythos / quajax-v1.0.0.js
Last active August 14, 2020 05:30
Single-file JavaScript module: Lightweight AJAX library for single get, multiple get, and full REST queries
/* Lightweight AJAX library for single get, multiple get, and full REST
queries. Will eventually be porting this to modern "fetch() => then...", if
we can map the same (very useful) API. NOT cross-platform (e.g., IE is
explicitly not supported, which makes things VERY simple).
*/
define(function (require, exports, module) {
exports.get = function (url, callback) {
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
@Tythos
Tythos / pubsub-v1.0.0.js
Last active August 14, 2020 05:36
Single-file JavaScript module: Attaches pub/sub behavior to the given object or constructor
/* Attaches pub/sub behavior to the given object. Returns a function that
attaches pub/sub behavior, including an *eventListeners* property, to the
given object or prototype function. Usage is simple; assume TestObj is a
constructor:
> pubsub(TestObj);
> var to = new TestObj();
> to.subscribe('trigger', function(eventObj) {
console.log(this);
console.log(eventObj);
@Tythos
Tythos / jtx-v1.2.0.js
Last active October 9, 2020 00:19
jtx: JavaScript Type Extensions, SFJSM providing useful methods associated with specific JavaScript datatypes
/* JavaScript Type Extensions (jtx) provides useful methods associated with
specific JavaScript datatypes, but (unlike previous implementations) without
monkey patching.
*/
define(function(require, exports, module) {
exports.String = {};
exports.Array = {};
exports.Object = {};
exports.Date = {};
@Tythos
Tythos / Animaniac-v1.1.0.js
Created April 6, 2020 17:34
Single-file JavaScript module: object-based animations for CSS-managed DOM manipulation
/* Object-based for DOM animation management of style properties.
*/
define(function(require, exports, module) {
function Animaniac() {
/* Initializes animation object with default parameters. Users will
typically assign the following properties before calling "start()":
* element (the relevant DOM element)
* properties (style property keys with 2-element initial/final values Array)
* callback (what to invoke when the transition has finished)
@Tythos
Tythos / fxp-v1.1.0.js
Created April 6, 2020 18:16
Single-file JavaScript module: MATLAB- (or matplotlib-) like plotting capabilities, wrapping d3 for easy and reusable charts
/* https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot
Once figure/axis handle is initialized, the dependency tree for new series
and handle property modifications is, order of update required:
#. <svg/> dimensions
#. margin
#. title, xlabel, ylabel positions
#. x/y scales
#. x/y axes
#. point positions
@Tythos
Tythos / rainbow-v0.0.1.js
Last active August 14, 2020 05:39
Some useful color management and conversion utilities, specifically intended for use with THREE.js
/* Collection of useful utilities for processing and transforming color values.
*/
define(function(require, exports, module) {
let THREE = require("lib/three-v0.115.0");
exports.hsv2rgb = function(hsv) {
/* Useful HSV-to-RGB conversion
*/
let hue = hsv[0] * 360;
@Tythos
Tythos / numb-v0.0.1.js
Created April 17, 2020 17:31
Useful collection of numerical methods with no dependencies; mostly bare for now, with great plans for the future, let me tell you :D
/* Useful collection of numerical methods
*/
define(function(require, exports, module) {
function quadratic(a, b, c) {
/* Returns a two-element Array of root solutions to the quadratic
defined by the coefficients a, b, and c. Depending on the solution,
one or both elements may be NaN.
*/
let b2 = Math.pow(b, 2);
@Tythos
Tythos / kirksrv.py
Last active May 21, 2020 18:12
Basic reusable server base, using Flask-based WSGI application served asynchronously w/ gevent.pywsgi
"""Basic reusable server base, using Flask-based WSGI application served
asynchronously with gevent.pywsgi; provides a nice template / starting point
that I've reused several dozen times.
"""
import os
import flask
from gevent import pywsgi
MOD_PATH, _ = os.path.split(os.path.abspath(__file__))
@Tythos
Tythos / WebThread-v1.0.0.js
Created June 15, 2020 23:11
WebThread-v1.0.0.js
/* Single-file JavaScript module that defines a developer-friendly interface
for adapting, and using, AMD-compatible modules in a threaded manner using
WebWorkers. There are two components:
1. The first ("if") block is evaluated by the WebWorker, which should
include the following line at the beginning of the file:
> importScripts("WebThread.js");
The module in question, which should be single-file (dependency-free),
@Tythos
Tythos / 0.1.0.js
Last active August 12, 2021 18:23
spheregeo
/**
*/
define(function(require, exports, module) {
let D2R = Math.PI / 180;
let sum = function(series) { return series.reduce(function(a=0, b) { return a + b; } ) };
/**
* Returns a unit vector (3-element Array) for the given phi and theta
* values.