Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a4027c9
Golang
devarshi-007 Feb 10, 2023
c6821f9
added local_and_utc_time file
devarshi-007 Feb 10, 2023
f7904ab
Added a course mini project folder
devarshi-007 Feb 10, 2023
a5005d2
Delete hello_world.go
devarshi-007 Feb 10, 2023
c34a501
Devarshi Trivedi named folder added
devarshi-007 Feb 13, 2023
a6c5e9b
done
devarshi-007 Feb 13, 2023
59ba5c2
Added (Starting) LMS System
devarshi-007 Feb 13, 2023
bb3a75f
Added Training docs
devarshi-007 Feb 13, 2023
95351db
Doc updated
devarshi-007 Feb 13, 2023
48d68eb
new concurransy started
devarshi-007 Feb 13, 2023
00d2af9
new concurransy started
devarshi-007 Feb 13, 2023
68987e6
Paniced and Recovered
devarshi-007 Feb 13, 2023
5c03ffa
C
devarshi-007 Feb 13, 2023
6eed959
oka
devarshi-007 Feb 14, 2023
b4f2bc8
Concurr
devarshi-007 Feb 14, 2023
eb7e261
o
devarshi-007 Feb 14, 2023
4f6ee53
Wati
devarshi-007 Feb 14, 2023
df06321
dir
devarshi-007 Feb 14, 2023
e345740
concurancy added
devarshi-007 Feb 14, 2023
ea41c44
channel practicies
devarshi-007 Feb 14, 2023
f7fce61
no
devarshi-007 Feb 15, 2023
368f36c
no
devarshi-007 Feb 15, 2023
a26dd51
cs
devarshi-007 Feb 15, 2023
59f6b67
add: gitignore
JayPonda Feb 17, 2023
86718bb
add: gitignore
JayPonda Feb 17, 2023
b076291
delete .gitignore in go_getting_started
JayPonda Feb 17, 2023
bb06e4f
I
devarshi-007 Feb 17, 2023
424aa46
CHanged
devarshi-007 Feb 17, 2023
8b877f2
Delete Devarshi_Trivedi directory
devarshi-007 Feb 17, 2023
ac04e28
Merge branch 'addedGitIgnore' into devarshi_version
devarshi-007 Feb 17, 2023
1b6ac55
Done TEsting
devarshi-007 Feb 17, 2023
8429c72
added dir Golang_HTTP
devarshi-007 Feb 17, 2023
8a07669
added structures dir
devarshi-007 Feb 17, 2023
a2f9902
HTTP Network
devarshi-007 Feb 17, 2023
885f8dc
Push HTTPs
devarshi-007 Feb 20, 2023
f3ace51
o
devarshi-007 Feb 21, 2023
ce45c89
nETWORKING dONE
devarshi-007 Feb 23, 2023
4be3c64
Empty
devarshi-007 Feb 23, 2023
6faf47f
Network Project Added
devarshi-007 Feb 23, 2023
ac29c7c
DAtabase added
devarshi-007 Mar 1, 2023
fd19b91
Create sqldocker.txt
devarshi-007 Mar 1, 2023
f9b9bc1
Golang with FIber
devarshi-007 Mar 10, 2023
2cd7673
Added vue
devarshi-007 Apr 3, 2023
5397801
feat: added
devarshi-007 Apr 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!*/
!*.*
**/*.out
80 changes: 80 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/Concurrancy/book.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import "fmt"

type Book struct {
ID int
Title string
Author string
YearPublished int
}

func (b Book) String() string {
return fmt.Sprintf(
"Title:\t\t%q\n"+
"Author:\t\t%q\n"+
"Published:\t%v\n", b.Title, b.Author, b.YearPublished)
}

var books = []Book{
{
ID: 1,
Title: "Bhedi Tapu",
Author: "I.K.Vijalyvala",
YearPublished: 2006,
},
{
ID: 2,
Title: "Bhedi Tapu 2",
Author: "I.K.Vijalivala",
YearPublished: 2007,
},
{
ID: 3,
Title: "Bhedi Tapu3",
Author: "I.K.Vijalyvala",
YearPublished: 2010,
},
{
ID: 4,
Title: "Bhedi Tapu 4",
Author: "I.K.Vijalivala",
YearPublished: 2011,
},
{
ID: 5,
Title: "Bhedi Tapu5",
Author: "I.K.Vijalyvala",
YearPublished: 2017,
},
{
ID: 6,
Title: "Bhedi Tapu 6",
Author: "I.K.Vijalivala",
YearPublished: 2017,
},
{
ID: 7,
Title: "Bhedi Tapu7",
Author: "I.K.Vijalyvala",
YearPublished: 2018,
},
{
ID: 8,
Title: "Bhedi Tapu 8",
Author: "I.K.Vijalivala",
YearPublished: 2019,
},
{
ID: 9,
Title: "Bhedi Tapu9",
Author: "I.K.Vijalyvala",
YearPublished: 2023,
},
{
ID: 10,
Title: "Bhedi Tapu 10",
Author: "I.K.Vijalivala",
YearPublished: 2023,
},
}
3 changes: 3 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/Concurrancy/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module concurrent

go 1.20
83 changes: 83 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/Concurrancy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package main

import (
"fmt"
"math/rand"
"sync"
"time"
)

var cache = map[int]Book{}
var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))

func main() {
//wg := sync.WaitGroup{}
wg := &sync.WaitGroup{} //we gonna passing this around in app , so we can pass pointer
m := &sync.RWMutex{}
cacheCh := make(chan Book)
dbCh := make(chan Book)
// count := 1
for i := 0; i < 10; i++ {
id := rnd.Intn(10) + 1
//wg.Add(1) //method-1
wg.Add(2) //method-2
go func(id int, wg *sync.WaitGroup, m *sync.RWMutex, ch chan<- Book) {
if b, ok := queryCache(id, m); ok {
// fmt.Println("Count: ", count)
// count++
// fmt.Println("from cache")
// fmt.Println(b)
ch <- b
}
wg.Done()
}(id, wg, m, cacheCh)
//wg.Add(1) //method-1
go func(id int, wg *sync.WaitGroup, m *sync.RWMutex, ch chan<- Book) {
if b, ok := queryDatabase(id, m); ok {
// fmt.Println("Count: ", count)
// count++
m.Lock()
cache[id] = b
m.Unlock()
ch <- b
}
wg.Done()
}(id, wg, m, dbCh)
//fmt.Println("Book not found of id", id)

go func(cacheCh, dbCh <-chan Book) {
select {
case b := <-cacheCh:
fmt.Println("from cache")
fmt.Println(b)
<-dbCh
case b := <-dbCh:
fmt.Println("from Database")
fmt.Println(b)
}
}(cacheCh, dbCh)

//Right way of doing this is waitgroups
time.Sleep(150 * time.Millisecond)
//DEMO WORKING ONLY BECAUSE OF THIS, REMOVE THIS AND IT DOSEN'T WORK
}
//time.Sleep(2 * time.Second)
wg.Wait() //wait till no activities
}

func queryCache(id int, m *sync.RWMutex) (Book, bool) {
m.RLock()
b, ok := cache[id]
m.RUnlock()
return b, ok
}

func queryDatabase(id int) (Book, bool) {
time.Sleep(100 * time.Millisecond)
for _, b := range books {
if b.ID == id {
return b, true
}
}
return Book{}, false
}
10 changes: 10 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/LMS/User/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package user

import "time"

type User struct {
UserId int
Name string
CurrentBookHolding int
UserValidity time.Time
}
3 changes: 3 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/LMS/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module main

go 1.20
5 changes: 5 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/LMS/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {

}
7 changes: 7 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/code/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
10 changes: 10 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/code/controllers/front.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package controllers

import "net/http"

func RegisterControllers() {
uc := newUserController()

http.Handle("/users", *uc)
http.Handle("/users/", *uc)
}
67 changes: 67 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/code/controllers/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package controllers

import (
"net/http"
"regexp"
"training/go/webservice/models"
)

type userController struct {
userIDP *regexp.Regexp
}

func (uc userController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hi, Controller here!"))
}

func (uc *userController) getAll(w http.ResponseWriter, r *http.Request) {
encodeResponseAsJSON(models.GetUsers(), w)
}

func (uc *userController) get (id int, w http.ResponseWriter) {
u, err := models.GetUserByID(id)
if err!= nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
encodeResponseAsJSON(u, w)
}

func (uc *userController) post(w http.ResponseWriter, r *http.Request) {
u, err := uc.parseRequest(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("could not parse user object"))
return
}
u, err = models.AddUser(u)
if err!=nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
encodeResponseAsJSON(u,w)
}

func (uc *userController) put(id int, w http.ResponseWriter, r *http.Request){
u, err := uc.parseRequest(r)
if err!=nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Could not parse User object"))
return
}
if id != u.ID {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("ID of submitted user must match ID in URL"))
return
}
encodeResponseAsJson(u, w)
}

func (uc *userController) parseREquest(r *http.Request)

func newUserController() *userController {
return &userController{
userIDP: regexp.MustCompile(`^/users/(\d+)/?`),
}
}
3 changes: 3 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/code/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module training/go/webservice

go 1.20
12 changes: 12 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/code/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"net/http"
"training/go/webservice/controllers"
)

func main() {

controllers.RegisterControllers()
http.ListenAndServe(":3000", nil)
}
60 changes: 60 additions & 0 deletions Devarshi_Trivedi/Mini_Projects/GO/code/models/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package models

import (
"errors"
"fmt"
)

type User struct {
ID int
FirstName string
LastName string
}

var (
users []*User
nextId = 1
)

func GetUsers() []*User {
return users
}

func AddUser(u User) (User, error) {
if u.ID != 0 {
return User{}, errors.New("It not have to set")
}
u.ID = nextId
nextId++
users = append(users, &u)
return u, nil
}

func GetUserByID(id int) (User, error) {
for _, u := range users {
if u.ID == id {
return *u, nil
}
}
return User{}, fmt.Errorf("User with id %v not found", id)
}

func UpdateUser(u User) (User, error) {
for i, candidate := range users {
if candidate.ID == u.ID {
users[i] = &u
return u, nil
}
}
return User{}, fmt.Errorf("User with id %v not found", u.ID)
}

func removeUserById(id int) error {
for i, u := range users {
if u.ID == id {
users = append(users[:i], users[i+1:]...)
return nil
}
}
return fmt.Errorf("User with id %v not found", id)
}
Binary file added Devarshi_Trivedi/Mini_Projects/GO/code/webservice
Binary file not shown.
36 changes: 36 additions & 0 deletions Devarshi_Trivedi/Practice/Bash_Script/loop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#!bin/bash
for i in {0..10}
do
echo "Hi:" $i
done

for j in {0..10..2}
do
echo $j
done

read a
if test $a -lt 5;then
echo "a less 5"
else
echo "a grete 5"
fi

read z
case $z in
1|2 ) echo "1|2" $z
;;
3|4 ) echo "3|4" $z
;;
* ) echo "sorry"
;;
esac

declare -i counter
counter=10
while [ $counter -gt 2 ]; do
echo The counter is $counter
counter=counter-1
done
exit 0
Loading