Skip to content

Instantly share code, notes, and snippets.

Avatar
👁️
What you look for is what you find.

Alfon alfonmga

👁️
What you look for is what you find.
View GitHub Profile
@alfonmga
alfonmga / logrus2telegram.go
Last active Aug 17, 2022
Logrus -> Telegram
View logrus2telegram.go
package logrus2telegram
import (
"fmt"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/sirupsen/logrus"
"errors"
View ginlogrus.go
package ginlogrus
import (
"fmt"
"math"
"net/http"
"os"
"time"
"github.com/gin-gonic/gin"
View gormlogrus.go
package gormlogrus
import (
"context"
"errors"
"time"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
gormlogger "gorm.io/gorm/logger"
@alfonmga
alfonmga / gcs_reverse_proxy.go
Last active Aug 12, 2022
Google Cloud Storage reverse proxy code extracted from https://github.com/daichirata/gcsproxy
View gcs_reverse_proxy.go
package main
import (
"context"
"flag"
"io"
"log"
"net/http"
"strconv"
"time"
@alfonmga
alfonmga / validator_interceptor.go
Created Aug 7, 2022
Buf connect-go protoc-gen-validate interceptor by @akshayjshah
View validator_interceptor.go
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 Jun 23, 2022 — forked from DusanBrejka/ffmpeg-format-to-mimetype.js
FFMPEG - map of formats to default mime types
View ffmpeg-format-to-mimetype.js
// 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 Jun 21, 2022 — forked from statico/useModals.tsx
Chakra UI await-able alert, confirm, and prompt modal dialogs
View useModals.tsx
/*
* 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 — forked from smnbbrv/promisified-grpc-client.ts
Promisify @grpc-js service client with typescript
View promisified-grpc-client.ts
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
Go program for reading CSV file, transform its data, and save it to another destination CSV file.
View main.go
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"time"
)
View PS3Dualshock_10_15.plist
<?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>