Skip to content

Instantly share code, notes, and snippets.

@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 / 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#)))
...))
@disco0
disco0 / iter.fnl
Last active November 2, 2021 08:02 — forked from leo60228/iter.fnl
; vim:set ft=fnl:
(fn filter-map [pred iter inv start-control]
(var control start-control)
(fn filter-map-inter []
(let [(new-control value) (iter inv control)]
(set control new-control)
(if (= value nil)
nil
; else
(macros
{:list-map
(fn list-map [mapper tgt]
(when (not (list? tgt)) (error (.. "Invalid form: " (tostring tgt) " is not a list")))
(let [new-list (list)]
(each [i v (ipairs tgt)]
(table.insert new-list (mapper v i tgt)))
new-list))
:list-map-recursive
@disco0
disco0 / class.fnl
Created June 9, 2021 06:32
Class script for Lua, includes inheritance (macro) (DO NOT USE PLEASE THIS SUCKS)
;; this, https://gist.github.com/nikneym/b7422a73c91d632e95ad34a813aad105
;; but stuffed in a Fennel macro.
(macro class [mother]
`(let [o# {}
mother# (or ,mother nil)]
(tset o# :__index o#)
(when mother#
(tset o# :super mother#)
(each [k# v# (pairs mother#)]
; lie and say it's clojure for highlighting
; vim: ft=clojure
; this is a hack that won't be necessary if/when we add `get-option` to the macro environment
(local meta-enabled (-> _SCOPE.specials.doc
(pcall (list (sym :doc) (sym :doc)) _SCOPE _CHUNK)))
(fn meta/when-enabled [...]
"Execute body in an implicit `do` when metadata is enabled. Otherwise,
contents are excluded from compiled output."