Skip to content

Instantly share code, notes, and snippets.

@crashbell
crashbell / better-nodejs-require-paths.md
Created August 13, 2017 03:58 — 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:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@crashbell
crashbell / enum.sql
Created August 7, 2017 07:08 — forked from d11wtq/enum.sql
Renaming an ENUM label in PostgreSQL
/*
Assuming you have an enum type like this.
You want to rename 'pending' to 'lodged'
*/
CREATE TYPE dispute_status AS ENUM('pending', 'resolved', 'open', 'cancelled');
BEGIN;
ALTER TYPE dispute_status ADD VALUE 'lodged';
UPDATE dispute SET status = 'lodged' WHERE status = 'pending';
@crashbell
crashbell / cfg-install.bash
Last active April 21, 2022 05:52
Install dotfile curl -Lks http://bit.do/crashbell-cfg-install | /bin/bash
rm -rf $HOME/.cfg
git clone --bare [email protected]:crashbell/dotfiles.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
move_backup () {
echo "Moving backup files";
mkdir --parents "$(dirname "$1")";
mv -f "$1" "$2";
@crashbell
crashbell / date.js
Last active May 6, 2017 03:49
a simple declare a new Date object
new Date(strDate);
def servers = ['server1', 'server2']
def version = "1.0.0-${env.BUILD_ID}"
stage 'Build, UT, IT'
node {
checkout scm
env.PATH = "${tool 'Maven'}/bin:${env.PATH}"
withEnv(["PATH+MAVEN=${tool 'Maven'}/bin"]) {
sh "mvn -e org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=$version -DgenerateBackupPoms=false"
require('babel-polyfill')
const gulp = require('gulp')
const del = require('del')
const babel = require('gulp-babel')
const eslint = require('gulp-eslint')
const nodemon = require('gulp-nodemon')
const dirs = {
jsPath: 'lib/**/*.js',
dest: 'build'
@crashbell
crashbell / pre-push
Last active January 16, 2017 03:47
Trigger `npm run lint` before pushing code to repo. Save as `pre-commit` or `pre-push` in .git/hooks. And `chmod 775` that file to make it executable.
#!/bin/bash
HAS_NPM=`which npm 2> /dev/null`
#
# There are some issues with Source Tree because paths are not set correctly for
# the given environment. Sourcing the bash_profile seems to resolve this for bash users,
# sourcing the zshrc for zshell users.
#
# https://answers.atlassian.com/questions/140339/sourcetree-hook-failing-because-paths-don-t-seem-to-be-set-correctly