Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -e
function cleanup {
echo "Removing /tmp/foo"
rm -r /tmp/foo
}
trap cleanup EXIT
mkdir /tmp/foo
asdffdsa #Fails
" Smooth Scroll
"
" Remamps
" <C-U>
" <C-D>
" <C-F>
" <C-B>
"
" to allow smooth scrolling of the window. I find that quick changes of
" context don't allow my eyes to follow the action properly.
@devguydavid
devguydavid / git-push-gerrit
Created February 13, 2013 00:28
A helpful alias for git/gerrit integration.
push-gerrit = "!bash -c ' \
local_ref=$(git symbolic-ref HEAD); \
local_name=${local_ref##refs/heads/}; \
remote=$(git config branch.\"$local_name\".remote || echo origin); \
remote_ref=$(git config branch.\"$local_name\".merge); \
remote_name=${remote_ref##refs/heads/}; \
remote_review_ref=\"refs/for/$remote_name\"; \
r=\"\"; \
if [[ $0 != \"\" && $0 != \"bash\" ]]; then r=\"--reviewer=$0\"; fi; \
if [[ $1 != \"\" ]]; then r=\"$r --reviewer=$1\"; fi; \
@devguydavid
devguydavid / _installation.md
Last active March 7, 2021 05:59
Automatic backups for google spreadsheets.

This script will automatically save spreadsheet sheets when edited in Google docs. It also adds a "Backup" menu that allows you to manually backup the currently opened sheet as well as backup all sheets in a spreadsheet.

The backups are put into CSV files, one per sheet, with the filename format being <sheetname>--<timestamp>.csv. They're put into the directory specified in the script. See the installation instructions below for more details.

Installation:

  • Open your google spreadsheet
  • Open the script editor by clicking on Tools -> Script Editor
  • Paste this code into the script editor
  • Change the backupFolderName to the folder in which you want backups for this spreadsheet to be saved*
  • Select Resources -> Current project's triggers
@devguydavid
devguydavid / fuzzyDays.js
Created August 28, 2013 18:41
Returns the day within which a given timestamp falls in human-friendly terms.
// Given a timestamp in ms, return the appropriate choice of the following depending on where the timestamp falls:
// X days ago
// yesterday
// today
// tomorrow
// X days from now
function fuzzyDays(timestamp) {
var fuzz = "today";
var todayStartMs = Utils.DayStart(new Date()).getTime();
var dayLengthMs = 24 * 60 * 60 * 1000;
@devguydavid
devguydavid / 00-KO-Observable-Cycle-Memory-Leak-README.md
Last active December 24, 2015 22:19
KO Observable Cycle Memory Leak

KO Observable Cycle Memory Leak

If you're not careful, it's easy to leak memory using knockout.js, especially in single page applications that add and remove objects. Here is one example of a leak created by a reverse dependency.

In this case a child object 'Adder' receives a reference to a 'ViewModel' observable and then uses that reference in its own computed. This creates a reverse dependency that needs to be cleaned up if 'Adder' objects are to be removed.

simplecycle.html is the view. simplecycle.js shows the leaking of Adder objects. simplecycle-fixed.js shows how to fix it.

To see the leak in action, visit http://jsfiddle.net/cygnl7/yRnN3/.

numbers.map(
func (number: Int) -> Int {
let result = 3 * number
return result
}
)
func multBy3 = {
(number: Int) -> Int in
let result = 3 * number
return result
}
@devguydavid
devguydavid / find-pis.sh
Created July 15, 2018 02:51
Find Raspberry Pis on 192.168.1.0
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
@devguydavid
devguydavid / write-raspbian.sh
Last active July 15, 2018 03:52
Write multiple raspbian SD cards from Mac OS X
# Instructions:
#
# First, a warning. WARNING!!! If you get this wrong you will DESTROY important
# data on your computer. If you are at all worried about this, do not use this
# method and find a safer method such as https://etcher.io/.
#
# USE THIS AT YOUR OWN RISK!
#
# Step 0 (Optional) - Install the 'pv' utility if you want to see write
# progress. The easiest method to install is using brew.