Skip to content

Instantly share code, notes, and snippets.

@thisdavej
thisdavej / google_sheets_function.js
Last active December 7, 2018 15:45
A modified version of the JSONTEMPLATE function from my post (https://thisdavej.com/consuming-json-web-data-using-google-sheets/) for Umar's JSON object
/**
* Parse JSON and render the results in a string template.
*
* @param {"http://path/to/myapi"} url
* JSON API data URL
* @param {"This is {{item1}}."} template
* string template for rendering results
* @customfunction
*/
function JSONTEMPLATE_UMAR(url, template) {
@thisdavej
thisdavej / button-presses.log
Created March 23, 2018 20:21
Process a log file and count the number of times different types of buttons were pressed for an IoT project. How would you accomplish?
2018-3-23 9:06:48|circuit board
2018-3-22 18:11:22|dash button
2018-3-22 8:46:54|web
...
@thisdavej
thisdavej / mapUntil.js
Created March 11, 2018 22:37
This JavaScript function called Array.prototype.mapUntil is like Array.prototype.map, but it only maps until a condition (predicate) is true.
Array.prototype.mapUntil = function(fn, predicate) {
const arr = [];
let done = false;
this.forEach(el => {
if (done) return arr;
if (!predicate(el)) arr.push(fn(el));
else done = true;
});
return arr;
};
@thisdavej
thisdavej / menu1.sh
Last active February 8, 2022 15:31
Displays a user friendly menu if remote host name is included in a file. See http://thisdavej.com/controlling-a-raspberry-pi-from-a-mobile-device-with-bonus-menu-too/ for more information.
show_menu () {
# We show the host name right in the menu title so we know which Pi we are connected to
OPTION=$(whiptail --title "Menu (Host:$(hostname))" --menu "Choose your option:" 12 36 5 \
"1" "Current time" \
"2" "Calendar" \
"3" "Uptime" \
"4" "Reboot Pi" \
"5" "Shut down Pi" 3>&1 1>&2 2>&3)
BUTTON=$?