Skip to content

Instantly share code, notes, and snippets.

@henrahmagix
henrahmagix / content.js
Last active September 23, 2020 08:43
Chrome extension to always select a specific user for Google Cloud Console
let url = new URL(window.location);
let authuser = url.searchParams.get('authuser');
// Log in as the account you always want to be logged-in as
// and replace 1 here with the authuser=N number in the url.
if (!authuser) {
url.searchParams.set('authuser', '1');
window.history.replaceState(null, null, url.toString());
window.location.reload;
}
@henrahmagix
henrahmagix / eml-to-html.sh
Created March 19, 2020 16:08
Pull the html out of an eml file
sed -n '/DOCTYPE/,/<\/html>/p;' $1 | perl -pe 's/=\r\n//g' | perl -pe 's/3D//g' | perl -pe 's/=[A-Z\d]{2}//g'
@henrahmagix
henrahmagix / datastore-entity.go
Last active February 17, 2020 11:04
How to get any data from Google Datastore as an untyped map
package main
type DynamicEntity map[string]interface{}
func (d *DynamicEntity) Load(props []datastore.Property) error {
loadMap(*d, props)
return nil
}
func loadMap(m map[string]interface{}, props []datastore.Property) {
@henrahmagix
henrahmagix / rgb-array.js
Last active October 16, 2019 02:59
Get an rgb() array of any hex or rgb color.
(function() {
function getRgbArray(color, alpha) {
// Always return an array, either empty or filled.
var rgb = [];
var hex;
// Get an array of rgb(a) values.
if (color.substr(0, 1) === '#') {
/* HEX STRING */
// If the first character is # we're dealing with a hex string. Get
@henrahmagix
henrahmagix / garlic-every-third-word.js
Last active December 28, 2018 20:42
Replace every 3rd word with "garlic"
// Select an element in the inspector, then paste this into the console.
function textNodesUnder(el){
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
while(n=walk.nextNode()) a.push(n);
return a;
}
function notAllWhitespace(value) {
return !value.match(/^\s*$/g);
@henrahmagix
henrahmagix / order-cloudbuild-logs
Last active August 24, 2018 13:02
Order logs from Google Cloudbuild bookmark (copy-paste into new bookmark, click to run)
javascript:(function (el) { if (!el) { throw new Error('no el'); } var text = el.innerText; if (!text) { throw new Error('no text for', el); } var rAll = /Step #(\d+)/; var match = function (s, r) { var m = s.match(r); return m && m[1]; }; var steps = {}; var lines = []; text.split('\n').forEach(s => { var m = match(s, rAll); if (!m) { lines.push(s); } else if (!steps[m]) { steps[m] = [s]; } else { steps[m].push(s); } }); Object.keys(steps).map(ns => parseInt(ns, 10)).sort((a,b) => a-b).forEach(n => { lines.push(steps[n].join('\n')) }); el.innerText = lines.join('\n'); })(document.querySelector('pre'));
@henrahmagix
henrahmagix / go-coverage-in-browser.sh
Created June 25, 2018 10:03
Open a browser window showing coverage for every go package in the current directory
# Assumes you are inside your GOPATH
for pkg in $(go list ./...); do
curr_dir_as_pkg=${PWD/$GOPATH\/src\//}
pkd_dir=${pkg/$curr_dir_as_pkg/}
if [ -z "$pkd_dir" ]; then
continue
fi
pkg_dir=${pkd_dir/\//}
name=${pkd_dir//\//-}
covfile=coverage$name.out
@henrahmagix
henrahmagix / narn.js
Created April 20, 2018 14:38
Quicker than yarn
#!/usr/bin/env node
console.log("nothing to do")
process.exit(0)
@henrahmagix
henrahmagix / protractor-element-screenshot.js
Last active October 30, 2017 17:38
Take a screenshot of an element in all browsers by cropping a page screenshot
// Altered from http://stackoverflow.com/a/38311061/3150057
const fs = require('fs');
const sharp = require('sharp');
const takeElementScreenshot = function (element, name) {
return protractor.promise
.all([
element.getLocation(),
element.getSize(),
browser.takeScreenshot()
])
@henrahmagix
henrahmagix / a-demo.md
Last active August 13, 2017 11:51
Download series of files in parallel with progress

Steps

  • Download these files to a folder
  • Go to http://downloader.soundcloud.ruud.ninja/
  • Authorise via SoundCloud login
  • Paste gettracklinks.browser.js into the browser console
  • Paste the clipboard into alltracks.json
  • Run node getallfiles.js