Skip to content

Instantly share code, notes, and snippets.

View wardoost's full-sized avatar

Ward wardoost

View GitHub Profile
@wardoost
wardoost / firestore-update-all-docs.ts
Last active March 17, 2020 00:28
Firestore update all docs of a subcollection
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import fetch from 'node-fetch';
const BATCH_LIMIT = 500;
const SUBCOLLECTION_NAME = 'subcollection'; // add your subcollection name
const DOC_UPDATE = { visible: true }; // change to your update that will be applied to all subcollection docs
export const updateAllDocs = functions.https.onRequest(async (req, res) => {
let query = admin

Keybase proof

I hereby claim:

  • I am wardoost on github.
  • I am wardoost (https://keybase.io/wardoost) on keybase.
  • I have a public key ASAYajrkhu4cPDZQaYAULZdT9Fgn5YnZa4iOxK30AuyrGQo

To claim this, I am signing this object:

export default function promiseTimeout(ms, promise) {
// Create a promise that rejects in <ms> milliseconds
let timeout = new Promise((resolve, reject) => {
let id = setTimeout(() => {
clearTimeout(id);
reject('Timed out in '+ ms + 'ms.')
}, ms)
})
@wardoost
wardoost / style.css
Created May 6, 2019 12:41
Easy CSS grid
// From https://daverupert.com/2017/03/initial-impressions-of-css-grid/
.container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(11em, 1fr));
grid-gap: 2vw;
}
// Hook extending the React useEffect hook to only run once
export function useEffectOnce(cb) {
const didRun = useRef(false);
useEffect(() => {
if (!didRun.current) {
cb();
didRun.current = true;
}
});
@wardoost
wardoost / shift-dates.sh
Last active April 2, 2018 23:14
Batch shift creation date of files
#!/bin/bash
# Shifts creation and modified dates of all files in CWD that start with DSC by +12 hours
# chmod +x shift-dates.sh to make executable
for f in DSC*.*; do
ts="$(GetFileInfo -d "$f")"
e="$(date -j -f "%m/%d/%Y %H:%M:%S" "$ts" +%s)"
((o=60*60*12))
((e+=o))
nd="$(date -r $e "+%m/%d/%Y %H:%M:%S")"
SetFile -m "$nd" "$f"
@wardoost
wardoost / higher-order-function.js
Created October 8, 2017 03:04
Composition in JS
const add = (a, b) => a + b
add(5, 9) // 14
// Higher-order function
const createAdd = a => b => add(a, b)
// Use HOF
const add3 = createAdd(3)
add3(8) // 11