Skip to content

Instantly share code, notes, and snippets.

@caderek
caderek / example.js
Created February 3, 2024 14:52
lodash chunk bundled
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) =>
function __require() {
return (
mod ||
@caderek
caderek / typelit.user.css
Created December 3, 2023 15:19
Typelit style
/* ==UserStyle==
@name Typelit Monika
@namespace github.com/openstyles/stylus
@version 1.0.0
@description A new userstyle
@author Me
==/UserStyle== */
@-moz-document domain(typelit.io) {
@caderek
caderek / primes.txt
Created July 18, 2023 09:26
First 1000 prime numbers
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349
353 359 367 373 379 383 389 397 401 409
419 421 431 433 439 443 449 457 461 463
467 479 487 491 499 503 509 521 523 541
@caderek
caderek / mod.js
Last active February 7, 2023 20:20
Modular arithmetic example
// JS remainder operator `%` won't work for our case,
// we need a modulo that follows modular arithmetics definition.
function mod(num, modulus) {
return ((num % modulus) + modulus) % modulus;
}
// Alternative (not strict, but IMO easier to remember)
function modAlt(num, modulus) {
const x = num % modulus;
return x < 0 ? x + modulus : x;
@caderek
caderek / wrapStorage.js
Last active February 5, 2023 06:39
Simple wrapper for local and session storage
/**
* Simple wrapper for localStorage and sessionStorage,
* that takes care of data initialization, serialization and deserialization,
* so you can work with simple JSON-compatible values.
*/
function wrapStorage(storage, initialData = {}) {
const publicAPI = {
get size() {
return storage.length
},
@caderek
caderek / loops.bench.js
Created January 13, 2023 21:06
JS loops benchmark.
import benny from "benny";
const data = Array.from({ length: 100_000 }, (_, i) => i);
let r1 = 0;
let r2 = 0;
let r3 = 0;
let r4 = 0;
let r5 = 0;
@caderek
caderek / remove-spaces.perf.js
Created January 11, 2023 23:00
Remove spaces benchmark
import b from "benny";
import {
removeSpaces,
removeSpaces2,
removeSpaces3,
removeSpaces4,
} from "./code.js";
{
const NUMBER_OF_FORMULAS = 1000;
const generateName = (num) => {
const charCode = (num % (122 - 96)) + 97;
const count = Math.floor(num / 26);
return String.fromCharCode(charCode).repeat(count + 1);
};
const formulas = new Map(
import b from "benny";
import calculateWithObject from "./calculate-with-object.js";
import calculateWithMap from "./calculate-with-map.js";
b.suite(
"calculate",
b.add("calculate with object", () => {
calculateWithObject("average", 1, 1);
}),