Skip to content

Instantly share code, notes, and snippets.

@JemarJones
JemarJones / jQuery Fallback
Created Jul 7, 2015
A function that replicates the familiar javascript fallback functionality for jquery objects (which are truthy).
View jQuery Fallback
var fallback = function(options){
var numOfOptions = options.length;
if (numOfOptions == 2){
return (options[0].length > 0)? options[0] : options[1];
}else if (numOfOptions > 2){
return fallback(options.slice(1));
}else if (numOfOptions == 1){
return options[0];
}else{
return $();
@cowboy
cowboy / sudo-keepalive-example.sh
Created Jul 15, 2012
Bash: Sudo keep-alive (good for long-running scripts that need sudo internally but shouldn't be run with sudo)
View sudo-keepalive-example.sh
#!/bin/bash
# Might as well ask for password up-front, right?
sudo -v
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Example: do stuff over the next 30+ mins that requires sudo here or there.
function wait() {