Skip to content

Instantly share code, notes, and snippets.

View josuebrunel's full-sized avatar

Josue Kouka josuebrunel

View GitHub Profile
@preslavrachev
preslavrachev / do.go
Last active August 4, 2022 13:15
Do is an experiment in mimicking the Result type (known from languages like Rust and Haskell). The idea is to minimize the amount of error checking and let the developer focus on the happy path, without undermining the power of Go's errors. The code below requires Go 1.18+, as it makes use of generic type parameters.
package do
type Void struct{}
type Result[T any] interface {
Unwrap() (T, error)
}
type defaultResult[T any] struct {
val T
@Integralist
Integralist / handle unknown json data structure.go
Created January 31, 2022 13:58
[Golang handle unknown json data structure] #go #golang #json #marshal #unmarshal
package main
import (
"encoding/json"
"fmt"
"log"
)
func main() {
var (
@philippegirard
philippegirard / main.py
Created April 18, 2020 20:18
fastapi logging middleware
import logging
from fastapi import FastAPI
from uicheckapp.services import EchoService
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
logger = logging.getLogger(__name__)
app = FastAPI()
@Saafke
Saafke / code.py
Created March 31, 2020 10:03
Python code for upscaling an image via OpenCV
import cv2
from cv2 import dnn_superres
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read image
image = cv2.imread('./input.png')
# Read the desired model
@StevenACoffman
StevenACoffman / goGetPrivate.md
Last active July 13, 2024 20:27 — forked from dmitshur/gist:6927554
How to `go get` private repos using SSH key auth instead of password auth.

Set GOPRIVATE to match your github organization

I keep fixing this up, but if it fails for you, check if these are better maintained https://tip.golang.org/cmd/go/#hdr-Configuration_for_downloading_non_public_code and https://golang.org/ref/mod#private-modules.

Cloning the repo using one of the below techniques should work correctly but you may still be getting an unrecognized import error.

As it stands for Go v1.13, I found in the doc that we should use the GOPRIVATE variable like so:

GOPRIVATE=github.com/ORGANISATION_OR_USER_NAME go get -u -f github.com/ORGANISATION_OR_USER_NAME/REPO_NAME

The 'go env -w' command (see 'go help env') can be used to set these variables for future go command invocations.

@jtbonhomme
jtbonhomme / hasMany.go
Created May 22, 2018 11:11
Gorm example of foreign key definition for a hasMany relation
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
// Customer ...
type Customer struct {
@booleangate
booleangate / a-salesforce-oauth-2.0-jwt-bearer-token-flow-walk-through.md
Last active July 19, 2024 17:51
Salesforce OAuth 2.0 JWT Bearer Token Flow walk-through

Salesforce OAuth 2.0 JWT Bearer Token Flow Walk-Through

This document will walk you through how to create or configure a Salesforce application for use with JWT authentication. These configuration steps and the example code works as of Salesforce API version 42.0.

Prerequisites

Create an RSA x509 private key/certification pair

@steven2358
steven2358 / ffmpeg.md
Last active July 22, 2024 08:40
FFmpeg cheat sheet
import cgi
def parse_form_data(formdata):
fp = cgi.StringIO(formdata)
env = cgi.os.environ
env['REQUEST_METHOD'] = 'POST'
data = cgi.FieldStorage(fp, environ=env)
return data
from dateutil.parser import parse as dateutil_parse
from lxml import etree, objectify as xobject
def is_clean(element):
if not element.getchildren() and element.text is None:
return False
return all(is_clean(child) for child in element.iterchildren())