Skip to content

Instantly share code, notes, and snippets.

@ahmedam55
ahmedam55 / gist:183ac065be9b7dd2ce5f
Created January 2, 2015 13:14
SPA problem with setIntervals and animation
for(var i=0;i<99999;i++){
clearInterval(i);
clearTimeout(i);
}
anonymous
anonymous / index.html
Created February 21, 2015 20:16
JS Bin Custom Directive Chart // source http://jsbin.com/cafapi
<!DOCTYPE html>
<html ng-app="chart">
<head>
<meta name="description" content="Custom Directive Chart">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
label{
width:55px;
@psymeon
psymeon / inViewport.js
Created September 3, 2014 12:40
Simple jQuery function that determines whether DOM element is in the browser's viewport.
// Custom jQuery function.
// Determines if element is withing the viewport.
$.fn.inViewport = function() {
$el = this;
var elTop = $el.offset().top;
var elBot = elTop + $el.outerHeight(true);
var winScrollTop = $(window).scrollTop();
var winHeight = $(window).height();
var inViewport = winScrollTop <= elBot && (winScrollTop + winHeight) >= elTop;
return inViewport;
@c0bra
c0bra / gist:5859295
Created June 25, 2013 15:15
ngVisible angular directive
.directive('ngVisible', function () {
return function (scope, element, attr) {
scope.$watch(attr.ngVisible, function (visible) {
element.css('visibility', visible ? 'visible' : 'hidden');
});
};
})
@number5
number5 / git-log.md
Last active July 9, 2019 21:40
pretty git log with relative dates and tags

My git log alias

alias gl='git log --graph --pretty=format:'%C(magenta)%h%Creset %w(72,1,2)%Cgreen(%cr) -%C(bold green)%d%Creset %s %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative'

gl screenshot

@armandocanals
armandocanals / largeSum.js
Created May 2, 2016 23:50
Sum Large Numbers in JavaScript
function add(num1, num2) {
num1 = num1.split('');
num2 = num2.split('');
num1 = num1.map(function (num) {
return parseInt(num, 10);
});
num2 = num2.map(function (num) {
return parseInt(num, 10);
@janit
janit / sw.js
Last active October 31, 2019 11:26
Service Worker example for controlling what is cached - See https://malloc.fi/fix-duplicate-redirects-service-worker-caching
self.addEventListener('install', function (event) {
event.waitUntil(preLoad());
});
var preLoad = function () {
// console.log('[PWA Builder] Install Event processing');
return caches.open('pwabuilder-offline').then(function (cache) {
// console.log('[PWA Builder] Cached index and offline page during Install');
return cache.addAll(['/offline.html', '/']);
});
@xurizaemon
xurizaemon / dynamic-variable-names.scss
Created September 19, 2012 22:56
i wanted dynamic variable names in sass. it doesn't do everything i expected. sadface panda needs to get hacking.
$whatson: #ed8f25;
$whatsonBg: lighten($whatson, 20%);
$childcare: #7c398a;
$childcareBg: lighten($childcare, 40%);
$health: #9cc700;
$healthBg: lighten($health, 30%);
$shopping: #0065fd;
$shoppingBg: lighten($shopping, 30%);
$groups: #cb0033;
$groupsBg: lighten($groups, 50%);
@ngmaloney
ngmaloney / get_meta_description.js
Created June 27, 2011 21:07
A Javascript function used to extract meta description from an HTML document.
/**
* Returns document meta description
*/
getMetaDescription = function() {
var metas = document.getElementsByTagName('meta');
for(var i in metas) {
if (typeof(metas[i].name) != 'undefined' && metas[i].name.toLowerCase() == "description") {
return encodeURIComponent(metas[i].content);
}
}