Skip to content

Instantly share code, notes, and snippets.

@a-laughlin
a-laughlin / test-gist.js
Created November 17, 2011 18:42
Test File - Moving SVN projects to Git.
var foo='test', barObj;
function bar(){
return {baz:'bop',bazReg:/^bop$/}
};
bar.prototype.someArray=[1,2,3,null,undefined,false,true,!!1,void 0,'#foo',bar];
barObj=new Bar();
@a-laughlin
a-laughlin / jquery.fisheyegrid.js
Created December 1, 2011 05:18
Fisheye Grid UI Design Pattern in jQuery
/*!
* jQuery Fisheye Grid version 0.01
* Copyright 2011, Adam Laughlin
* http://a-laughlin.com
* Licensed under MIT & GPL version 2
* http://static.a-laughlin.com/mit_license.txt
* http://static.a-laughlin.com/gpl_license.txt
*/
/*
@a-laughlin
a-laughlin / jquery.multi-pubsub.js
Created December 2, 2011 06:28
Multi-dependency pubsub with jQuery.Callbacks() and jQuery.Deferreds()
/*!
* jQuery multi-dependency pubsub v0.01
* Copyright 2011, Adam Laughlin
* http://a-laughlin.com
* Licensed under MIT & GPL version 2
* http://static.a-laughlin.com/mit_license.txt
* http://static.a-laughlin.com/gpl_license.txt
*
* inspired by Addy Osmani's example at:
* http://addyosmani.com/blog/jquery-1-7s-callbacks-feature-demystified/
@a-laughlin
a-laughlin / gist:7065031
Created October 20, 2013 04:19
Simple utility to get selected text in a page
;(function(win,doc){
function _getSelectedText (){
_getSelectedText = win.getSelection ? // redefine itself when first run
win.getSelection :
doc.getSelection ?
doc.getSelection:
doc.selection ?
function(){return doc.selection.createRange().text;} :
function(){return '';};
@a-laughlin
a-laughlin / gist:6a009b290909b0d33de9
Created May 27, 2014 01:33
AngularJS - simple example of how services, factories, and values work
// how services, factories, and values work
var foo = {
providers:{},
instances:{},
provider:function(name,fn){
var pName = name + 'Provider';
foo.providers[pName] = foo.providers[pName] || new fn();
foo.instances[name] = foo.instances[name] || foo.providers[pName].$get();
return foo.providers[pName];
@a-laughlin
a-laughlin / gist:1035d616c666271e1fe3
Created June 18, 2014 01:23
Bookmarklet to quickly switch between a repo and the gh-pages (github.io) view.
// Instructions. Save as a bookmark. Click when on a repo or github.io (gh-pages branch) site.
javascript:(function(h,p){
location = /io$/.test(h) ?
'https://github.com/' + h.split('.')[0] + p:
'http://'+ p.split('/')[1]+'.github.io'+ '/' + p.split('/').slice(2).join('/')
})(location.host,location.pathname);
@a-laughlin
a-laughlin / angular-watchcount.js
Created August 4, 2014 13:32
Bookmarklet to count AngularJS watches
// Instructions - create a bookmark. Save this code as the url.
// Click the bookmarklet to see watch count output in the console.
// Currently counts watches by nodeName. It would be more useful by class. TBD.
javascript: (function () {
var totalWatches = 0;
var watchesByElem = {};
angular.forEach(angular.element('.ng-scope'), function (elem) {
var s = angular.element(elem).scope();
var w = s.$$watchers;
if (s.$$watchers) {
@a-laughlin
a-laughlin / angular.debug.js
Last active August 29, 2015 14:06
Search scope keys and values, including nested objects/arrays, for instances of string or regexp
javascript:(function(){
window.angular.debug = {
searchScope : function(varName,options) {
var registeredScopes = {};
var opts = angular.extend({
includeFns:false,
includeHidden:false,
recurseDepth:20
}, options);
var testFn = function(test,testStr){
@a-laughlin
a-laughlin / stickymenu.js
Last active August 29, 2015 14:11
Consistently Working AngularJS Sticky Menu Bar
.directive("stickyMenu", ['$window', function ($window) {
return {
restrict: 'A',
link: function(scope, $el, attrs) {
var windowTop;
var $win = angular.element($window);
var isFixed = false;
var origElemOffsetTop;
var origWidth;
var origOffsetLeft;
@a-laughlin
a-laughlin / hide-boston-calendar-events.js
Last active October 13, 2015 16:39
Hide "The Boston Calendar" Events and remember hidden
// simple bookmarklet to hide events and re-hide them when re-activated
javascript:(function($){
var itemsStr = localStorage.getItem('hiddenItems') || '[]';
var itemsArr = JSON.parse(itemsStr);
var $a = $('li.event h3 a');
$(document).off('click');
$('.hider').remove();
$(document).on('click','.hider',hiderClicked);
itemsArr.forEach(hideItem);