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 / 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 / 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: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 / 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 / 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 / 0_reuse_code.js
Created September 22, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@d1b1
d1b1 / delicious.jquery.js
Created February 2, 2012 04:19
Delicious Tag Builder for browser side jekyll blogs.
function get_delicious_json( tags, settings) {
var url = 'http://feeds.delicious.com/v2/json/' + settings.username + '/';
var tagStories = new Object();
var target = $('<ul>', {}).appendTo(settings.target);
$.each(tags.split(settings.separator), function(index, tagStr) {
$.getJSON(url + tagStr + "?callback=?", function(data) {
$.each(data, function(key, val) {
t = val.u;
@d1b1
d1b1 / Validator.prototype.arrayOf(size, regex)
Last active December 11, 2015 04:08
Custom Node.js Validator - arrayOf(size, regex) - Provides the ability to validate that a request value is an array of a given size where each element matches the regex pattern provided. Uses underscore. Designed for a node.js API path where 'date=2012-11-01,2012-12-01' will be used for a date filter into Mongo.
// This is a custom validator that will ensure that
// the value is an array of two elements where each
// element matches the same regex format.
var _ = reqquire('underscore');
var simpleDateRegex = new RegExp("^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])");
Validator.prototype.arrayOf = function(size, regex) {
// Split the string into an array.
@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;
@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.');
}