Skip to content

Instantly share code, notes, and snippets.

@vespoli
vespoli / time-ago-filter.js
Created December 18, 2016 23:38
Time ago filter for Angular
angular
.module('foo', [])
.filter('timeAgo', function() {
return function(s) {
var d = new Date(s);
var seconds = Math.floor((new Date() - d) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {return interval + " years ago";}
if (interval === 1) {return interval + " year ago";}
@vespoli
vespoli / random-content.jade
Created August 10, 2014 17:04
Random content generator utility for jade templates. Accepts config options for min, max, type and punctuation
- var randomContent = function(config){
- var RandomContentConfig = function(config){ //- override defaults with passed in config
- var config = config || {};
- this.type = config.type || 'text';
- this.min = config.min || 10;
- this.max = config.max || 100;
- this.punctuation = typeof(config.punctuation) !== 'undefined' ? config.punctuation : true;
- };
- var puncChance = .0001;
- var c = new RandomContentConfig(config); //- config object
@vespoli
vespoli / date.toMMDDYYYY
Created February 5, 2014 18:08
Date: Format JavaScript date to MM/DD/YYYY
Date.prototype.toMMDDYYYY = function (key) {
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
return f(this.getUTCMonth() + 1) + '/' +
f(this.getUTCDate()) + '/' +
this.getUTCFullYear();
};
@vespoli
vespoli / date.time_ago.js
Last active August 29, 2015 13:56
Time ago - Returns a string with a string containing an approximation time since the date. ie: "5 minutes", "2 days", "10 years"
Date.prototype.timeAgo = function(){
var seconds = Math.floor((new Date() - this) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {return interval + " years";}
if (interval === 1) {return interval + " year";}
interval = Math.floor(seconds / 2592000);
if (interval > 1) { return interval + " months";}
if (interval === 1) {return interval + " month";}
@vespoli
vespoli / parallax
Last active January 4, 2016 02:28
Light weight parallax that uses images not background images and just what I needed. WIll post markup and css later. Needs cleanup too. Expects element to be passed containing the image used as the background. kind of specific for now.
(function ($) {
var $window = $(window);
var windowHeight = $window.height();
var Parallax = function (element, options) {
var $this = $(element);
var $img = $this.find('img:first');
var obj = this;
var thisTop, maxOffset, thisHeight;
@vespoli
vespoli / dataservice
Last active January 3, 2016 04:39
Data service class pattern for web service heavy front end projects. Supports calls to multiple sources with a single callback.
/*******************************************************************************
* Global data service utility "class"
*******************************************************************************/
NAMESPACE.DataService = function(){
var foo = {
set : function(obj, callback, errorConfig){
var payload = JSON.stringify(obj),
config = {
url: '/foo/update/',
@import "grid_settings";
* {
-webkit-box-sizing: border-box; /* Android ≤ 2.3, iOS ≤ 4 */
-moz-box-sizing: border-box; /* Firefox 1+ */
box-sizing: border-box; /* Chrome, IE 8+, Opera, Safari 5.1 */
}
/* The Grid ---------------------- */