Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / proposal-template.md
Created July 13, 2022 08:19
Proposal Template

What problem are you trying to solve?

  • Introduce the problem statement here. This might be well-defined ('we need to tweak the parameter of a rule from X to Y to help reduce a certain type of abuse'), or more fuzzy ('we need to invest more in paying back technical debt').
  • Focus on the underlying problem that needs to be solved, as opposed to jumping to how you will solve it.

Why should we solve it?

  • Why is this an important problem for us to solve?
  • Is it a big enough problem to solve?
  • Should we solve it now, or later?
  • Provide specific data (quantitative or qualitative) wherever possible.
const isWebpSupported = () =>
new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(true);
img.onerror = () => reject(false);
img.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
});
isWebpSupported().then(console.log).catch(console.error)
@dannycroft
dannycroft / npm-audit-high.sh
Created July 1, 2019 15:53
Show only High severity problems with npm audit
npm audit | grep -B 1 -A 10 High
/* ------------------------------- */
/* common/errorHandler.js */
/* ------------------------------- */
const asyncUtil = fn =>
function asyncUtilWrap(...args) {
const fnReturn = fn(...args)
const next = args[args.length-1]
return Promise.resolve(fnReturn).catch(next)
}
@dannycroft
dannycroft / pi-stats.py
Last active October 1, 2019 12:40
PI Stats
import os
# Return CPU temperature as a character string
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
# Return RAM information (unit=kb) in a list
# Index 0: total RAM
# Index 1: used RAM
@dannycroft
dannycroft / RequestQueue.js
Created August 15, 2018 08:56
RequestQueue to ensure that only a single request is executing at a time.
import EventEmitter from 'events';
import onFinished from 'on-finished';
/*
* RequestQueue to ensure that only a single request is executing at a time.
*
* This middleware intercepts requests as they come in by delaying executing of
* next() until previous requests finish processing. This complements external
* server configuration via haproxy or similar that restricts concurrent
* requests. This per-process queue allows an application level guarantee of
@dannycroft
dannycroft / getUsers.js
Last active June 1, 2018 09:47
Simple challenge to collect and parse users
/* -----------------------------------------------------------------------------
Complete the following tasks using only browser based APIs. Update
the supplied "getUsers()" function to achieve the following:
- Make a request to the API_URL (see below)
- Return a Promise
- Parse each of the returned results to match the example below:
[
@dannycroft
dannycroft / configure.sh
Created February 1, 2018 13:55
Docker and Kubernetes setup
#!/bin/sh
sudo apt-get update \
&& sudo apt-get install -qy docker.io
sudo apt-get update \
&& sudo apt-get install -y apt-transport-https \
&& curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
@dannycroft
dannycroft / fancy-logs.js
Created January 7, 2018 10:46
Jazz hands for your console logs
const log = new Proxy({}, {
get: (_, color) => (...args) => {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
});
// example
log.tomato('I am tomato');
log.chocolate('I am chocolate');
log.cornflowerblue('I am cornflowerblue');
@dannycroft
dannycroft / ec2-instances.sh
Created December 15, 2017 12:42
Get a list of instance with id, name and type
aws --output table ec2 describe-instances --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value,InstanceId,InstanceType]'