Skip to content

Instantly share code, notes, and snippets.

@Genovo
Genovo / better-nodejs-require-paths.md
Created March 29, 2021 11:46 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@Genovo
Genovo / proxyTrack.js
Created December 19, 2019 21:57 — forked from mrharel/proxyTrack.js
Using Proxy to Track Javascript Class
const callerMap = {};
function getCaller(error) {
if (error && error.stack) {
const lines = error.stack.split('\n');
if (lines.length > 2) {
let match = lines[2].match(/at ([a-zA-Z\-_$.]+) (.*)/);
if (match) {
return {
name: match[1].replace(/^Proxy\./, ''),
@Genovo
Genovo / puck.sh
Created May 28, 2019 15:53 — forked from lopes/puck.sh
A DNS propagation checker in Shell Script.
#!/bin/bash
#puck.sh
# A DNS propagation checker. Fetches in many DNS servers around
# the world for IPs assigned to a given domain.
#
# Author: José Lopes de Oliveira Júnior <http://joselop.es>
#
#
@Genovo
Genovo / unary.js
Last active February 25, 2018 15:56
“Unary” is a function decorator that modifies the number of arguments a function takes: Unary takes any function and turns it into a function taking exactly one argument.
const unary = (fn) =>
fn.length === 1
? fn
: function (something) {
return fn.call(this, something)
}
['1', '2', '3'].map(unary(parseInt))
//=> [1, 2, 3]
@Genovo
Genovo / swa11-6.py3
Created October 22, 2017 01:54
Shortcut for SWA Fare Lookup-hardcoded Airports
#!/usr/bin/python3
#swaSearch.py
#Southwest Air Fare Searcher
#
#
#Default Aiports:
departureAirportCode = "LAX"
arrivalAirportCode = "SJC"
#departureDate=
@Genovo
Genovo / strictMode.sh
Created September 13, 2017 18:40
Bash "Strict Mode"
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'