Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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
@henrahmagix
henrahmagix / turtles.js
Created May 25, 2017 12:48
Is it really turtles all the way down?
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');
let numberOfLevels = 0;
process.stdout.write('How many levels would you like to inspect? ');
process.stdin.on('data', function (n) {
numberOfLevels = parseInt(n, 10);
@henrahmagix
henrahmagix / showyourmoves.sh
Last active May 16, 2017 14:21
The sound of 8 "show your moves" all together
W () { sleep $((1 + RANDOM % 10)); }
s () { W && echo -n s; }
h () { W && echo -n h; }
o () { W && echo -n o; }
w () { W && echo -n w; }
y () { W && echo -n y; }
u () { W && echo -n u; }
r () { W && echo -n r; }
m () { W && echo -n m; }