Skip to content

Instantly share code, notes, and snippets.

@bitifet
bitifet / teleport
Created March 6, 2024 13:32
Directory "teleportation" script: Allow to test your working copy in a remote server, perhaps behind a firewall, with just an ssh connection.
#!/usr/bin/env bash
# :vim setf bash
# Constants:
tunPort=9876;
screenSessId="teleport_$$"
# Define handy default values:
allHostNames=$(hostname -A);
srcFQDN=${allHostNames%% *}
@bitifet
bitifet / objectMap.js
Last active January 25, 2024 16:22
objectMap(): Kind of Array.map() but for objects...
// USAGE: objectMap(<object>, <callback>)
// <object>: Any regular JavaScript object.
// <callback>: function(<current_value>, <current_key>, <original_object>) {...}
// EXAMPLE:
// objectMap({a: null, b: "23"}, Number) //-> { a: 0, b: 23 }
function objectMap(obj, cbk) {
return Object.fromEntries(
Object.entries(obj).map(
([key, value])=>[key, cbk(value, key, obj)]
)
@bitifet
bitifet / SmallCahce.js
Created January 14, 2024 22:15
Just a simple Array Cache that I finally won't use by now... 😃
export class smallCache extends Array {
constructor(maxlength = 10) {
super();
Object.defineProperty(this, "maxlength", {
value: maxlength,
enumerable: false,
@bitifet
bitifet / aside.js
Created July 14, 2022 11:10
Log objects aside in console.
function aside(...args) {
// Usage examples:
// ---------------
// console.log(aside(var1, var2));
// console.log(aside({var1, var2, someValue: 23}));
// console.log(aside.bind("My title")(var1, var2));
// console.log(
// aside.bind({
// title: "My title",
// separator: "#",
@bitifet
bitifet / edam_module_index.js
Last active March 23, 2022 22:31
Event Driven Async Modules
// sampleModule/index.js
// =====================
// EDAM - Event Driven Async Module
// (Example / Skeleton)
"use strict";
module.exports = (async ()=>{
// Module-level definitions:
const module_preferences = {
p1: 10,
@bitifet
bitifet / wildcards.js
Last active November 18, 2020 17:51
Transform search patterns to regular expressions.
// wildcards(pattern [, modifiers])
// ================================
//
// Transform search patterns with wildcards ('*' and '?')
// to suitable regular expresions.
//
// CAUTION: Pre-wrap with '*' (if needed).
//
// @@ Examples: @@ //
// @@ --------- @@ //
@bitifet
bitifet / 01_The_Problem.txt
Created September 17, 2019 08:44
Regular expression translation
Translate well known filesystem-like wilcards ('?' for single character and '*' for 0 or more) to:
a) Suitable SQL pattern (with '_' and '%' instead) for 'like' and 'ilike' comparsion.
b) Suitable regular expression.
In both cases whithout breaking anything. That is, exitent meaningful ('%', and '_' for DB
and '.', '+', '[', etc... for regular expressions) should be properly escaped.
Also:
@bitifet
bitifet / Deferrable_Promis_Cancellator.js
Last active September 12, 2019 08:39
Promise Cancellator
// Promise cancellation utility
// Inspired on this @getify tweet:
// https://twitter.com/getify/status/1171820071582339072
// (Deferrable version)
// ----- IMPLEMENTATION: -----
function cancellator() {
let cancelTimowut = null;
let cancelMessage = "Cancelled";
const stoppers = [];
@bitifet
bitifet / BestPractice_Solution.js
Created August 28, 2019 16:12
.softBind() - Rebindable [function].bind() alternative.
// Unless it could become ECMASCRIPT proposal best practice
// would be to use regular function in order to avoid polluting
// [function]'s prototype
// Twitter: https://twitter.com/bitifet/status/1166745132651220992?s=20
const softBind = (function() {
const master = Symbol();
return function softBind(self, ...args) {
const fn0 = self[master] || self;
const fn = fn0.bind(...args)
fn[master] = fn0;
[B9B80A21DF98BE68DB4033CF3D4D2246B2AF9078989B9AB5260C1C5F349F5BE338DBA0453B87F1C5F2D66B6C1526EC2771317B2DAFB1E22DD0A5A7C689DB6BFBC5745A5569054495288B1B91894C73DDBDAB97F25C862DF282DBF46559AC91165E47A660BB98BAAA6E717724BE210B78C45E3AC83F152D4424965057093B2F2FA1B17257E1DB20F6CE30141F38880B42520F6107C61CDA31815B6E6293B74FDDFC0C9D7159B098FA4F5694F697E1FC6EE92284CA6EE2474F93B32E2608195EAAA573295004DC499276FDC698C2FFDE49543562F3BA5931479F37E9994C0A299FEEDF26247AE0E05890AEE439423633D151CEA28FDEB352BD46AF9F96BB7E18FD99F98CB964C154BE60232C7CFF32B7]