Skip to content

Instantly share code, notes, and snippets.

View benjamincharity's full-sized avatar
🤖

Benjamin Charity benjamincharity

🤖
View GitHub Profile
@benjamincharity
benjamincharity / ngShowFilter.html
Created May 27, 2015 16:54
Use ng-show rather than ng-repeat's filter for better performance.
<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 June 2, 2015 19:00
Http post with external request object.
var req = {
method: 'POST',
url: ENV.API_END_POINT + '/users',
headers: {
'Authorization': 'Basic ' + Base64Service.encode(mUser + ':' + mPass)
},
data: user
};
$http(req)
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;
var input = 4.537;
var result = parseFloat(Math.round(num3 * 100) / 100).toFixed(2); // 4.54
@benjamincharity
benjamincharity / triangle.scss
Created June 17, 2015 11:16
SCSS Triangle mixin.
/*
* @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: '';
@benjamincharity
benjamincharity / currency.scss
Created June 17, 2015 11:17
Format currency.
%currency {
position: relative;
&:before {
content: '$';
position: relative;
left: 0;
}
}
@mixin tooltip(
$content: attr(data-tooltip),
$direction: top
) {
position: relative;
&:before, &:after {
display: none;
z-index: 98;
}
@benjamincharity
benjamincharity / flipCalendar
Created June 23, 2015 19:38
Create a 90 day calendar.
/* 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: {
// 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 August 29, 2015 14:23
A filter that turns an array of integers into weekday names.
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\'';
}