Skip to content

Instantly share code, notes, and snippets.

@rmtsrc
rmtsrc / .gitignore
Last active September 29, 2020 14:09
Concourse CI with a Windows worker
keys/*
@rmtsrc
rmtsrc / raspberry-pi-cec-client.md
Created May 13, 2019 09:49
Using cec-client on a Raspberry Pi to control TV power and inputs via HDMI

Using cec-client on a Raspberry Pi

Most modern HDMI connected devices support Consumer Electronics Control (CEC). It allows devices to send commands to each other, typically to get the TV to switch input and control volume. If you have ever turned on a Game Console and had your TV automatically change input to that device you have seen CEC in action. It is very convenient and useful, sort of a universal remote that works.

Every manufacturer seems to have it’s own branding of CEC (e.g. Samsung Anynet+, LG SimpLink, Sharp Aquos Link) but it may need to be enabled. Check your manual for details.

Using a Raspberry Pi connected to a TV that supports CEC, you can use the command line cec-client application to control the inputs and the TV itself. These are notes on how to use cec-client and understand the different options.

Details

@rmtsrc
rmtsrc / sort-package-json.sh
Created December 4, 2018 14:13
Sorts dependencies in all `package.json` files in the current directory
# yarn global add npm-sort
# find . ! -path "*node_modules*" -type f -name "package.json" -exec `pwd`/sort-package-json.sh "{}" \;
pushd `dirname $1` && npm-sort && sed -i '' -e '$a\' package.json && popd
@rmtsrc
rmtsrc / index.js
Last active March 25, 2020 10:03
Log all incoming HTTP and HTTPS requests
const fs = require('fs');
const https = require('https');
const Koa = require('koa');
const multipartBodyParser = require('koa-body');
const app = new Koa();
app.use(
multipartBodyParser({
@rmtsrc
rmtsrc / index.js
Created August 1, 2017 11:31
Node Chrome Headless wait until element exists
const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');
const sleep = require('sleep-async');
// Optional: set logging level of launcher to see its output.
// Install it using: yarn add lighthouse-logger
// const log = require('lighthouse-logger');
// log.setLevel('info');
/**
@rmtsrc
rmtsrc / wait-until-javascript-has-finished-executing.html
Last active August 1, 2017 11:45
Waits until JavaScript has finished executing (Hacky! Waits 500ms after other JavaScript processes have stopped modifying the DOM, so doesn't wait for other async events to finish like fetch)
<!-- Place before </body> -->
<script async defer type="text/javascript">
(function() {
if (window.addEventListener) {
window.addEventListener('load', loadHandler, false);
} else if (window.attachEvent) {
window.attachEvent('onload', loadHandler);
} else {
window.onload = loadHandler; // Or you may want to leave this off and just not support REALLY old browsers
}
#!/usr/bin/env bash
mem=$(free -m | grep Mem)
memAvaMb=$(echo $mem | awk '{print $2}')
memFreeMb=$(echo $mem | awk '{print $4}')
memPercentFree=$(free | grep Mem | awk '{print $4/$2 * 100.0}' OFMT="%3.1f%")
disk=$(df -h / | grep /)
diskTotal=$(echo $disk | awk '{print $2}')
diskUsed=$(echo $disk | awk '{print $3}')
@rmtsrc
rmtsrc / index.js
Created January 23, 2017 17:21
Get a Browser Cookie
// @see http://stackoverflow.com/a/15724300
export default (cookieName) => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${cookieName}=`);
if (parts.length === 2) {
return parts.pop().split(';').shift();
}
};
#!/bin/bash
set -e
FQDN[0]="test.example.com"
FQDN[1]="test2.example.com"
for hn in "${FQDN[@]}"
do
echo $hn
mkdir $hn.ssl
# Updates, Homebrew & Cask
alias update='mac-up && brew-up && apm update --confirm false'
alias mac-up='sudo softwareupdate --install --all'
alias brew-cask-upgrade='for c in `brew cask list | grep -v "(\!)"`; do ! brew cask info $c | grep -qF "Not installed" || brew cask install $c; done'
alias brew-up='brew update && brew upgrade && brew-cask-upgrade && brew cask cleanup && brew cleanup'