Skip to content

Instantly share code, notes, and snippets.

View wholypantalones's full-sized avatar

Jason Dare wholypantalones

View GitHub Profile
@wholypantalones
wholypantalones / unique.js
Created September 29, 2015 19:45
Angular unique filter
.filter('unique', function () {
return function (items, filterOn) {
if (filterOn === false) {
return items;
}
if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
var hashCheck = {}, newItems = [];
@wholypantalones
wholypantalones / deferMaps.js
Created August 24, 2015 19:58
Lazyload Google Maps Angular Service
/*
usage:
Initializer.mapsInitialized.then(function(){
initMap(); // do stuff with maps
});
*/
angular.module('ngApp', []).
factory('Initializer', function($window,$q){
var asyncUrl = '//maps.googleapis.com/maps/api/js?callback=',
mapsDefer = $q.defer();
@wholypantalones
wholypantalones / alpha-numeric.js
Created July 20, 2015 13:53
Capitalized AlphaNumeric Directive
.directive('onlyAlpha', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function (inputValue) {
if (inputValue == undefined) return '';
var transformedInput = inputValue.replace(/[\W_]+/g,'').toUpperCase();
if (transformedInput!=inputValue) {
modelCtrl.$setViewValue(transformedInput);
modelCtrl.$render();
@wholypantalones
wholypantalones / form-hijack.js
Last active August 29, 2015 14:19
Dynamic form post using angular w/ action
<form class="form-horizontal" name="chkForm" method="post" action="/this/is/an/action/" ng-submit="processThis(chkForm.$valid,$event)" novalidate>
/* the processThis function fires before the form action submits so we can hijack it. Passing $event allows for event.preventDefault() to be used
in the function in order to stop the form posting. https://docs.angularjs.org/api/ng/directive/ngSubmit
*/
</form>
//in controller
$scope.processThis = function(isValid,e) {
if(isValid) {
e.preventDefault();
@wholypantalones
wholypantalones / uLangLang.js
Created March 3, 2015 21:00
Get browser language preference
var lang = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage);
@wholypantalones
wholypantalones / ecma-ie8.js
Last active August 29, 2015 14:16
ECMA Compats for < IE8
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@wholypantalones
wholypantalones / autofill.js
Created February 16, 2015 20:29
AutoFill
javascript:%20{var%20d=window.location.hostname;var%20h=d.split('.');var%20x=h[1]+'.'+h[2];document.activeElement.value='fuckoff@'+x;void(0)};
@wholypantalones
wholypantalones / dateUTC.js
Created February 4, 2015 15:19
Take a moment and format your date to UTC
moment().utc().format('YYYY-MM-DD[T]HH:mm:ss[Z]').toString();
@wholypantalones
wholypantalones / mapObjects.js
Last active August 29, 2015 14:14
Get and fit the mutha f**king bounds of things on a google map
/*
mutha f**king angular-google-maps
http://angular-ui.github.io/angular-google-maps/#!/api
*/
$scope.findSquare = function(index) {
var boundaryLatLng = new google.maps.LatLngBounds(),
thisBounds = [];
// or do a forEach here for multiples
thisBounds.push(
@wholypantalones
wholypantalones / hexidecimal.js
Last active February 3, 2016 20:43
Six digit random hex color generator
// http://www.paulirish.com/2009/random-hex-color-code-snippets/
'#'+('000000' + Math.floor(Math.random()*16777215).toString(16)).slice(-6)