Skip to content

Instantly share code, notes, and snippets.

View nelsonpecora's full-sized avatar

Nelson Pecora nelsonpecora

View GitHub Profile
@nelsonpecora
nelsonpecora / typechecker.js
Last active August 29, 2015 13:55
A convenience function for checking the *actual* type of a javascript variable
// convenience function for type checking
window.is = function(type, obj) {
var result = Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
return obj !== undefined && obj !== null && result === type;
// e.g. is('string', foo);
}
@nelsonpecora
nelsonpecora / directive.js
Created January 30, 2014 19:10
Where to put link method(s) if you have a compile method
var app = angular.module('app', []);
// without compile:
app.directive('myDir', function() {
return {
restrict: 'A',
link: function() {
//postlink stuff
}
}
@nelsonpecora
nelsonpecora / hover.css
Last active August 29, 2015 13:56
Trying to find the best hack to display :hover styles only on devices where you can actually hover.
a, a:visited {
color: #009bff;
text-decoration: none;
cursor: pointer;
outline: none;
-webkit-transition: color 200ms ease-out;
-moz-transition: color 200ms ease-out;
-ms-transition: color 200ms ease-out;
-o-transition: color 200ms ease-out;
// define bolster js files (for concat and jshint)
var bolsterFiles = [
'wp-content/themes/bolster2/js/app.js',
'wp-content/themes/bolster2/js/services.js',
'wp-content/themes/bolster2/js/directives.js',
'wp-content/themes/bolster2/js/filters.js',
'wp-content/themes/bolster2/js/controllers.js'
];
// configure grunt
// transform newlines into <br /> tags
app.filter('newlines', ['$sce', function ($sce) {
return function(text) {
var t = text.replace(/\n/g, '<br/>');
return $sce.trustAsHtml(t)
}
}]);
@nelsonpecora
nelsonpecora / proxy-unit-test.coffee
Created February 27, 2014 16:13
A simple unit test for a proxy service, written in coffeescript. Note the use of Jasmine spies.
# Proxy
describe 'Proxy Service', ->
proxy = null
$httpBackend = null
mockGrowl =
addSuccessMessage: ->
addErrorMessage: ->
returnedData =
grunt.registerTask 'marcom-css',
'less:marcomCSS'
'autoprefixer:marcomCSS'
'cmq:marcomCSS'
'cssmin:marcomCSS'
$urlRouterProvider.otherwise(function($injector, $location) {
window.location.href = $location.$$absUrl;
});
try {
angular.module('ngSanitize');
// module js exists!
if(!myModule.requires.indexOf('ngSanitize')) myModule.requires.push('ngSanitize');
// checks to see if ngSanitize is injected, else injects it
} catch(e) {
// just use whatever other module people want
}
@nelsonpecora
nelsonpecora / typeOf.coffee
Last active August 29, 2015 13:56
Douglas Crockford's convenience function for type checking, rewritten in coffeescript. 'Cause that's how we roll.
window.typeOf = (value) ->
s = typeof value
if s == 'object'
if value
if Object.prototype.toString.call(value) == '[object Array]' then 'array' else 'object'
else 'null'
else return s