Skip to content

Instantly share code, notes, and snippets.

View samal-rasmussen's full-sized avatar

Sámal Rasmussen samal-rasmussen

  • Tórshavn, Faroe Islands
  • 13:52 (UTC)
View GitHub Profile
@samal-rasmussen
samal-rasmussen / divide.js
Last active August 30, 2024 11:12
bigint, round to even tests
function divide(a, b) {
// Make A and B positive
const aAbs = a > 0 ? a : -a;
const bAbs = b > 0 ? b : -b;
let result = aAbs / bAbs;
const rem = aAbs % bAbs;
// if remainder > half divisor, should have rounded up instead of down, so add 1
if (rem * 2n > bAbs) {
result++;
@samal-rasmussen
samal-rasmussen / npmtrends-sanitisation.md
Last active March 14, 2023 15:28
npmtrends download flooding sanitisation

In the .js bundle on the npmtrends site I found the success handler for fetch requests.

It looks like this:

  e.fetch = function(t, e) {
      ...
      return this.retryer = new a.m4({
          fn: y.fetchFn,
 abort: null == h || null == (o = h.abort) ? void 0 : o.bind(h),
@samal-rasmussen
samal-rasmussen / gist:910ef2238eb5ea81fdca8eeba4ae29d1
Created April 21, 2017 09:16
Simple Rxjs subject load tester
const subjectCount = 500000;
const subjects = [];
for(let i = 0 ; i < subjectCount; i++) {
subjects[i] = new Subject();
subjects[i].subscribe(
(next) => console.log('next ' + i + ' ' + next),
(error) => console.log('error ' + i + ' ' + error),
() => console.log('close ' + i)
);
}