Skip to content

Instantly share code, notes, and snippets.

View rahul-yr's full-sized avatar

Rahul Reddy rahul-yr

View GitHub Profile
@rahul-yr
rahul-yr / schema.go
Created July 4, 2022 15:01
This is the snippet for TODO GraphQL schema
package todo
import "github.com/graphql-go/graphql"
// used for Todo Schema
var todoSchema = graphql.NewObject(
graphql.ObjectConfig{
Name: "Todo",
Fields: graphql.Fields{
"id": &graphql.Field{
@rahul-yr
rahul-yr / udf.go
Created July 4, 2022 14:36
This is where all the CRUD operations defined for Todo model
package todo
// used to store todos
var TodoItems = []Todo{}
// used to assign unique id to each todo
var count = 1
// Here comes all the Queries
@rahul-yr
rahul-yr / models.go
Created July 4, 2022 14:33
This is a Todo model in go
package todo
// Todo is a struct that represents a todo item
type Todo struct {
ID int `json:"id"`
Title string `json:"title"`
Completed bool `json:"completed"`
}
@rahul-yr
rahul-yr / concurrency.go
Created June 21, 2022 15:50
Sample addition program with wait groups
package main
import (
"log"
"sync"
"time"
)
// wg is a wait group
// it is used to wait for all go routines to finish
@rahul-yr
rahul-yr / concurrency_without_wg.go
Created June 21, 2022 15:49
Sample addition program in go
package main
import (
"log"
"time"
)
// addTwoNumbers adds two numbers together and prints the result
func addTwoNumbers(a int, b int) {
// sleep for a second to simulate a long running operation
@rahul-yr
rahul-yr / sequential.go
Created June 21, 2022 15:45
Addition program in go
package main
import (
"log"
"time"
)
// addTwoNumbers adds two numbers together and prints the result
func addTwoNumbers(a int, b int) {
// sleep for a second to simulate a long running operation
@rahul-yr
rahul-yr / concurrency.go
Last active June 20, 2022 13:12
This is a gist for implementing Concurrency in Golang
package main
import (
"log"
"runtime"
"runtime/pprof"
"sync"
"time"
)
@rahul-yr
rahul-yr / parallelism.go
Created June 20, 2022 12:57
This is a gist for implementing parallelism in go
package main
import (
"log"
"runtime"
"runtime/pprof"
"sync"
"time"
)
@rahul-yr
rahul-yr / main.py
Created June 15, 2022 10:22
Here is the main file for url shorteners
from fastapi import FastAPI
from url_shortener import router
# Create the app
app = FastAPI()
# Add the router
app.include_router(router.url_shortener, prefix="/url-shortener")
@rahul-yr
rahul-yr / router.py
Created June 15, 2022 10:09
Here is the snippet for url shorteners
import secrets
import string
from fastapi import APIRouter
from url_shortener.models import CreateUrlShortener, CreateUrlShortenerResponse
from url_shortener.database import MockDBOperations
from starlette.responses import RedirectResponse
# Create the router
url_shortener = APIRouter()