Skip to content

Instantly share code, notes, and snippets.

View subfuzion's full-sized avatar

Tony Pujals subfuzion

View GitHub Profile
@subfuzion
subfuzion / gist:1128192
Created August 5, 2011 18:37
Git Tips: Reset, Clean - Remove untracked files and directories from the working tree when switching branches or checking out different commits.
git reset --hard
git clean -f -d
Description:
============
Git Tips: Remove untracked files and directories from the working
tree when switching branches or checking out different commits.
Explanation:
@subfuzion
subfuzion / mandrill-api-node.md
Last active January 1, 2016 06:09
Use mandrill-api-node with npm
@subfuzion
subfuzion / deploy.md
Created February 26, 2014 18:43
shell script to deploy and start a node app via ssh

A simple starter script to copy a node app to a remote host and start it over ssh.

Not very robust in terms of order-dependent argument handling. Arguments have defaults, but if you provide a value for one, any preceding args must also be supplied.

Arguments

  1. The source directory. Defaults to current directory.
  2. The destination server for the ssh connection.
  3. The port to run the app on the destination server. Defaults to port 80.
@subfuzion
subfuzion / error.md
Created February 26, 2014 18:54
Creating custom Error objects in Node.js

Sometimes you want to wrap error objects with application-specific errors for your stack traces.

Your custom error constructor:

function CustomError(e, extra) {
  Error.call(this);
  Error.captureStackTrace(this, CustomError);
  this.id = e.id;
 this.name = 'CustomError';
@subfuzion
subfuzion / nconf.md
Created February 26, 2014 19:01
Using nconf for Node application configuration

It's easy enough to load json files in Node, but what's nice about nconf is it neatly takes care of mundane issues and provides a nice way of hierarchically designating the precedences of settings. For example, it is trivial to specify that application args will override environment settings, which will override any configuration file settings, which will override any application defaults.

This is more of a memory aid to myself. It's best to check out the full documentation the first time through to familiarize yourself with all that nconf has to offer.

https://github.com/flatiron/nconf

npm install --save nconf

Using nconf

@subfuzion
subfuzion / mongoose-cheatsheet.md
Created February 26, 2014 19:03
mongoose cheatsheet

Definitely not comprehensive. This is meant to be a basic memory aid with links to get more details. I'll add to it over time.

Install

$ npm install mongoose --save

Connect

const mongoose = require('mongoose');
@subfuzion
subfuzion / vi-keys.md
Created February 26, 2014 19:06
VI keys

Just a quick and dirty memory aid for common things.

Undo, Redo, and Repeat

Action Keys
Undo u or :u
Undo all changes to line U
Redo undone change Ctrl-R or :red[o]
Repeat last command .
@subfuzion
subfuzion / ssh-notes.md
Created February 26, 2014 19:10
ssh notes

Just a basic memory aid.

Create keys

Create a new key using the email address as label

$ ssh-keygen -t rsa -C "name@example.com"

Accept the default name (~/.ssh/id_rsa) or provide another for multiple identities

@subfuzion
subfuzion / mongo-shell-helpers.md
Created February 26, 2014 19:14
mongo shell helpers

You can load helper functions from a JavaScript file to make working with data in the mongo shell easier.

I typically like to create a queries.js file that contains a number of helper functions. You load a file in the shell like this:

> load('queries.js')

Since I keep editing the file and adding more helpers as I'm working, I usually add a helper function to the file that reloads itself to save a few keystrokes. Yup, I'm that lazy.

function update() {

@subfuzion
subfuzion / mongo-autostart-osx.md
Last active March 2, 2022 00:57
mongo auto start on OS X

Install with Homebrew

brew install mongodb

Set up launchctl to auto start mongod

$ ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

/usr/local/opt/mongodb/ is a symlink to /usr/local/Cellar/mongodb/x.y.z (e.g., 2.4.9)