Skip to content

Instantly share code, notes, and snippets.

/**
* Illustrates methods for testing for the existence of support
* for setting a speaker device.
*/
// Check for the setSinkId() method on HTMLMediaElement.
if (setSinkId in HTMLMediaElement.prototype) {
// Do the work.
}
/**
* iOS doesn't support beforeunload, use pagehide instead.
* NOTE: I tried doing this detection via examining the window object
* for onbeforeunload/onpagehide, but they both exist in iOS, even
* though beforeunload is never fired.
*/
var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0;
var eventName = iOS ? 'pagehide' : 'beforeunload';
window.addEventListener(eventName, function (event) {
/**
* Illustrates how to clone and manipulate MediaStream objects.
*/
function makeAudioOnlyStreamFromExistingStream(stream) {
var audioStream = stream.clone();
var videoTracks = audioStream.getVideoTracks();
for (var i = 0, len = videoTracks.length; i < len; i++) {
audioStream.removeTrack(videoTracks[i]);
}
/**
* Illustrates how to handle getting the correct deviceId for
* a user's stored preference, while accounting for Safari's
* security protocol of serving a random deviceId per page load.
*/
// These would be pulled from some persistent storage...
var storedVideoDeviceId = '1234';
var storedVideoDeviceLabel = 'Front camera';
@thehunmonkgroup
thehunmonkgroup / attention.sh
Last active January 20, 2023 20:39
Bash script to play a sound file every X seconds
#!/usr/bin/env bash
progname=$(basename ${0})
command=${1}
default_seconds="60"
default_volume="1"
default_filepath="${HOME}/attention.wav"
usage() {
echo "
[:~/git … rm/live/staging/provider-pre/gcp] staging+ 1 ± TF_LOG=DEBUG terraform apply
2020/03/21 21:10:28 [WARN] Log levels other than TRACE are currently unreliable, and are supported only for backward compatibility.
Use TF_LOG=TRACE to see Terraform's internal logs.
----
2020/03/21 21:10:28 [INFO] Terraform version: 0.12.24
2020/03/21 21:10:28 [INFO] Go runtime version: go1.12.13
2020/03/21 21:10:28 [INFO] CLI args: []string{"/usr/local/bin/terraform", "apply"}
2020/03/21 21:10:28 [DEBUG] Attempting to open CLI config file: /home/hunmonk/.terraformrc
2020/03/21 21:10:28 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/03/21 21:10:28 [INFO] CLI command args: []string{"apply"}
###########################################
# IAM ROLES
###########################################
resource "google_project_iam_custom_role" "fencing" {
role_id = "fencing"
title = "Fencing"
permissions = [
# Allows instance status to be queried.
"compute.instances.get",
#!/bin/sh
# nfsserver
#
# Description: Manages NFS server as OCF resource
# by hxinwei@gmail.com
# NFSv4-only modifications by thehunmonkgroup at gmail dot com
# License: GNU General Public License v2 (GPLv2) and later
if [ -n "$OCF_DEBUG_LIBRARY" ]; then
. $OCF_DEBUG_LIBRARY
--[[
Wrapper for freeswitch.Dbh to fetch results into an indexed table of
assocative tables.
]]
function db_fetch(dbh, sql)
local rows = {}
dbh:query(sql, function(data)
local row = {}
for col, val in pairs(data) do
row[col] = val
@thehunmonkgroup
thehunmonkgroup / count-test-assertions.py
Last active September 8, 2023 23:45
Quick and dirty test assertion counter for Python tests (pytest)
#!/usr/bin/env python
# pytest provides no mechanism for counting the number of assertions in tests.
#
# This seems like useful information, and this script provides a *reasonable*
# method to get a count.
#
# Since it's simply counting occurances of the string 'assert', it's not
# guaranteed to be fully accurate, but given that a true assert statement
# usually only has one 'assert' string per line, and given that in a test