Skip to content

Instantly share code, notes, and snippets.

View d1b1's full-sized avatar
🎯
Focusing

Stephan L. Smith d1b1

🎯
Focusing
View GitHub Profile
@d1b1
d1b1 / Git Notes
Last active August 29, 2015 14:28
Git Must-Remember Notes
// GIT Merge
// Use this feature to push an local branch 'over' a remote branch.
// This is useful when mushing a local release branch into the staging
// environment.
git push origin localBranch:remoteBranch
or
@d1b1
d1b1 / gist:d82a2bfe0ac103298079
Created June 2, 2015 00:40
Parse.com + Stripe.com API Workaround
Seems that parse.com has either neutered a portion of the their stripe.com integration, just decided it is not needed. The docs seem to point to the Stripe.Customers.update(id, token) as the way to add a card (using a token) to a customers account. This works, but only allows a single card. This overwrites the initial card with the new card. Not great.
// This should work, but only allows a single card.
Stripe.Customers.update(customer, { card: found.get('token') },
function(err, token) {
console.log('got here for token');
console.log(token);
});
// This works, and seems to point to the need for parse.com to add some work to their backlog. Looks
@d1b1
d1b1 / gist:966ef9798db13b7856f5
Created July 23, 2014 13:36
Atom.io Snippets
'.source.js':
'Form Input':
'prefix': 'input'
'body': '
<div class="form-group">\n
<label class="col-md-3 control-label">$1</label>\n
<div class="col-md-6">\n
<input type="text" class="form-control col-xs-3" name="$2" value="{{model.$2}}" placeholder="" >\n
<span class="error help-block hide">Please enter a $1</span>\n
</div>\n
@d1b1
d1b1 / Backbone-View-Example.js
Last active August 29, 2015 14:02
Backbone Paginationer - Code Example for using Collection Plugin and View Search Options.
// Working model of how to use the Backbone.Paginator Plugin.
var defaults = {
queryParams: {
pageSize: '_limit',
currentPage: '_page',
totalPages: null,
totalRecords: null,
},
state: {
@d1b1
d1b1 / gist:9667600
Created March 20, 2014 16:17
Delete folders older then 2 weeks
find . -maxdepth 1 -type d -mtime +14 -exec rm -r {} \;
@d1b1
d1b1 / gist:7949456
Last active December 31, 2015 06:39
Express.js App for testing REST API (Swagger.js) on CodeShip.io
/*
This script is part of a pattern that allows mocha to test
a REST API (Swagger.js + Expressjs) on a CI provider, codeship.io,
travis-ci etc. This makes the express app accessible to script
that starts the server and runs the tests.
Also see: https://gist.github.com/d1b1/7949308 (Programmable Mocha script)
*/
@d1b1
d1b1 / gist:7949308
Last active October 25, 2016 08:50
Programmatic Mocha script for CodeShip.io - Starts an express app, and runs any .js tests in the tests folder. This allows a node.js Swagger.js rest API to be testable on travis-ci and codeship.io.
/*
Programmatic Mocha code - This is used by a codeship
test to both start an expressjs app, setup routes and
run a suite of mocha tests.
Hint: Place this in the root of the project. Call from
test package.js or setup with > node mocha.js
Also see: https://gist.github.com/d1b1/7949456 (Expressjs + Swagger App)
@d1b1
d1b1 / forever.sh
Last active December 11, 2015 04:48
Simple bash command to start forever. Defines all the log settings and the --SourceDir syntax.
forever stopall
ROOT='/var/www/myapp'
forever start \
-l ${ROOT}/logs/manage-all.log \
-o ${ROOT}/logs/manage-out.log \
-e ${ROOT}/logs/manage-err.log \
-a \
--sourceDir ${ROOT}/manager/ \
@d1b1
d1b1 / Validator.prototype.isObjectID()
Last active December 11, 2015 04:08
Custom Node.js Validator for MongoIDs. Build to DRY out and standardize the validation of MongoIDs passed as path or query values into a express endpoint.
var Validator = require('validator').Validator;
Validator.prototype.isObjectID = function() {
var regex = new RegExp("^[0-9a-fA-F]{24}$");
if (!regex.test(this.str)) {
this.error(this.msg + ', Requires a String of 12 bytes or a string of 24 hex characters.');
}
@d1b1
d1b1 / req.urlparams()
Last active December 11, 2015 04:08
Simple Express Server function to put Query variables into the request scope for router calls.
/*
Used the url module to parse and place the parameters into req.urlparams.
Follows the same pattern used for swagger API path variables that load
into the req.params scope.
*/
app.use(function(req, res, next) {
var url = require('url');
var queryURL = url.parse(req.url, true);
req.urlparams = queryURL.query;