Skip to content

Instantly share code, notes, and snippets.

View nwaughachukwuma's full-sized avatar
🧶
Making stuff

Chukwuma Nwaugha nwaughachukwuma

🧶
Making stuff
View GitHub Profile
GET v4_enrichmentsx/_search
{
"query": {
"bool": {
"filter": [
{
"terms": {
"FIELD": [ # 64000
"VALUE1",
"VALUE2"
@nwaughachukwuma
nwaughachukwuma / nyreFetch.ts
Created January 14, 2023 09:22
Nyre-Fetch is a simple Node.js wrapper built on top of node-fetch. It includes helper methods I find helpful and use in my projects.
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(
@nwaughachukwuma
nwaughachukwuma / getVideoSnapshot.ts
Last active October 2, 2023 02:03
Get video frame preview (snapshot) from video element
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')
@nwaughachukwuma
nwaughachukwuma / compressImage.ts
Last active January 14, 2023 04:27
Compress any image file before upload using imageBitmap and canvas
// 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')) {
@nwaughachukwuma
nwaughachukwuma / deploy-docker-image-to-cloud-run.md
Last active September 22, 2022 16:59
Seven easy steps to deploy a docker image to cloud run [for pros]
  1. Build the image from a Dockerfile
    1. docker build ./ --tag {name}:latest. Advisable to use your service name here
  2. Test if the application is running
    1. docker run -p 8080:8080 -it name
    2. docker run -p 8080:8080 -e ENV=VALUE -it name
      1. e.g. docker run -p 8080:8080 -e PORT=8080 -it name
  3. Configure docker on GCloud CLI
    1. gcloud auth configure-docker gcr.io
    2. gcloud auth configure-docker {region}.gcr.io
  4. Enable cloud-run if it isn’t enabled, using cloud console or GCloud CLI
We couldn’t find that file to show.
@nwaughachukwuma
nwaughachukwuma / cheatsheet-elasticsearch.md
Created March 23, 2020 05:04 — forked from ruanbekker/cheatsheet-elasticsearch.md
Elasticsearch Cheatsheet : Example API usage of using Elasticsearch with curl
@nwaughachukwuma
nwaughachukwuma / recoupFunds.ts
Last active December 26, 2019 08:16
This is used to recoup funds from an integrated business
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'
@nwaughachukwuma
nwaughachukwuma / captureCharge.ts
Last active December 24, 2019 07:52
Capture a previously created charge on transaction completion
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
@nwaughachukwuma
nwaughachukwuma / createCustomerCard.ts
Last active December 23, 2019 22:22
Create a credit card from a token and link it to customer
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()) {