Skip to content

Instantly share code, notes, and snippets.

View dhsrocha's full-sized avatar
🎯
Focusing

Diego Rocha dhsrocha

🎯
Focusing
View GitHub Profile
@dhsrocha
dhsrocha / PortUtil.java
Last active April 14, 2021 23:20
Find next available TCP port.
import java.net.ServerSocket;
class PortUtil {
private PortUtil() {}
/**
* Recursively loops until finding a available TCP port, locks it, get
* its value and then releases it.
*
@dhsrocha
dhsrocha / Exec.java
Created February 27, 2021 03:39
Practical sample (Java 8+) for `Runtime.exec` and output returning.
package template;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
@dhsrocha
dhsrocha / setup.sh
Last active April 4, 2020 04:27
Python environment setup with pyenv and pipenv. Also contains self-check logic and middleware setup powered by Shellcheck and Docker respectively.
#!/usr/bin/env sh
set -e
# @see https://gist.github.com/dhsrocha/ee88f54c2e913c59412817e210bd206b/edit
# ::: Global variables
readonly RC="$HOME/.bashrc"
readonly PROJ_NAME="${PWD##*/}"
readonly PROJ_VER="3.8.2"
#!/usr/bin/env sh
set -e; set -f
# http://www.bashoneliners.com/oneliners/243/
CWD=$(cd "$(dirname "$0")" && pwd)
# Run database's docker stack
run_db() { (
sudo docker-compose \
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
#org.slf4j.simpleLogger.defaultLogLevel=info
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
@gene1wood
gene1wood / install-depot-multisystem.sh
Last active April 15, 2020 22:36
Create MultiBoot USB
#! /bin/bash
exec >& >(tee -a /tmp/debug-install-depot-multisystem.txt)
# │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
# │ install-depot-multisystem.sh │
# │ written by François Fabre │
# │ MultiSystem LiveUSB │
# │▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
# Mr Fabre François @frafa
@branneman
branneman / better-nodejs-require-paths.md
Last active September 23, 2024 17:37
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