Skip to content

Instantly share code, notes, and snippets.

View jimmont's full-sized avatar

Jim Montgomery jimmont

View GitHub Profile
@jimmont
jimmont / diff
Last active August 29, 2015 14:09
what changed from the default
function diff(defaults, customs, diffs){
/**
* @description
compare an object against the default returning an object with the differences
in the customs object separated out in the returned value
when there are no unique values in the customs object undefined is returned
* @returns
diff value, when no differences undefined, when an object returns object with keys and other values
* @example
usr.diff(defaults, custom);
(function() {
'use strict';
angular.module('derModule')
.directive('inputRange', ['$parse', function ngRangeSlider($parse) {
/**
* @ngdoc directive
* @name input-range
* @description
dual-control range inputs
* @example
@jimmont
jimmont / ng-expressions.html
Last active August 29, 2015 14:05
Angular expression collection. Or something like that.
<script>
$scope.ping;
$scope.j = 4;
$scope.stuff = [3,7,1,0];
$scome.time = new Date
</script>
<hr ng-init="ping=[1,2,3]" ng-bind="::once" ng-attr-j="::{{ 1 + jOnce }}" ng-repeat="a in b = (stuff | orderBy: 'toString()' ) track by $index">
<time ng-attr-title="{{ time | date:'EEEE MMMM d, yyyy h:mm:ss a (\'GMT\'Z)' }}">{{time | date:'MM/dd/yy HH:mm:ss'}}</time>
@jimmont
jimmont / sumArray-ng-filter.js
Created August 13, 2014 03:06
Infinity number error handling in Angular filters for pass-thru. Positive stuff!
/**
* @ngdoc filter
* @name sumArray
* @description
* return the sum of a list of values (no explicit type coercion)
*
* @example
expression:
`we have {{ [1, 2, 3] | sumArray }} items`
@jimmont
jimmont / anagramDetector
Last active August 29, 2015 14:02
your anagrams are showing doctor
/* usage: isAnagram('Elvis','lives'); */
function isAnagram(read,dear){
return read.toLowerCase().split('').sort().join('') === dear.toLowerCase().split('').sort().join('');
};
@jimmont
jimmont / detectTextFile.js
Created May 23, 2014 17:39
check if a file is text based on its content
// detect if a text file, like Perl's stat(file); if(-T) ...
fs.open(file,'r',function(err, fd){
if(err) return;
var len = 100;
var buf = new Buffer(len);
var re = /[.a-z0-9(){}\[\]? "':;<>?\s\n\r\t "':;#@~$%*<>.,_=+-]/ig;
fs.read(fd,buf,0,len,0,function(err,num,buf){
if(err || num < 1) return;
var str = buf.toString('utf-8',0,num);
// do we have enough of the types of characters typical of a text file?
@jimmont
jimmont / snippets.js
Last active October 2, 2016 23:09
snippet collection
// work with angular since Batarang is giving me problems
(function(){
function $scope($0){ $0 = angular.element(
typeof($0) === 'string' ? document.querySelectorAll($0) : $0
).scope(); $scope.$0 = $0; return $scope; }
window.$scope = $scope;
console.log('window.$scope($0) returns scope for element $0',$scope(document));
})();
// $http for convenient http requests
(function(){
@jimmont
jimmont / transitionEnd.js
Created May 3, 2014 20:34
transitionEnd attribute directive
/*
element{transition:height 500ms ease-out;height:10px;}
element.change{height:200px;}
<element transition-end="endTransition($event)"></element>
$scope.endTransition = function(e){ }
*/
.directive('transitionEnd', function($parse){
return {
restrict: 'A'
,link: function(scope,elem,attr){
@jimmont
jimmont / rAF.js
Last active December 17, 2015 03:29 — forked from paulirish/rAF.js
// paulirish, emoller et al. MIT license
window.requestAnimationFrame = window.requestAnimationFrame || function(callback, element){
var fn, cfn, w = window, lastTime = 0, v, vendors = 'webkit,moz,ms,o'.split(',');
while(!fn && (v = vendors.shift())){
fn = w[v+'RequestAnimationFrame'];
cfn = w[v+'CancelAnimationFrame'] || w[v+'CancelRequestAnimationFrame'];
};
w.requestAnimationFrame = fn || function(callback, element){
var id, currTime = new Date().getTime(), timeToCall = Math.max(0, 16 - (currTime - lastTime));