Skip to content

Instantly share code, notes, and snippets.

@kcmckell
kcmckell / findAndRemove.js
Last active December 28, 2015 20:49
Find and remove elements that match.
function findAndRemove(superset, subset) {
var ind = 0;
while (superset.length > 0 & subset.length>0 $ len<subset.length) {
var f = superset.indexOf(subset[ind]);
if (f>=0) {
superset=superset.slice(0,f).concat(superset.slice(f+1));
subset=subset.slice(0,ind).concat(subset.slice(ind+1));
} else {
ind++;
}
@kcmckell
kcmckell / ExternalQueryByTeam
Created October 15, 2013 19:50
This Google Spreadsheet function should pull all rows that have Column5 == Team1 and display their Columns 3, 2 and 5 in an external spreadsheet. See the comments below for notes.
=query( importrange( "<source_spreadsheet_key_from_url>", "Form Responses!A:E" ), "select Col3, Col2, Col5 where Col5 contains 'Team1' order by Col2, Col3", 1 )
@kcmckell
kcmckell / createArray
Created October 10, 2013 21:12
Create N-dimensional empty array in JavaScript. Courtesy Matthew Crumley via StackOverflow: http://stackoverflow.com/questions/966225/how-can-i-create-a-two-dimensional-array-in-javascript/966938#966938 Syntax: createArray(); // [] createArray(3,1); // [ [], [], [] ]
function createArray(length) {
var arr = new Array(length || 0),
i = length;
if (arguments.length > 1) {
var args = Array.prototype.slice.call(arguments, 1);
while(i--) arr[length-1 - i] = createArray.apply(this, args);
}
return arr;
};
@kcmckell
kcmckell / RegistrationConfirmation.js
Last active December 22, 2015 12:28
Multi-purpose confirmation email sender. Connected to the spreadsheet that collects form responses, it is triggered on form submit. It parses the registration data, and then sends out several emails: 1. Confirmation to the registering player. 2. A copy of that registration to the webmaster (to serve as data backup). 3. A notification to the volu…
function onFormSubmit(e) {
// Log me like a hurricane.
var len = e.values.length;
for (var i = 0; i<len; i++){Logger.log(i + "<==>" + e.values[i]);};
// Gather form info into JavaScript variables.
var whoAreYou = e.values[28];
var Player;
var guestArray = new Array;
if (whoAreYou === 'Player') {
// Register a Player.
@kcmckell
kcmckell / .gitignore
Last active December 15, 2015 16:19 — forked from rbochet/.gitignore
Boilerplate gitignore file for LaTeX projects.
# Case-by-case basis for tracking PDF:
# *.pdf
# Latex files
*.aux
*.auxlock
*.glo
*.idx
*.log
@kcmckell
kcmckell / backup_utils.php
Last active December 15, 2015 14:19
A PHP file containing useful utilities for backing up files and databases on a Linux server.
<?php
class MailChunker {
public function __construct( $addr = "", $sub = "", $msg = "" , $from = "", $file = "", $maxfsize = "9MB") {
$this->addr = $addr; # Comma-separated string of email addresses.
$this->sub = $sub;
$this->msg = $msg;
$this->from = $from;
$this->fname = $file;
$this->maxfsize = $maxfsize;
};
@kcmckell
kcmckell / git-ra
Created January 30, 2013 07:59
Super useful shell one-liner to git-remove all deleted files. Credit goes to "Saeb" on <a href="http://stackoverflow.com/questions/1402776/how-do-i-commit-all-deleted-files-in-git">Stackoverflow</a>.
for x in `git status | grep deleted | awk '{print $3}'`; do git rm $x; done
@kcmckell
kcmckell / ConfEmail_v1
Last active August 29, 2015 14:06
Hopu Confirmation Email
function onFormSubmit(e) {
// Initial Testing/Debugging
// var test = '';
// var appendme = '';
// for (var i = 0; i<e.values.length; i++) {
// appendme = i+': '+e.values[i];
// Logger.log(appendme);
// test += appendme+'\n';
// }
Logger.log(e);
@kcmckell
kcmckell / lt
Created July 23, 2014 22:25
Recursively list all files in a directory, sorted by modification time, filtering out 'Icon' files. [Credit](http://stackoverflow.com/questions/3400031/bash-filtering-out-directories-and-extensions-from-find)
gfind . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' ' | grep -v Icon
@kcmckell
kcmckell / git-loghtml
Created July 3, 2014 12:44
Output git log for each file to HTML
for x in `git diff --name-only FROMCOMMIT TOCOMMIT | awk '{print $1}'`; do git log --word-diff --color -U2 FROMCOMMIT..TOCOMMIT $x|tmp/ansi2html.sh > change/$x.html; done