Skip to content

Instantly share code, notes, and snippets.

@cmargroff
cmargroff / cubicBezier.class.js
Last active August 29, 2015 14:26
Cubic Bezier interpolation class for javascript animation.
function cubicBezier(x1, y1, x2, y2){
var p1 = [x1, y1], p2 = [x2, y2];
this.calculate = function(t){
return [
0 * Math.pow(1-t, 3) + p1[0] * 3 * Math.pow(1-t, 2) * t + p2[0] * 3 * (1-t) * Math.pow(t, 2) + 1 * Math.pow(t, 3),
0 * Math.pow(1-t, 3) + p1[1] * 3 * Math.pow(1-t, 2) * t + p2[1] * 3 * (1-t) * Math.pow(t, 2) + 1 * Math.pow(t, 3),
];
};
}
@cmargroff
cmargroff / window.themeColor.js
Last active August 15, 2018 21:48
Set window color for Chrome 39 Android 4.3+
(function(window, document){
if (typeof window.chrome != "undefined") {
document.themeColorMeta = document.createElement("meta");
document.themeColorMeta.name = "theme-color";
document.themeColorMeta.content = "transparent";
document.head.appendChild(document.themeColorMeta);
Object.defineProperty(window, "themeColor", {
get: function(){
return document.themeColorMeta.content;
},
Object.defineProperty(SVGPolygonElement.prototype, 'pathLength', {
get: function(){
var numPoints = this.points.length || this.points.numberOfItems;
var l = 0;
for (var i = 1; i < numPoints; i++) {
var point2 = this.points[i] || this.points.getItem(i);
var point1 = this.points[i-1] || this.points.getItem(i-1);
l += Math.sqrt(Math.pow(Math.abs(point2.x-point1.x),2)+Math.pow(Math.abs(point2.y-point1.y),2));
}
return l;
"use strict";
class Spline{
constructor(points){
if(points.length % 2 !== 0 || points.length < 6){
return undefined;
}
this.x = [];
this.y = [];
for(var i=0; i < points.length; i+=2){
// ==UserScript==
// @name Steam Wishlist Discount Sort
// @namespace http://steamcommunity.com/
// @version 0.1.3
// @description Adds discount sort button and allows sorting by discounts descending
// @author Chris Margroff
// @match *://steamcommunity.com/*/*/wishlist*
// @grant none
// ==/UserScript==
// ==UserScript==
// @name PkmnCards Random Hotkey
// @namespace https://pkmncards.com/
// @version 0.1.3
// @description Adds a keyboard hotkey to jump to a random card.
// @author Chris Margroff
// @match https://pkmncards.com/*
// @grant none
// ==/UserScript==
// ==UserScript==
// @name Steam Tag Page Hotkeys
// @namespace http://store.steampowered.com/
// @version 0.1
// @description Hotkeys for paging through discovery queue on tag pages
// @author Chris Margroff
// @match http://store.steampowered.com/tag/*/*
// @grant none
// ==/UserScript==
@cmargroff
cmargroff / AudioNode.events.js
Last active July 11, 2017 18:22
Dispatch events to connected node of an input connected or disconnected
AudioNode.prototype.originalConnect = AudioNode.prototype.connect;
AudioNode.prototype.originalDisconnect = AudioNode.prototype.disconnect;
//event.detail is the connected or disconnected node
Object.defineProperties(AudioNode.prototype, {
connect: {
value: function(){
if (arguments[0] instanceof AudioNode) {
arguments[0].dispatchEvent(new CustomEvent('inputconnected', {detail: this}))
}
// ==UserScript==
// @name Pkmn Cards Proxy Print Layout
// @namespace https://pkmncards.com/
// @version 0.2.2
// @description Format print layout better
// @author Chris Margroff
// @match https://pkmncards.com/proxy/*
// @grant none
// ==/UserScript==
@cmargroff
cmargroff / node-windows-loadavg.js
Created August 6, 2018 19:51
emulates loadavg for windows platforms
var lastCpus = [];
var lastTimestamp = 0;
const { performance } = require('perf_hooks');
function AvgList(limit){
this.measures = [];
this.totalTime = 0;
this.limit = limit;
this.push = function(measure){
if ((this.totalTime + measure.delta) > this.limit) {