Skip to content

Instantly share code, notes, and snippets.

Avatar

Harry Scheuerle hscheuerle

View GitHub Profile
View ScreenLockModifier.swift
import SwiftUI
struct ScreenLockModifier: ViewModifier {
func body(content: Content) -> some View {
content
.onAppear {
UIApplication.shared.isIdleTimerDisabled = true
}
.onDisappear {
UIApplication.shared.isIdleTimerDisabled = false
@hscheuerle
hscheuerle / utilities.ts
Created Jun 28, 2021
non variadic cypress page object utility function
View utilities.ts
export const dataCy = (value: string) => cy.get(`[data-cy=${value}]`);
export const dataCyPath = (...attrs: string[]) => cy.get(attrs.map(attr => `[data-cy=${attr}]`).join(' '));
export const dataCyObject = <T extends readonly string[]>(hostAttr: string, attrs: T) =>
attrs.reduce((cyObject, attr) => (cyObject[attr] = () => dataCyPath(hostAttr, attr)) && cyObject, {} as Record<T[number], () => Cypress.Chainable<JQuery<HTMLElement>>>);
View firebase-hosting-pull-request.yml
name: Deploy to Firebase Hosting on PR
"on": pull_request
jobs:
build_and_preview:
if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
runs-on: ubuntu-latest
env:
IDS: '{ master: "hscheue-workspace", development: "work-development-6804b" }'
SA: '{ master: "FIREBASE_SERVICE_ACCOUNT_HSCHEUE_WORKSPACE", development: "FIREBASE_SERVICE_ACCOUNT_WORK_DEVELOPMENT_6804B" }'
C: '{ master: "production", development: "development" }'
View firebase-hosting-merge.yml
name: Deploy to Firebase Hosting on merge
"on":
push:
branches:
- master
- development
jobs:
build_and_deploy:
runs-on: ubuntu-latest
env:
@hscheuerle
hscheuerle / firestore.rules
Created May 24, 2021
DocumentReference serialization is type path in Firestore rules, forward slash paths are type path in "raw" form. Here's a utility for checking ownership
View firestore.rules
function sentInvitation(invitationId) {
return exists(/databases/$(database)/documents/accounts/$(request.auth.uid))
&& get(/databases/$(database)/documents/invitations/$(invitationId)).data.invitedBy == /databases/$(database)/documents/accounts/$(request.auth.uid)
}
// In production, wrapping exists and get in small utilities is worth tradeoff in code readability
// chaining this with utility that null-checks auth and auth.uid helps read rule errors in unit tests
@hscheuerle
hscheuerle / many-to-many-firebase-functions.ts
Last active Apr 29, 2021
Many to many ref handling for firebase functions
View many-to-many-firebase-functions.ts
import * as functions from "firebase-functions";
// import type so that lazy import isn't made useless
import type * as admin from "firebase-admin";
// global types only
type DocumentReference = admin.firestore.DocumentReference;
// lazy init admin, not required in pubsub but when paired in functions
// file with callables is important.
let initialized = false;
@hscheuerle
hscheuerle / index.js
Last active May 25, 2019
Naming for mongodb driver
View index.js
const { MongoClient: driver } = require('mongodb');
const connectionSpread = [
process.env.DB_URL_DEVELOPMENT || 'mongodb://localhost:27017',
{ useNewUrlParser: true }
];
(async () => {
try {
const client = await driver.connect(...connectionSpread);
@hscheuerle
hscheuerle / request.js
Last active Oct 27, 2018
node.js http request with redirect
View request.js
const handleRequest = async uri => {
return new Promise((resolve, reject) => {
http.get(uri, async res => {
const { statusCode } = res
if (statusCode === 302) { // redirect
const { location } = res.headers
const data = await handleRequest(location)
resolve(data)