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 / 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 / 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 / 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
@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
We couldn’t find that file to show.
@nwaughachukwuma
nwaughachukwuma / stripe.ts
Last active September 29, 2021 18:21
Create stripe customer and store on user document
/**
* Create your stripe customer
*/
import * as functions from 'firebase-functions';
import { DocumentSnapshot } from "firebase-functions/lib/providers/firestore";
import * as Stripe from "stripe"
const secretKey = functions.config().stripe.key // ensure you have set the configuration
const stripe = new Stripe(secretKey)
@nwaughachukwuma
nwaughachukwuma / Comment.php
Last active March 28, 2020 21:46
A comment model with it's relationship
<?
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
public function post()
{
return $this->belongsTo('\App\Post');
}
}
@nwaughachukwuma
nwaughachukwuma / Post.php
Last active March 28, 2020 21:45
A post model with it's relationships
<?
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function user()
{
return $this->belongsTo('\App\User');
}
public function comments()