Skip to content

Instantly share code, notes, and snippets.

View cbumgard's full-sized avatar

Chris Bumgardner cbumgard

  • San Francisco, CA
View GitHub Profile
@cbumgard
cbumgard / date-range-form.html
Last active January 25, 2016 10:21
Date Range Form with Validation. Live demo: http://jsfiddle.net/chrisbumgardner/VzYQn/2/embedded/result/. Built with jQuery, jQuery UI DatePicker, jQuery Validation, and Zurb Foundation This form allows choosing a date range from any previous day up to and including today's date. When a start date is selected, the end date cannot come before it.…
<br>
<div class="container">
<div class="row">
<div class="six columns">
<h2>Date Range Form</h2>
<h5 class="small">By <a href="https://gist.github.com/cbumgard/4742703" target="_blank">Chris Bumgardner</a></h5>
<h3 class="subheader">Built with <a href="http://jquery.com/" target="_blank">jQuery</a>, <a href="http://api.jqueryui.com/datepicker/" target="_blank">jQuery UI DatePicker</a>, <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank">jQuery Validation</a>, and <a href="http://foundation.zurb.com/" target="_blank">Zurb Foundation</a></h3>
<h5><a href="http://jsfiddle.net/chrisbumgardner/VzYQn/" target="_blank">See the jsFiddle</a></h5>
@cbumgard
cbumgard / funcy-fizzbuzz.js
Created December 15, 2012 19:53
FizzBuzz in Javascript using pattern-matching library Funcy (https://github.com/bramstein/funcy). Inspired by this Clojure example: https://github.com/clojure/core.match.
var fun = require('funcy')
, _ = fun.wildcard
, n;
for (n = 1; n <= 100; n++) {
console.log(
fun(
[[0, 0], function() { return 'FizzBuzz'; }],
[[0, _], function() { return 'Fizz'; }],
[[_, 0], function() { return 'Buzz'; }],
[_, function() { return n; }]
@cbumgard
cbumgard / fizzbuzz.js
Created December 15, 2012 19:09
another javascript fizzbuzz
var fizz, buzz, fizzbuzz, n;
for (n = 1; n <= 100; n++) {
fizz = !(n % 3);
buzz = !(n % 5);
fizzbuzz = fizz && buzz;
console.log(
fizzbuzz ? 'FizzBuzz' :
(fizz ? 'Fizz' :
(buzz ? 'Buzz' : n)));
}​
@cbumgard
cbumgard / date-util.js
Created December 11, 2012 01:03
Formatting dates/times in node.js using Olson timezones and moment.js. Converts server-side timestamps to the browser's timezone.
var moment = require('moment');
var tz = require('timezone/loaded');
var time = require('time');
module.exports = function() {
var strftime_format = '%F %T %z'; // used to convert a date into a normalized strftime format with timezone
var moment_format = 'YYYY-MM-DD HH:mm:ss zz'; // moment.js LDML format for parsing date strings
/**
* Convert a Javascript Date into node-time wrapper with the appropriate timezone.
@cbumgard
cbumgard / fizzbuzz.js
Created November 30, 2012 20:45
FizzBuzz solution in JavaScript in < 5 minutes
var output, i;
for (i = 1; i <= 100; i++) {
output = '';
i % 3 === 0 ? output += 'Fizz' : output;
i % 5 === 0 ? output += 'Buzz' : output;
output === '' ? output = i : output;
console.log(output);
}​
@cbumgard
cbumgard / gist-form-input.html
Last active October 13, 2015 03:08
"gist" URL jQuery validator method for form inputs
<!-- Put a text input to be validated into a form. Make sure it has the class "gist" for the validator. -->
<input id="inputGistUrl" type="text" name="gist_url" placeholder="https://gist.github.com/1234567" class="required gist">
@cbumgard
cbumgard / awesome-app-content.jade
Created November 18, 2012 02:35
node-boot hello world homepage
.container
.featurette
h2.featurette-heading Welcome to #{title}
p.lead Everything appears to be running correctly. Here's something for your entertainment.
a(href='http://xkcd.com/163/')
img(src='http://imgs.xkcd.com/comics/donald_knuth.png')
hr.featurette-divider
@cbumgard
cbumgard / get_started
Last active October 12, 2015 20:38
Cloning and running node-boot
git clone https://github.com/cbumgard/node-boot
cd node-boot/
npm install
grunt dev
node app.js
@cbumgard
cbumgard / index.js
Created November 15, 2012 02:20
Dynamic config module for node.js apps to simplify managing configurations for different environments. Reads in a config file matching the current NODE_ENV.
// This module loads a config file in the current working directory matching the NODE_ENV variable.
// I.e. either './development.js' or './production.js' based on the process.env.NODE_ENV variable.
// If not set, it defaults to './development.js'.
// Can load custom environment files as well, as long as the NODE_ENV variable matches
// a file in the current directory. E.g. './staging.js'
// Usage: calling code can just require this module, e.g. "var config = require('./config')"
// assuming this file is named "index.js" and lives in a subdirectory named "config" of the app root.
var config
, config_file = './' + (process.env.NODE_ENV ? process.env.NODE_ENV : 'development') + '.js';