Skip to content

Instantly share code, notes, and snippets.

View Gergling's full-sized avatar
🦇
Behind a keyboard

Greg Gergling

🦇
Behind a keyboard
View GitHub Profile
@Gergling
Gergling / ng-overlapping-divs
Created February 11, 2015 22:41
A function designed to pick out the (x, y) co-ordinates from absolute, arbitrarily positioned, potentially-overlapping 'tiles'. Originally used to handle mouse interaction with isometrically-positioned tiles.
var tileOp = function ($event, fnc, always) {
var el = $element.find('.isometric-grid'),
x = $event.clientX - el.offset().left + $window.scrollX,
y = $event.clientY - el.offset().top + $window.scrollY;
$scope.tiles.forEach(function (tile) {
always(tile);
if (tile.boundsCheck(x - tile.left(), y - tile.top())) {
fnc(tile);
}
@Gergling
Gergling / ng-component-listing
Last active August 29, 2015 14:09
Lists all required modules and components in an array of specified modules.
angular.forEach([ /* ... Provide some module names ... */ ], function (moduleName) {console.log(moduleName, angular.module(moduleName).requires);angular.forEach(angular.module(moduleName)._invokeQueue, function(component) {console.log("-", component[1], component[2][0], component); });});
@Gergling
Gergling / dom-element-click-toggle
Created July 30, 2014 11:42
DOM Element Click Toggle
/* Stolen from anonymous234 on http://what.thedailywtf.com/ (http://what.thedailywtf.com/t/banners-that-change-as-you-scroll-down-the-page-and-dont-have-a-close-button/1754/48) */
/* Run to activate remove-clickable elements */
/* Run again to switch off */
javascript:var b=new Array();var c=1;var o=((document.onkeydown==null)||(o==2))?0:1;document.onkeydown=ck;z=document.getElementsByTagName('*');for(i=0;i<z.length;i++){if(z[i].tagName.search(/(HTML|BODY)/i)==-1){z[i].onclick=function(e){t=this;if(window.event) e=window.event;if((t==e.target)||(window.event)) t.parentNode.removeChild(t);e.stopPropagation();return false;};z[i].onmouseover=function(){if(!c)return;c=0;t=this;b[t]=t.style.backgroundColor;t.style.background='#FF9999';};void(z[i].onmouseout=function(){t=this;t.style.backgroundColor=b[t];c=1;});}}function ck(e){k=window.event?window.event.keyCode:e.keyCode;if((k==27)||o){o=2;document.onkeydown=null;for(i=0;i<z.length;i++){if(z[i].tagName.search(/(HTML|BODY)/i)==-1){z[i].onclick=null;z[i].onmouseov
@Gergling
Gergling / console.require.js
Last active September 7, 2016 11:39
Script for copying into a console to include jquery and requirejs.
// Usage:
//document.write('<scr'+'ipt src="https://requirejs.org/docs/release/2.1.8/comments/require.js"></scr'+'ipt>');
var script = document.createElement('script');script.src = "https://requirejs.org/docs/release/2.1.8/comments/require.js";
document.head.appendChild(script);
var oldDollar = $;requirejs(["https://code.jquery.com/jquery-1.10.2.js"], function() {
var jQuery = $;
var $ = oldDollar;
});
@Gergling
Gergling / newvhost.sh
Last active December 19, 2015 18:48
Shell script for generating new virtual hosts on Ubuntu based on old vhosts as a template. usage: bash newvhost [name old vhost] [name new vhost]
#!/bin/bash
SITES_AVAILABLE=/etc/apache2/sites-available/
TEMPLATE=$SITES_AVAILABLE$1
NEWVHOST=$SITES_AVAILABLE$2
echo Copying template $TEMPLATE as new virtual host file.
sudo cp $TEMPLATE $NEWVHOST
echo Enabling new virtual host.
@Gergling
Gergling / PackageLoader.js
Created May 23, 2013 15:57
This is a requirejs-based preloader progress bar using jquery. Download the files into a directory and run index.html in a browser to see the effects.
var PackageLoader = function() {
this.cb = Math.random(0, 100000000000);
this.current = 0;
this.batches = [];
// Load kicks off the entire loading process.
this.load = function(config, loadMap, onload) {
var scope = this;
for(label in loadMap) {
scope.batches.push(new PackageBatch(label, loadMap[label]));