Skip to content

Instantly share code, notes, and snippets.

View JonCatmull's full-sized avatar

Jon Catmull JonCatmull

View GitHub Profile
@JonCatmull
JonCatmull / relative-date.pipe.ts
Created December 21, 2016 10:38
Relative date Pipe for Angular2 + TypeScript . Convert date|timestamp into relative date string e.g. "5 days ago", "1 minute ago" etc.
import { Pipe, PipeTransform } from '@angular/core';
// Epochs
const epochs: any = [
['year', 31536000],
['month', 2592000],
['day', 86400],
['hour', 3600],
['minute', 60],
['second', 1]
@JonCatmull
JonCatmull / line-height.plugin.js
Last active November 26, 2018 12:02 — forked from aaerofeev/line_height.js
Froala Editor line-height plugin
/*!
* Froala Line Height plugin
* froala_editor v2.7.1 (https://www.froala.com/wysiwyg-editor)
*/
!function (a) {
"function" == typeof define && define.amd ? define(["jquery"], a) : "object" == typeof module && module.exports ? module.exports = function (b, c) {
return void 0 === c && (c = "undefined" != typeof window ? require("jquery") : require("jquery")(b)), a(c), c
} : a(jQuery)
}(function (a) {
@JonCatmull
JonCatmull / lighthouse-compose-import.sh
Created September 6, 2018 15:14
lighthouse compose
curl -o lightsail-compose.sh https://raw.githubusercontent.com/JonCatmull/docker/master/lightsail-compose.sh
chmod +x ./lightsail-compose.sh
./lightsail-compose.sh
@JonCatmull
JonCatmull / smart-date.pipe.ts
Created December 21, 2016 10:50
Relative date Pipe for Angular2 + TypeScript . Convert date or timestamp into relative date string e.g. "5 days ago" or to local date string e.g. "11/12/2016"
import { Pipe, PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';
import { RelativeDatePipe } from './relative-date.pipe'; // https://gist.github.com/JonCatmull/e00afb1c96298a4e386ea1b5d091702a
const secondsInAday = 86400;
/*
* Turn Date into realtive date (e.g. "5 days ago") unless date is
* more than relativeMax days ago.
@JonCatmull
JonCatmull / _responsive-sprite.scss
Last active December 21, 2016 10:20
Create a responsive sprite map with support for svg and png. Uses modernizer for png fallback.
@mixin responsive-sprite($img, $icon-classes, $horizontal: true) {
$icon-number: ceil(length($icon-classes));
$moveby: 100% / ($icon-number - 1); // one less that actual amount
background-image: url('#{$img}');
background-position: 0 0;
background-repeat: no-repeat;
@if $horizontal {
@JonCatmull
JonCatmull / harlem-konami.js
Created May 25, 2016 10:16
harley shake konami
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
$(document).unbind('keydown',arguments.callee);
@JonCatmull
JonCatmull / angular-pagination.directive.js
Last active February 17, 2016 10:35
Angular directive to generate pagination numbers. Allows setting of max numbers to display and it will keep the first and last page visible.
(function() {
'use strict';
angular
.module('fcp')
.directive('pagination', pagination);
/** @ngInject */
function pagination() {
var directive = {
@JonCatmull
JonCatmull / itemFirst.filter.js
Created January 28, 2016 10:42
Angular filter - Move an array item to first position but preserve the rest of the lists order (only set up for basic array of either integers or strings)
(function() {
'use strict';
angular
.module('fcp')
.filter('itemFirst', itemFirst);
/** @ngInject */
function itemFirst($filter) {
@JonCatmull
JonCatmull / gmaps-draggable.js
Last active August 29, 2015 14:23
Google maps draggable with geolocate
/**
*
* Google Map
*-------------------------------------
*/
$('.googleMap').each(function() {
var $map = $(this),
lat = ($map.attr('data-lat') ? parseFloat($map.data('lat')) : 0),
lng = ($map.attr('data-lng') ? parseFloat($map.data('lng')) : 0),
@JonCatmull
JonCatmull / js-object-guide.js
Last active August 29, 2015 14:21
Guide for creating objects in JavaScript
var ExampleObject = function()
{
var privateStaticMethod = function() {};
var privateStaticVariable = "foo";
var constructor = function ExampleObject(foo, bar)
{
var = privateProperty = foo;
this.publicProperty = bar;