Skip to content

Instantly share code, notes, and snippets.

@devguydavid
devguydavid / philips-db.zsh-theme
Last active December 12, 2023 16:04
Modified philips zsh theme I like
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
if [ "$AWSUME_PROFILE" = "canary-production-admin" ]; then PCOLOR="red"; else PCOLOR="green"; fi
## Prompt stuff
# Autoload zsh's `add-zsh-hook` and `vcs_info` functions
# (-U autoload w/o substition, -z use zsh style)
autoload -Uz add-zsh-hook vcs_info
# Set prompt substitution so we can use the vcs_info_message variable
#!/bin/bash
OIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *
do
echo "$f"
done
IFS=$OIFS
# Give it a gpx filename as the argument.
# This assumes the track name is in the <name> element. This is how it came from Strava. YMMV.
# Some of theses headers certainly aren't needed. Experiment carefully. Read the comments inline.
# Most important will be your API key which is in the binary form data. Search for 'name="key"'
# below. You may have to inspect an API call to get your key.
filename="$1"
filecontents=`cat $1`
name=`cat $1 | grep '<name>' | sed -e 's/.*<name>//g' | sed -e 's/<\/name>//g'`
@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.
@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}'
func multBy3 = {
(number: Int) -> Int in
let result = 3 * number
return result
}
numbers.map(
func (number: Int) -> Int {
let result = 3 * number
return result
}
)
@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/.

@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 / _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