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 / 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]));
@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 / 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 / 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 / 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 / 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 / printR
Created February 17, 2015 15:07
A recursive printing function, similar to PHP's print_r.
var printR = function (obj, indent) {
indent = indent || 0;
if (typeof obj === "string") {
grunt.log.writeln("'" + obj + "'");
} else if (typeof obj === "object") {
grunt.log.writeln("{");
Object.keys(obj).forEach(function (key) {
grunt.log.write(repeat(" ", indent + 2) + key + ": ");
printR(obj[key], indent + 1);
});
@Gergling
Gergling / install-everything.sh
Last active September 19, 2015 15:36
Installs various dev tools
# Multi-window terminal
sudo apt-get install terminator
# Basic IDE
sudo apt-get install vim
# JRE
sudo apt-get install default-jre
# Clipboard, useful for copying rsa keys
@Gergling
Gergling / auto.sh
Created October 13, 2017 13:00
Bash scripts for restarting wifi when it fails.
#!/bin/bash
recent_restart=1
while true; do
printf $(date +"%Y-%m-%d")
printf " "
printf $(date +"%H:%M:%S")
printf " "
if [[ $(ping -c 1 google.com) ]] > /dev/null 2>&1 ; then
if [ $recent_restart -eq 0 ] ;
@Gergling
Gergling / pdf-fields.php
Last active April 9, 2018 13:22
Takes a `pdftk` field dump and turns it into a PHP-copyable output.
<?php
// Usage example: pdftk stuff.pdf dump_data_fields | php pdf-fields.php
$stdin = file('php://stdin');
// print_r($stdin);
$data = [];
$i = 0;
foreach($stdin as $idx => $line) {
$chunks = explode(': ', $line);