Skip to content

Instantly share code, notes, and snippets.

///<reference types="tampermonkey"/>
// @ts-check
// ==UserScript==
// @name DevTools - GM API on console
// @name:zh-CN 开发工具:在控制台启用 GM API
// @namespace https://github.com/cologler/
// @version 0.1.0.3
// @description Modified fork of original script <gist.github.com/Cologler/323558e1e55d20b73eadc8a5eb6bebde>
// @description:zh-CN try to take over the world!
@disco0
disco0 / vectorized-atan2f.cpp
Created August 18, 2021 01:40 — forked from bitonic/vectorized-atan2f.cpp
Vectorized & branchless atan2f
// Branchless, vectorized `atan2f`. Various functions of increasing
// performance are presented. The fastest version is 50~ faster than libc
// on batch workloads, outputing a result every ~2 clock cycles, compared to
// ~110 for libc. The functions all use the same `atan` approximation, and their
// max error is around ~1/10000 of a degree.
//
// They also do not handle inf / -inf
// and the origin as an input as they should -- in our case these are a sign
// that something is wrong anyway. Moreover, manual_2 does not handle NaN
// correctly (it drops them silently), and all the auto_ functions do not
@disco0
disco0 / naive-rate-limiter.ts
Last active July 20, 2021 11:03 — forked from jwulf/naive-rate-limiter.ts
A naive functional rate limiter with an absolute limit
interface QueuedTask<T> {
task: () => T;
promise: {
resolve: (res: any) => void;
reject: (err: any) => void;
};
}
interface RateLimitedTask<T> {
task: () => T;
@disco0
disco0 / throttle.ts
Created July 20, 2021 11:01 — forked from Almenon/throttle.ts
typescript throttling / ratelimiting
/**
* class for limiting the rate of function calls.
* Thanks to Pat Migliaccio.
* see https://medium.com/@pat_migliaccio/rate-limiting-throttling-consecutive-function-calls-with-queues-4c9de7106acc
* @example let l = new limit(); let logMessageLimited = l.throttleAndQueue(msg => { console.log(msg); }, 500);
*/
class limit{
public callQueue = []
/**
@disco0
disco0 / README.md
Created July 20, 2021 10:51 — forked from luciferous/README.md
Rate Limiter in Javascript

How to use

Let's say you want to limit some event to 5 occurrences every 20 seconds, you would set up the RateLimit like so:

var limit = new RateLimit(20); // Initialize a 20 second ticklog

// For events that we initiate...
if (limit.count('myevent_id') <= 5)) {

// Do some stuff

@disco0
disco0 / gist:4854605760fad0d6cdbde82de54fd68e
Created July 13, 2021 08:19 — forked from dpflug/gist:1986830
Substrate by j.tarbell
// Substrate Watercolor
// j.tarbell June, 2004
// Albuquerque, New Mexico
// complexification.net
// Processing 0085 Beta syntax update
// j.tarbell April, 2005
int dimx = 250;
int dimy = 250;
@disco0
disco0 / brew-install-vintage.zsh
Created July 12, 2021 23:25
brew-install-vintage - Install a previous version of a homebrew formula
#!/usr/bin/env zsh
###
# Installs a previous version of a homebrew formula.
#
# Based on https://cmichel.io/how-to-install-an-old-package-version-with-brew/
#
# @param $1 @ Formula Name
# @param $2 @ Version
##
@disco0
disco0 / shader.hlsl
Created July 12, 2021 02:43 — forked from mmozeiko/shader.hlsl
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
@disco0
disco0 / gist:49e84ec03e7e5561b84ac455d25584f8
Created June 17, 2021 09:16 — forked from osa1/gist:2757232
Lisp-style lazy-lists in Lua
function makeThunk(f, args)
return { tag = "thunk", f = f, args = args }
end
function evalThunk(t)
return t.f(unpack(t.args))
end
function cons(first, rest)
return { first = first,
(fn comprehend [init update ...]
(let [clauses [...] n (length clauses) result (gensym)]
(tset clauses n (update result (. clauses n)))
(for [i (- n 1) 1 -1] (table.insert (. clauses i) (. clauses (+ i 1))))
`(do (var ,result ,init) ,(. clauses 1) ,result)))
(fn tbl [...]
(comprehend {}
(fn [result expr] `(match ,expr (k# v#) (tset ,result k# v#)))
...))