Skip to content

Instantly share code, notes, and snippets.

@mracette
mracette / pagination.js
Created October 26, 2020 22:41
Vanilla JS improved pagination algorithm
/**
* Calculates a fixed-length array of pagination display elements,
* Example return value: [1, "...", 4, 5, 6, "...", 20]
*
* Inspired by https://gist.github.com/kottenator/9d936eb3e4e3c3e02598, but re-worked to ensure
* that the number of display elements stays constant regardless of the current page. Thus, the
* algorithm mimics the behavior of https://material-ui.com/components/pagination/
*
* @param {number} currentPage
* The current page. The rest of the display is oriented around this page.
@mracette
mracette / prepare-commit-msg.js
Last active August 15, 2020 12:01
Git hook tailored for js13k development. It runs build steps and logs the project size at each step.
/*
You will need to configure the global path variables to point to the directories
in your project, as well as to replace any execSync() commands with the build
commands that you are using.
To enable this hook, create .git/hooks/prepare-commit-msg (you may need to unhide
the .git/* folder), make it executable using chmod +x .git/hooks/prepare-commit-msg,
and add the following code in that file to point the hook to this source:
#!/usr/bin/env node