Skip to content

Instantly share code, notes, and snippets.

@bugventure
bugventure / chain.js
Last active July 2, 2019 03:02
Express middleware chain implementation
module.exports = function chain() {
var steps = Array.apply(null, arguments);
return function middleware(req, res, next) {
(function dequeue() {
var step = steps.shift(),
callback = steps.length ? function (err) {
if (err) {
return next(err);
}
@bugventure
bugventure / uuid.js
Last active November 30, 2021 10:16
UUID regex matching in node.js
function createUUID() {
return uuid.v4();
}
// version 4
// createUUID.regex = '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$';
createUUID.regex = '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$';
createUUID.is = function (str) {
return new RegExp(createUUID.regex).test(str);
@bugventure
bugventure / .bashrc
Last active September 15, 2016 23:05
cwd-only bash prompt with posh-git-sh
# https://github.com/lyze/posh-git-sh
# posh-git-sh (symbolic link from the posh-git-sh github repo is required first)
source ~/git-prompt.sh
# PROMPT_COMMAND='__posh_git_ps1 "\u@\h:\w" "\\\$ "'
PROMPT_COMMAND='__posh_git_ps1 "[\w]" "\\\$ "'
@bugventure
bugventure / raiseterminal.sh
Last active August 29, 2015 14:07
Bash script to start a new or focus any open terminal window in Ubuntu
if
ps aux | grep "[g]nome-terminal" > /dev/null
then
xdotool windowactivate `xdotool search --onlyvisible --class gnome-terminal`
else
gnome-terminal &
fi