Skip to content

Instantly share code, notes, and snippets.

View JonCatmull's full-sized avatar

Jon Catmull JonCatmull

View GitHub Profile
@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;
@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 / redactor-chrome-span-fix.js
Created August 26, 2015 08:28
Fix for redactor in chrome
// Place inside setEvents: function() { on line 1361
// Check for chrome span bug
this.$editor.on("DOMNodeInserted", $.proxy(function(e) {
if (e.target.tagName == "SPAN" ) {
console.log('clean spans');
var helper = $("<b>helper</b>");
$(e.target).before(helper);
@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 / 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 / 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 / file-size.pipe.ts
Last active April 14, 2024 14:27
Angular2 + TypeScript file size Pipe/Filter. Convert bytes into largest possible unit. e.g. 1024 => 1 KB
/**
* @license
* Copyright (c) 2019 Jonathan Catmull.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@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 / 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 / ordinal.pipe.ts
Last active January 12, 2024 16:09
Appends ordinal (st, nd ,rd ,th) to number or turns number into ordinal. Typescript Angular2 Pipe
import { Pipe, PipeTransform } from '@angular/core';
const ordinals: string[] = ['th','st','nd','rd'];
/*
* Append ordinal to number (e.g. "1st" position)
* Usage:
* value | ordinal:keepNumber
* Example:
* {{ 23 | ordinal}}