Skip to content

Instantly share code, notes, and snippets.

@mcranston18
mcranston18 / directive_isFocused
Last active December 16, 2015 19:19
AngularJS Directive to Validate Field After User Has Left It
App.directive('isFocused', function(){
var isFocused = {
restrict: 'A',
scope: {
model: '=isFocused'
},
link: function(scope, element, attrs) {
scope.model = false;
element.focus(function(){
@mcranston18
mcranston18 / directive_scrollSpy
Created October 30, 2013 15:15
Angular directive for scroll spy
'use strict';
angular.module('AppSuccess')
.directive('scrollSpy', ['$window', function ($window) {
return {
restrict: 'A',
link: function (scope, element) {
// Get offset before scrollSpy activates
// otherwise offset of element would change
@mcranston18
mcranston18 / directive_verticalAlign
Created October 30, 2013 15:20
Directive to vertically align in CSS
app.directive('verticalAlign', function () {
return {
restrict: 'A',
link: function (scope, elm, attrs) {
var childHeight = elm[0].clientHeight;
var parentHeight = elm[0].parentElement.clientHeight;
var offset = (parentHeight - childHeight) / 2;
elm[0].style.paddingTop = offset + 'px';
}
}
var webdriver = require('browserstack-webdriver');
var browserNameList : ['firefox', 'chrome', 'opera'];
for(i = 0; i < browserList; i++) {
// Input capabilities
var capabilities = {
'browserName' : browserNameList[i],
'browserstack.user' : 'xxx',
var assert = require('assert'),
fs = require('fs');
var webdriver = require('browserstack-webdriver'),
test = require('browserstack-webdriver/testing');
var browserNameList = ['ie', 'firefox', 'opera'];
for(i = 0; i < browserNameList.length; i++) {
test.describe('Google Search', function() {
@mcranston18
mcranston18 / SampleAngularCtrl
Last active August 29, 2015 14:03
This is a sample Angular controller demonstrating a possible way to organize your CRUD operations.
'use strict';
angular.module('app.photo')
.controller('EditPhotoCtrl', function($scope, $state, $location, $window,
UserService, PhotoService, UtilitiesService) {
/**
* INIT VALUES
*/
'use strict';
angular.module('app.picture')
.directive('pictureList', function() {
return {
restrict: 'E',
scope: {
pictures: '='
@mcranston18
mcranston18 / gist:c14bffa5caa3a5398fa5
Last active August 29, 2015 14:05
Sample Angular Test
'use strict';
describe('PhotoCtrl', function() {
var ctrl, rootScope, scope, q, Mock;
beforeEach(angular.mock.module('app.photo', 'ui.router'));
beforeEach(inject(function($controller, _$rootScope_, _$location_, _$state_, _$q_) {
beforeEach(inject(function(_) {
underScoreService = _;
}));
it('should do something', function () {
expect(underScoreService).toBe(true);
});
var git = require('gulp-git');
var inject = require('inject-string');
// This successfully returns my git hash
gulp.task('hash', function() {
git.revParse({args:'--short HEAD'}, function (err, hash) {
return hash;
});)
})