Skip to content

Instantly share code, notes, and snippets.

View viggy28's full-sized avatar

viggy28

View GitHub Profile
title
Managing & Developing Extensions

Intro to omni

omni is a Postgres shared library (and also an extension) that helps managing and developing Postgres easier. Think of it like an extension for extensions !

Why?

@viggy28
viggy28 / pg_cext.c
Created November 27, 2023 23:03
A postgres C extension demos how to use SPI - Server Programming Interface
#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"
#include "inttypes.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(add_nums);
@viggy28
viggy28 / _tree
Created April 5, 2022 01:03 — forked from alexedwards/_tree
Dependency injection via closure (handlers in multiple packages)
.
├── go.mod
├── handlers
│ ├── books
│ │ └── books.go
│ └── env.go
├── main.go
└── models
└── models.go
@viggy28
viggy28 / runcontainer.go
Created March 8, 2022 03:03 — forked from frikky/runcontainer.go
Run a custom Docker container with port 8080 and environment variables
package main
import (
"log"
"context"
"fmt"
"github.com/docker/docker/client"
natting "github.com/docker/go-connections/nat"
"github.com/docker/docker/api/types/container"
package main
import "fmt"
type DB struct {
Name string
}
// double pointer
// a pointer which points to another pointer
// There are two ways I can convert json body to struct. Don't know what's the difference.
// https://www.reddit.com/r/golang/comments/5yhfo1/jsondecoder_vs_jsonunmarshal/
// Other than reddit reference I don't see any other links.
//Method1:
var c Service
byteArray, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Fatalf("fatal: reading from readall body %v", req.Body)
}
#!/bin/bash
# stop the container
echo "stopping mydemoapp docker container..."
sudo docker stop mydemoapp
# remove the container
echo "removing mydemoapp docker container..."
sudo docker rm mydemoapp
1. never deploy django project with debug=true
https://docs.djangoproject.com/en/3.2/ref/settings/#debug
@viggy28
viggy28 / workers-fetch-example.js
Created April 19, 2021 01:26
An example to fetch an URL using Cloudflare workers
addEventListener("fetch", event => {
return event.respondWith(handleRequest())
})
async function handleRequest() {
const init = {
"headers": {
"x-rapidapi-key": "<replaceme>",
"x-rapidapi-host": "community-open-weather-map.p.rapidapi.com"
},
@viggy28
viggy28 / checkPipeExecError.go
Last active April 13, 2021 20:49
checkPipeExecError checks for error in the pipe irrespective of what the command is the function returns the actual error message
package main
import (
"fmt"
"github.com/bitfield/script"
"strings"
)
func main() {
fmt.Println("Hello World")