Skip to content

Instantly share code, notes, and snippets.

View alfonmga's full-sized avatar
👁️
What you look for is what you find.

Alfon alfonmga

👁️
What you look for is what you find.
View GitHub Profile
@alfonmga
alfonmga / validator_interceptor.go
Created August 7, 2022 21:33
Buf connect-go protoc-gen-validate interceptor by @akshayjshah
var validatorInterceptor = connect.UnaryInterceptorFunc(
func(next connect.UnaryFunc) connect.UnaryFunc {
return connect.UnaryFunc(func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) {
validator, ok := request.Any().(interface{ ValidateAll() error })
if !ok {
// Handle this however you'd like; maybe return an error with
// CodeInternal if all your types should support validation?
return next(ctx, request)
}
if err := validator.ValidateAll(); err != nil {
@alfonmga
alfonmga / ffmpeg-format-to-mimetype.js
Created June 23, 2022 15:38 — forked from DusanBrejka/ffmpeg-format-to-mimetype.js
FFMPEG - map of formats to default mime types
// INCOMPLETE
// This command will give you list of available FFMPEG formats and their default Mime types
// ffmpeg -formats -hide_banner | tail -n +5 | cut -c5- | cut -d' ' -f1 | xargs -i{} ffmpeg -hide_banner -h demuxer={} | pcregrep -o2 -o4 -M '(Muxer (\w+) )|(Mime type:( .*).)'
// And then parse the output with regex to JSON format in JavaScript for example:
// str.match(/(.*)\n (.*)/gm).map(m => `"${m.replace(/\n /, '": "')}"`).join(',\n');
// Combine the output with MDN - Common MIME types
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
// And with IANA:
@alfonmga
alfonmga / useModals.tsx
Created June 21, 2022 17:03 — forked from statico/useModals.tsx
Chakra UI await-able alert, confirm, and prompt modal dialogs
/*
* Usage:
* const { alert, confirm, prompt } = useModals()
* alert("Hey!") // awaitable too
* if (await confirm("Are you sure?")) ...
* const result = await prompt("Enter a URL", "http://")
*/
import React, {
createContext,
@alfonmga
alfonmga / promisified-grpc-client.ts
Created May 24, 2022 15:37 — forked from smnbbrv/promisified-grpc-client.ts
Promisify @grpc-js service client with typescript
import { Client, ServiceError, Metadata, CallOptions, ClientUnaryCall } from '@grpc/grpc-js';
import { Message } from 'google-protobuf';
type OriginalCall<T, U> = (request: T, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError, res: U) => void) => ClientUnaryCall;
type PromisifiedCall<T, U> = ((request: T, metadata?: Metadata, options?: Partial<CallOptions>) => Promise<U>);
export type Promisified<C> = { $: C; } & {
[prop in Exclude<keyof C, keyof Client>]: (C[prop] extends OriginalCall<infer T, infer U> ? PromisifiedCall<T, U> : never);
}
@alfonmga
alfonmga / main.go
Created May 21, 2022 13:37
Go program for reading CSV file, transform its data, and save it to another destination CSV file.
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"time"
)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CGPDeviceCategory</key>
<string>GamePad</string>
<key>CGPDeviceType</key>
<string>PS3</string>
<key>CGPDisplayNameOvr</key>
<string>DualShock3 Analogue Triggers</string>
@alfonmga
alfonmga / Vagrantfile
Created November 24, 2021 17:25
Ubuntu 20.04 Linux VM
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@alfonmga
alfonmga / Docker.md
Created November 14, 2021 23:04 — forked from CaryBourgeois/Docker.md
How to set up FaunaDB clusters using the Public Docker image.

How to use the FaunaDB public Docker image.

This document will walk through creating a FaunaDB docker instance using the publicly available docker image. Three different types of deployments will be illustrated.

  • A single node FaunaDB - basic developer functionality.
  • A three node, single replica instance of FaunaDB - scale out operations.
  • A three node, three replicas instance of FaunaDB - distributed operations.

Finally, we will wrap up with some more general documentation around the various options available when using the public docker image.

Requirements

@alfonmga
alfonmga / ga4mp.js
Created November 11, 2021 20:04
GA4 measurement protocol JS lib
const axios = require('axios')
// This is the interface/object for communicating with GA4MP
export function GA4MPClient(apiSecret, measurementId, clientId) {
// Vars for GA4 connection
this.API_SECRET = apiSecret; // GA > Admin > Data Streams > choose your stream > Measurement Protocol > Create
this.MEASUREMENT_ID = measurementId; // GA Admin > Data Streams > choose your stream > Measurement ID
@alfonmga
alfonmga / gist:b04d65b89624a9889e7426aab2b8805d
Created November 1, 2021 13:43
robegamar public PGP key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGEEd88BEACWuQuJFSYTeMJBtbpN3znYJAFlttv3mk9rC6HyWR4XMB14k1GD
cwVQVvsFjPD9pzsxafPWVGeaYSDAexeszaO62iatk8w+ebzrNJp0sFD/yMjHXCDn
8DwuuANorLZGsIS8P34sCeSGdigcgwtgOQpnjFZ2RQAwsZCzJaoZi/LqmpV9jrUk
ozphWkGhtJ0k9VihtMwX4CSQ0CDTAsScw0EsovIEobkNakeQJZsFOAysMyrXi/Sx
3dvZg2A2g7jOPmU+AQvvOy5CYXdm8KWHY0zUKdjBg8KQwimXEYGQlLy7SjirYBjq
EkpQPgRoYcpF2zLM/jjPJCRJe63z05sQx9I/zXz3vonvd47n6/L0elhmIwh/Oajo
SUuzRwIkvVPVepPFdDCUVxkUYtWfs3KcjPAvsgHJMPSb3OL1eKN2JO7f/rrjV1g8
ZYymI92Vg680ebpyy1eftk9ipyklIstvflvqFU6LqrsDhlt9eJmVpecGjtw+3YcR