Skip to content

Instantly share code, notes, and snippets.

View asciimike's full-sized avatar
🔥
All the things

Mike McDonald asciimike

🔥
All the things
View GitHub Profile
function convertToML(val, unit, conversions) {
var conversionFactors = {};
for (i = 1; i < conversions.length; i++) {
conversionFactors[conversions[i][0]] = conversions[i][1]
}
return val * conversionFactors[unit];
}
function calculateAverageValueByVolume(volumes, values) {
var totalVolume = 0.0;
@asciimike
asciimike / index.html
Created April 4, 2020 01:42
Covid Act Now Embed
<html>
<body>
<!-- You can quickly add it to your website via an iFrame: -->
<!-- Don't forget to change the state you want to display -->
<iframe
src="https://covidactnow.org/embed/us/co"
title="CoVid Act Now"
width="350"
height="700"
frameBorder="0"
@asciimike
asciimike / Dockerfile
Created January 8, 2019 15:41
CLI in a container
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
ENV NODE_ENV=production
RUN npm install --production
COPY . .
CMD [ "npm", "start" ]
@asciimike
asciimike / create-token.sh
Created September 14, 2018 18:43
Create a Google-signed JWT with the audience set to a particular URL
### Step 0: Configure FUNCTION_URL and SERVICE_ACCOUNT as needed
OAUTH_ENDPOINT="https://www.googleapis.com/oauth2/v4/token"
FUNCTION_URL="..."
SERVICE_ACCOUNT="..."
### Step 1: Generate JWT payload
cat <<EOF > input.json
{
"iat": $(date +%s),
"exp": $(($(date +%s) + 3600)),
@asciimike
asciimike / actions.js
Created September 11, 2018 21:04
Example of a "serverless" system
function logger(string) {
console.log("Logging [" + Date.now() + "]: " + string);
}
@asciimike
asciimike / app.yaml
Created September 11, 2018 18:56
Testing Google Cloud IAP (https://cloud.google.com/iap) with GAE 2nd Generation Runtimes
runtime: nodejs8
@asciimike
asciimike / Chat.rules
Created August 20, 2018 18:46
Firebase Pro Series "Pro Chat" secure chat app (from http://youtu.be/oFlHzF5U-HA)
function isChatMessage(message) {
return message.size() == 4
&& message.username is string
&& message.userId is string
&& message.createdAt is timestamp
&& message.messageText is string
&& message.messageText.size() <= 160;
}
function isUser(user) {
@asciimike
asciimike / group_storage_permissions.rules
Created December 5, 2016 08:01
Firebase Storage "serverless" group permissions
/*
You can create a Role Based Access Control system by storing ownership and access membership in the custom metadata of the file.
The proposed solution uses the existing "owner" "editor" and "reader" permissions.
If you store a user and the associated permission as a key/value pair in the file metadata:
// custom file metadata looks like:
metadata: {
"user:1234": "owner",
"user:5678": "editor",
@asciimike
asciimike / firebase_storage_multi_file_upload.js
Last active November 29, 2021 18:05
Upload multiple files transactionally in Firebase Storage
// set it up
firebase.storage().ref().constructor.prototype.putFiles = function(files) {
var ref = this;
return Promise.all(files.map(function(file) {
return ref.child(file.name).put(file);
}));
}
// use it!
firebase.storage().ref().putFiles(files).then(function(metadatas) {
@asciimike
asciimike / BUILD
Last active July 11, 2022 13:28
Example of how to reference a CocoaPod in Bazel
ios_app(
name = "App",
hdrs = ["src/*.h"],
srcs = ["src/*.m"],
deps = [
"@SDWebImage//:latest_library",
],
)
ios_test(