Skip to content

Instantly share code, notes, and snippets.

View annibal's full-sized avatar

Arthur Annibal annibal

View GitHub Profile
@annibal
annibal / color-tags.md
Created March 28, 2024 21:40
Colored Tags in GitHub Markdown

Using place-hold.it

  • image Task is Yet To Start
  • image Work In Progress
  • image Pull Request in Review
  • image Merged
  • image Blocked by some kind of issue

Syntax:

@annibal
annibal / generateCsv.js
Last active March 28, 2024 21:40
Function to generate controlled random CSV
function generateCsv(params) {
const { colsDef, rowsDef, withHeaders, asString } = params || {};
const formatNumber = (val, intDigits = 1, decDigits = 0) => {
if (isNaN(val)) return "";
return (+val).toLocaleString(undefined, {
minimumIntegerDigits: intDigits,
minimumFractionDigits: decDigits,
});
@annibal
annibal / docValidationHelper.js
Last active November 10, 2023 15:54
Functions to generate Brazil's Document validator number - CPF / CNPJ
/**
* Receives a part of the document and returns a validation digit
* Used mostly for CPF or CNPJ
*
* Ex.:
* getVerificationDigit("000000001") // 9
* getVerificationDigit("0000000019") // 1
* getVerificationDigit("100200300") // 8
* getVerificationDigit(1, 9) // 9
* getVerificationDigit(19, 9) // 1
@annibal
annibal / onClickMakeDots.js
Created November 8, 2023 16:55
Fn to create dots when clicking an element, Fn helper to convert these to scaled, compact array
/* const */ dotsMadeStoreArr = [];
function attachOnClickMakeDotsListener(elm) {
function onClickMakeDotsListener(evt) {
onClickMakeDots(evt);
}
elm.addEventListener("click", onClickMakeDotsListener);
return function detachOnClickMakeDotsListener() {
elm.removeEventListener("click", onClickMakeDotsListener);
/**
* Create a function that transforms an index into an pseudo-random value, where the values are tied to a string
* @param salt string, must have at least one [a-z0-9] character
* @param parseVal [optional] function(val: number, i: number, saltRange: [number, number]) to transform the salt result
* @returns function(idx: number, skipParse: boolean = false), will always return the same value for the specific SALT and IDX
*/
const getSaltedRandomFn = (salt, parseVal) => {
const safeSalt = (salt || "").replace(/[^a-z0-9]/gi, "").toLowerCase();
@annibal
annibal / jsAirflow.js
Created August 11, 2023 13:10
JS Airflow
// Main "Lib" function
/**
* Executes a flow of callbacks passing inputs and storing outputs
* Example: jsAirflow(
* [
* { fn: 'sum', in: ['v1', 'v2'], out: ['result'] },
* { fn: 'power', in: ['result', 'power'], out: ['result'] },
#!/bin/ksh
#
# @(69)$Id$
#
# Helpful functions for your terminal
function git_branches()
{
if [[ -z "$1" ]]; then
git_branches .
@annibal
annibal / input.js
Created August 14, 2019 23:04
Javascript input mapper
const getKey = inputName => (inputs[namedIndexesMap[inputName]] || {value:null}).value
//TODO gamepad
class InputMap {
constructor(inputName, type='', assignedKeyboardKeys=[], assignedGamepadButtons=[], assignedGamepadAxis=[]) {
const strArrayToKeyObj = arr => arr.reduce( (all,curr) => ({...all, [curr]: true}),{})
if (inputName == null) {
throw TypeError("Input Name cannot be null or undefined ")
}
@annibal
annibal / starting_vega_chart.json
Created May 7, 2019 14:11
Starting Vega Chart Spec
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 300,
"height": 300,
"padding": {
"top": 20,
"left": 80,
"bottom": 40,
"right": 20
},
@annibal
annibal / tableGenerator.js
Created April 16, 2019 18:39
Js Customizable Random Table generator
(function() {
function zeroFill(str, len, char) {
if ((str+"").length < len) {
return Array(len-(str+"").length).fill(char)+(str+"")
}
return (str+"")
}
function withVerifierDigits(numbers) {
numbers = numbers+""