Skip to content

Instantly share code, notes, and snippets.

View dhollenbeck's full-sized avatar

Dan Hollenbeck dhollenbeck

View GitHub Profile
@dhollenbeck
dhollenbeck / Menu_view.js
Created January 24, 2012 22:12
backbone.js collection with nested models for a nested list menu
App.views.Menu = App.views.View.extend({
//define this.el, the wrapper element
//id: '',
tagName: 'div',
className: 'menu',
id: 'menu',
//template function
template: _.template($('#menu-template').html()),
@dhollenbeck
dhollenbeck / client.js
Created December 6, 2012 19:43
Backbone.js and slim framework exmaple
// define a user model
App.models.User = Backbone.RelationalModel.extend({
urlRoot: '/api/users/',
defaults: {
first_name: '',
name_last_name: '',
email: ''
}
});
@dhollenbeck
dhollenbeck / example.js
Last active August 29, 2015 14:24
Handlebar Template Example
/*
Node.js example of using Handlebars template engine to create custom text strings with custom template functions.
Setup:
- handlebars template language
- swag template helpers
- custom template helpers
*/
var Handlebars = require('handlebars');
@dhollenbeck
dhollenbeck / node-excel.md
Last active October 16, 2015 13:12
Node.js and MS Excel
@dhollenbeck
dhollenbeck / timezone.js
Last active December 7, 2015 21:45
zipdatamaps.com
var request = require('request');
var zip = '78733';
var url = 'http://www.zipdatamaps.com/' + zip;
request(url, function (error, response, body) {
if (error) console.log(error);
//parse timezone
var min = body.indexOf('blah');
var max = body.indexOf('blah blah');
var tz = body.substring(min, max);
@dhollenbeck
dhollenbeck / hbs.js
Created March 31, 2016 12:38
Node.js express-handlebars YAML Front Matter (YFM) example
'use strict';
var yfm = require('yfm');
var _ = require('underscore');
var exphbs = require('express-handlebars');
var hbs = exphbs.create({/* options */});
hbs._compileTemplate = function (template, options) {
var results = yfm(template); //parse yfm
var compiled = this.handlebars.compile(results.content, options); //compile without yfm
@dhollenbeck
dhollenbeck / handlebars-helper.js
Last active November 5, 2016 18:02
Handlebars Each New Line (nl2br)
// does not support named parameters
exports.eachNewLine = function (str, options) {
var accum = '';
var data = Handlebars.createFrame(options, options.hash);
var arr = str.split(/\r?\n/);
arr.map(function(str) {
if (str) accum += options.fn(str.trim(), {data: data});
});
return accum;
@dhollenbeck
dhollenbeck / on-delete-redirect.js
Last active November 14, 2016 11:27
Express on delete redirect
// This gist shows how to handle multiple redirect options after a delete resource.
app.get('/parents/:parent_id/resources', function(req, res){
req.flash('on-del-resource', req.originalUrl);
res.render('parents/index')
});
app.get('/resources', function(req, res){
req.flash('on-del-resource', req.originalUrl);
res.render('resources/index')
@dhollenbeck
dhollenbeck / clear.js
Last active February 23, 2018 22:09
codemirror clear
var el = $('.CodeMirror');
var editor = var editor = el[0].CodeMirror;
var value = '';
editor.setValue(value);
editor.save();
var div = editor.getWrapperElement()
div.hide();
@dhollenbeck
dhollenbeck / .bash_profile
Created October 18, 2018 20:16
Bash Profile
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
default_username='dan'
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi