Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Charity benjamincharity

View GitHub Profile
@benjamincharity
benjamincharity / ngShowFilter.html
Created May 27, 2015
Use ng-show rather than ng-repeat's filter for better performance.
View ngShowFilter.html
<input type="text" data-ng-model="searchModel">
<li data-ng-show="(searchModel && ([contact.name.formatted]|filter:searchModel).length)">
{{ ::contact.name.formatted }}
</li
@benjamincharity
benjamincharity / httpPost.js
Created Jun 2, 2015
Http post with external request object.
View httpPost.js
var req = {
method: 'POST',
url: ENV.API_END_POINT + '/users',
headers: {
'Authorization': 'Basic ' + Base64Service.encode(mUser + ':' + mPass)
},
data: user
};
$http(req)
View dollarsToCents.js
angular.module('admin')
.directive('dollarsToCents', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
if(ngModel) { // Don't do anything unless we have a model
ngModel.$parsers.push(function(value) {
return value*100;
View roundToTwoDecimalPlaces.js
var input = 4.537;
var result = parseFloat(Math.round(num3 * 100) / 100).toFixed(2); // 4.54
View triangle.scss
/*
* @include triangle within a pseudo element and add positioning properties (ie. top, left)
* $direction: up, down, left, right
*/
@mixin triangle(
$direction: 'down',
$size: 6px,
$color: #222
){
content: '';
View currency.scss
%currency {
position: relative;
&:before {
content: '$';
position: relative;
left: 0;
}
}
View tooltip.scss
@mixin tooltip(
$content: attr(data-tooltip),
$direction: top
) {
position: relative;
&:before, &:after {
display: none;
z-index: 98;
}
@benjamincharity
benjamincharity / flipCalendar
Created Jun 23, 2015
Create a 90 day calendar.
View flipCalendar
/* global jQuery */
'use strict';
angular.module('clutch.directives').directive('flipCalendar',
function($state, $rootScope, ngDialog, $q, cfpLoadingBar) {
return {
restrict: 'A',
templateUrl: 'partials/authenticated/flip/calendar.html',
scope: {
View splitArray.js
// Prototype method
Array.prototype.chunk = function(chunkSize) {
var array=this;
return [].concat.apply([],
array.map(function(elem,i) {
return i%chunkSize ? [] : [array.slice(i,i+chunkSize)];
})
);
};
//
@benjamincharity
benjamincharity / weekdayFilter.js
Last active Aug 29, 2015
A filter that turns an array of integers into weekday names.
View weekdayFilter.js
angular.module('myModule')
.filter('weekdays', function() {
'use strict';
return function(day, length) {
// If length exists but doesn't match our keywords
if( length && length !== 'long' && length !== 'short' && length !== 'letter' ) {
return 'Length must be \'long\', \'short\' or \'letter\'';
}