Skip to content

Instantly share code, notes, and snippets.

@lleaff
lleaff / DEBUG.js
Created February 27, 2017 15:15
Better console.log debugging
self.DEBUG_ON = true;
function DEBUG(...args) {
if (!DEBUG_ON) { return; }
const stack = (new Error().stack).match(/\s+at .*\s+at ([^\(]+)/);
const caller = stack && stack[1] ? stack[1].replace(/\s+$/, '') : 'top_level';
(console.debug || console.log)(`[DEBUG@(${caller})]:`, ...args);
}
Object.defineProperty(Object.prototype, 'DEBUG', {
value: function DEBUG_PIPE(msg, ...args) {
DEBUG(msg, this, ...args);
@lleaff
lleaff / js-dependency-graph.sh
Last active December 1, 2017 15:25
Generate JavaScript dependency graph with Madge and open in default SVG viewer
#!/bin/bash
# Generate JavaScript dependency graph with Madge and open in default SVG viewer
function random_filename() {
local length=${1:-10}
head -c $(( $length * 100 )) /dev/urandom | \
tr -dc 'a-zA-Z0-9-_' | \
head -c $length
}
@lleaff
lleaff / substenv-ng-inplace.bash
Last active December 4, 2017 10:22
Replace marked variables with environment variables (in-place version)
#!/bin/bash
################################################################################
#
# Replace marked variables with environment variables (in-place version).
# Author: lleaff
# Version: 1.0
#
################################################################################
@lleaff
lleaff / custom.css
Created January 23, 2019 17:06
VS Code - Smaller Activity bar, larger sidebar
/*
* VS Code - Smaller Activity bar, larger sidebar (left side only)
*
* To enable:
* - Install https://marketplace.visualstudio.com/items?itemName=be5invis.vscode-custom-css
* - Save content of this file somewhere, CUSTOMCSSPATH.
* - Add to VS Code user settings:
* "vscode_custom_css.imports": ["file://CUSTOMCSSPATH"],
* "vscode_custom_css.policy": true,
* - $ sudo -E code --user-data-dir=$HOME/.config/Code/
@lleaff
lleaff / transfer-ass-headers
Created June 23, 2020 14:59
Copy styles from one ASS subtitle file to another
#!/usr/bin/env node
// Copy styles from one ASS subtitle file to another by copying every section above [Events]
const fs = require('fs').promises
const sourcePath = process.argv[2]
const targetPath = process.argv[3]
async function main() {