Skip to content

Instantly share code, notes, and snippets.

View viggy28's full-sized avatar

viggy28

View GitHub Profile
@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")
@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"
},
1. never deploy django project with debug=true
https://docs.djangoproject.com/en/3.2/ref/settings/#debug
#!/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
// 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)
}
package main
import "fmt"
type DB struct {
Name string
}
// double pointer
// a pointer which points to another pointer
@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"
@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 / invalid-zips.json
Created July 21, 2018 16:44
JSON list of valid and invalid US ZIP codes
["00000", "00001", "00002", "00003", "00004", "00005", "00006", "00007", "00008", "00009", "00010", "00011", "00012", "00013", "00014", "00015", "00016", "00017", "00018", "00019", "00020", "00021", "00022", "00023", "00024", "00025", "00026", "00027", "00028", "00029", "00030", "00031", "00032", "00033", "00034", "00035", "00036", "00037", "00038", "00039", "00040", "00041", "00042", "00043", "00044", "00045", "00046", "00047", "00048", "00049", "00050", "00051", "00052", "00053", "00054", "00055", "00056", "00057", "00058", "00059", "00060", "00061", "00062", "00063", "00064", "00065", "00066", "00067", "00068", "00069", "00070", "00071", "00072", "00073", "00074", "00075", "00076", "00077", "00078", "00079", "00080", "00081", "00082", "00083", "00084", "00085", "00086", "00087", "00088", "00089", "00090", "00091", "00092", "00093", "00094", "00095", "00096", "00097", "00098", "00099", "00100", "00101", "00102", "00103", "00104", "00105", "00106", "00107", "00108", "00109", "00110", "00111", "00112", "00113
@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);