Skip to content

Instantly share code, notes, and snippets.

View TravisMullen's full-sized avatar

Travis Mullen TravisMullen

View GitHub Profile
@TravisMullen
TravisMullen / hasRequiredAttributeSpec.js
Last active September 17, 2016 16:42
hasRequiredAttribute asmine Matchers
beforeEach(function() {
jasmine.addMatchers({
//
// actual: data object to check for property
//
// expected: property or property chain as string
//
hasRequiredAttribute: function() {
return {
compare: function(actual, expected) {
@TravisMullen
TravisMullen / animateCss.watcher.js
Last active January 16, 2017 21:11
Watcher for $animateCss (Angular 1.5)
'use strict';
// for use of 100% CSS but still want that angular layer
//
// assumes standard ngAnimate CSS class usage `ng-EVENT`
//
// .animation-watcher {
// /* this transition tells ngAnimate to make the animation happen */
.directive( 'stopEvent',
[ function() {
'use strict';
return {
restrict : 'A',
link : function(scope, element, attr) {
element.bind(attr.stopEvent, function(e) {
e.stopPropagation();
});
@TravisMullen
TravisMullen / load-animation-play-state.js
Created March 30, 2017 13:11
Making Animations Wait
// wait for document
document.body.className += " js-loading";
window.addEventListener("load", removeLoadingClass, false);
function removeLoadingClass() {
document.body.className = document.body.className.replace("js-loading","");
}
// wait for image
// Adjust the "querySelector" value to target your image
var img = document.querySelector("img");
@TravisMullen
TravisMullen / must-have-style-preprocessors.scss
Created April 6, 2017 20:39
A few small style Preprocessors in SCSS
// Angular Base Apps
// by Base Apps
// https://github.com/base-apps/angular-base-apps
// Licensed under MIT Open Source
// updated by Travis Mullen
//
$include-css: () !default;
$modules: () !default;
$rem-base: 16px !default;
@TravisMullen
TravisMullen / multiple-promises.js
Last active April 7, 2017 21:19
Multiple Promises
//
// https://developers.google.com/web/fundamentals/getting-started/primers/promises
//
// With Promises
let dis = this
return new Promise(function (resolve, reject) {
return this.promises.reduce(function (chain, individualPromise) {
return chain.then(function () {
return individualPromise
}).then(function (value) {
@TravisMullen
TravisMullen / mongo-docker.bash
Created April 30, 2017 04:42 — forked from davideicardi/mongo-docker.bash
Running mongodb inside a docker container (with mongodb authentication)
# Create a container from the mongo image,
# run is as a daemon (-d), expose the port 27017 (-p),
# set it to auto start (--restart)
# and with mongo authentication (--auth)
# Image used is https://hub.docker.com/_/mongo/
docker pull mongo
docker run --name YOURCONTAINERNAME --restart=always -d -p 27017:27017 mongo mongod --auth
# Using the mongo "localhost exception" (https://docs.mongodb.org/v3.0/core/security-users/#localhost-exception)
# add a root user
@TravisMullen
TravisMullen / CallToAction.vue
Created May 6, 2017 06:44
"Call-to-action" SVG Component Vue.js
<template lang="pug">
router-link.button.large(:to='route')
| {{ message }}
.svg-icon.postfix.fill-white(
v-once='',
v-html='icon'
)
</template>
<script>
@TravisMullen
TravisMullen / InputDebounce.js
Created May 6, 2017 06:50
debounce function for Vuejs from Docs
// https://vuejs.org/v2/guide/migration.html#debounce-Param-Attribute-for-v-model-removed
/*
By using the debounce function from lodash or another dedicated
utility library, we know the specific debounce implementation we
use will be best-in-class - and we can use it ANYWHERE. Not just
in our template.
*/
new Vue({
el: '#debounce-search-demo',
// truncate text
function trimMiddle (text, maxLength, div) {
const d = div || ' '
const l = text.length
let t
let a
let b
if (l > maxLength) {
a = Math.floor((maxLength / 2) - 1)