- Build the image from a
Dockerfile
docker build ./ --tag {name}:latest
. Advisable to use your service name here
- Test if the application is running
docker run -p 8080:8080 -it name
docker run -p 8080:8080 -e ENV=VALUE -it name
- e.g.
docker run -p 8080:8080 -e PORT=8080 -it name
- e.g.
- Configure docker on GCloud CLI
gcloud auth configure-docker gcr.io
gcloud auth configure-docker {region}.gcr.io
- Enable cloud-run if it isn’t enabled, using cloud console or GCloud CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET v4_enrichmentsx/_search | |
{ | |
"query": { | |
"bool": { | |
"filter": [ | |
{ | |
"terms": { | |
"FIELD": [ # 64000 | |
"VALUE1", | |
"VALUE2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nodeFetch, { type RequestInit, type Response } from "node-fetch"; | |
import type { AbortSignal } from "abort-controller"; | |
const TEN_MEGABYTES = 1000 * 1000 * 10; | |
type StreamOptions = RequestInit & { | |
signal?: AbortSignal; | |
highWaterMark?: number; | |
}; | |
export async function fetch( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type EventDef<D> = Event & { detail?: D } | |
type VideoRef = string | HTMLVideoElement | null | |
const eventName = 'image-updated' | |
export default function getVideoSnapshot(videoRef: VideoRef) { | |
if (typeof videoRef === 'string') { | |
videoRef = document.getElementById(videoRef) as HTMLVideoElement | null | |
} | |
if (!videoRef) { | |
throw new Error('Video element not found') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See compatibility table for .toBlob() Method | |
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility | |
interface Option { | |
type: 'image/jpeg' | 'image/png' | 'image/webp' | 'image/bmp' | 'image/gif'; | |
quality?: number; | |
} | |
async function compressImage(file: File, option: Option) { | |
if (!file.type.startsWith('image')) { |
My Elasticsearch cheatsheet with example usage via rest api (still a work-in-progress)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {stripe, StripeConfig} from './stripe-util' | |
/** | |
* Used to charge vendor's accounts on Stripe such as payment for a service | |
*/ | |
export async function chargeConnectedAccount(source: string, amount: number, description: string, metadata: any = {}) { | |
const cost = Math.round(amount * 100) | |
const descriptor = 'transaction descriptor' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {stripe} from './stripe-util' | |
import {admin} from '../admin' | |
import {DocumentSnapshot} from "firebase-functions/lib/providers/firestore"; | |
export async function handleTransaction(chargeId: string, transactionStatus: string, customer: DocumentSnapshot) { | |
let charge: any; | |
switch (transactionStatus) { | |
case 'COMPLETED': | |
charge = await captureCharge(chargeId) | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as _ from 'lodash' | |
import * as Stripe from 'stripe' | |
import { Request, Response } from "express"; | |
import {admin} from '../admin' // already initialized | |
import { isDefaultCard, stripe } from './stripe-util' | |
export const addPaymentMethod = async (req: Request, res: Response) => { | |
const errors = validationResult(req) | |
if (!errors.isEmpty()) { |
NewerOlder