Skip to content

Instantly share code, notes, and snippets.

View Shipow's full-sized avatar

Kevin Granger Shipow

View GitHub Profile
@Shipow
Shipow / toFixedNumber.js
Created August 4, 2015 13:13
Native like function to return number with fixed float
Number.prototype.toFixedNumber = function(x, base){
var pow = Math.pow(base||10,x);
return +( Math.round(this*pow) / pow );
}
@Shipow
Shipow / humanize.js
Last active August 29, 2015 14:17 — forked from maggiben/humanize.js
angular.module('humanize', [])
.filter('humanize', function(){
return function humanize(number) {
if(number < 1000) {
return number;
}
var si = ['K', 'M', 'G', 'T', 'P', 'E'];
var exp = Math.floor(Math.log(number) / Math.log(1000));
var result = number / Math.pow(1000, exp);
result = (result % 1 > (1 / Math.pow(1000, exp - 1))) ? result.toFixed(2) : result.toFixed(0);
@Shipow
Shipow / tsvtojson.js
Created March 16, 2015 14:06
TSV to JSON
var tsvToJson = function(input){
var info = input.replace(/['"]/g,''),
lines = info.split('\n'),
firstLine = lines.shift().split('\t'),
json = [];
// Helper function to remove quotes
// and parse numeric values
var removeQuotes = function(string){
string = string.replace(/(['"])/g, "\\$1");
@Shipow
Shipow / ng-lazy-load
Last active August 29, 2015 14:16
Angular Lazy load images with cache detection
app.directive('imgPreload', ['$timeout', function($timeout) {
return {
restrict: 'A',
scope: {
ngSrc: '@'
},
link: function(scope, element, attrs) {
var loaded = false;
element.on('load', function() {
loaded = true;
@Shipow
Shipow / vertical-align.sass
Created July 26, 2014 15:10
Sass - Vertical Align
.parent-element
-webkit-transform-style: preserve-3d
-moz-transform-style: preserve-3d
transform-style: preserve-3d
@mixin vertical-align
position: relative
top: 50%
-webkit-transform: translateY(-50%)
-ms-transform: translateY(-50%)
@Shipow
Shipow / cdn-fallback.js
Created April 9, 2014 07:58
CDN fallback
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script>
window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js">\x3C/script>')
</script>
@Shipow
Shipow / FloatClearing.sass
Created March 10, 2014 16:48
Sass - Float Clearing
@mixin clear()
&:before, &:after
content: "\0020"
display: block
height: 0
overflow: hidden
&:after
clear: both
@Shipow
Shipow / ng.filter.orderObjectBy.js
Last active December 30, 2015 20:19
Angular filter orderObjectBy
app.filter('orderObjectBy', function(){
return function(input, attribute) {
if (!angular.isObject(input)) return input;
var array = [];
for(var objectKey in input) {
array.push(input[objectKey]);
}
array.sort(function(a, b){
a = parseInt(a[attribute]);
b = parseInt(b[attribute]);
@mixin text-truncate
overflow: hidden
text-overflow: ellipsis
white-space: nowrap
@Shipow
Shipow / SASS: Clearfix
Last active December 26, 2015 14:39
SASS: Clearfix
@mixin clearfix()
&
*zoom: 1
&:before,
&:after
content: ""
display: table
&:after
clear: both