Skip to content

Instantly share code, notes, and snippets.

@getify
getify / 1.md
Last active March 23, 2024 16:16
describing a bundling question in detail

I'm the author of an npm package that comes as a single ESM-format module, let's call it "A". This package is only a client-side (browser) library, it will not work in Node -- it interacts with client-only web platform APIs.

The "A" package doesn't use any typical build tools (typescript, webpack/vite, etc). But it does include a simple "publish-build" script that's used at npm publish time to prepare a dist/ directory for the package.

The package relies on three npm package dependencies (call them "B", "C", and "D"), which I do not own/control. These 3 packages only distribute themselves as plain .js window-global style scripts. They cannot be imported, because (unfortunately) they make assumptions about global-scope this (being window), non-strict mode, etc. That also means they can't just be inlined into the "A" distribution module file.

Moreover, these dependencies are big enough (and potentially useful enough) that a user of "A" might also want to access and use "B", "C", or "D" functi

@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 / 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,
@smoya
smoya / .gitattributes
Last active March 29, 2022 16:23
Prettify json files output on git diff.
*.json diff=json
// Handy plv8 console object (debugging)
var console = (function(){
var columns = 100;
function logString(level, str) {
var chunk = str.substring(0, columns);
var overflow = str.substring(columns);
plv8.elog(level, chunk);
if (overflow.length) logString(level, " | "+overflow);
};

TMUX - Single window group, multiple session.

So I have been using tmux for a while and have grown to like it and have since added many many customizations to it. Now once you start getting the hang of it, you'll naturally want to do more with the tool.

Now tmux has a concept of window-group and session and if you are like me you'll want multiple session that connects to the same window group instead of a new window group every time. Basically I just need different views into the same set of windows that I have already created, I don't want to create a new set of windows every time I fire up my terminal.

This is the default case if you simply use the tmux command as your login shell, effectively creating a new group of windows every time you start tmux.

This is less than ideal because, if you are like me, you fire up one-off terminals all the time and you don't want all those one-off jobs to stay running in the background. Plus sometimes you need information fro

@creationix
creationix / bash-escape.js
Created April 26, 2012 20:08
Bash argument escaping
// Implement bash string escaping.
var safePattern = /^[a-z0-9_\/\-.,?:@#%^+=\[\]]*$/i;
var safeishPattern = /^[a-z0-9_\/\-.,?:@#%^+=\[\]{}|&()<>; *']*$/i;
function bashEscape(arg) {
// These don't need quoting
if (safePattern.test(arg)) return arg;
// These are fine wrapped in double quotes using weak escaping.
if (safeishPattern.test(arg)) return '"' + arg + '"';