Skip to content

Instantly share code, notes, and snippets.

View souvikhaldar's full-sized avatar
🌴
On vacation

Souvik Haldar souvikhaldar

🌴
On vacation
View GitHub Profile
@souvikhaldar
souvikhaldar / factorial.py
Last active March 24, 2017 16:24
null created by souvikhaldar - https://repl.it/Gcri/0
def factorial(n):
if n==0:
return 1
else:
return (n*factorial(n-1))
@souvikhaldar
souvikhaldar / finding length using recursion.py
Created March 24, 2017 16:29
finding length using recursion created by souvikhaldar - https://repl.it/Gcri/1
def Length(l):
if l==[]:
return (0)
else:
return(1 + Length(l[1:]))
@souvikhaldar
souvikhaldar / Sum of elements.py
Created March 24, 2017 16:32
Sum of elements created by souvikhaldar - https://repl.it/Gcri/2
def sumlist(l):
if l==[]:
return (0)
else:
return(l[0]+sumlist(l[1:]))
@souvikhaldar
souvikhaldar / recursion.go
Created October 24, 2018 14:41
Pattern printing using recursion
package main
import (
"fmt"
)
func print(n int) {
for i := 0; i < n; i++ {
fmt.Print("* ")
}
// getRandNum returns a random number of size four
func getRandNum() (string, error) {
nBig, e := rand.Int(rand.Reader, big.NewInt(8999))
if e != nil {
return "", e
}
return strconv.FormatInt(nBig.Int64()+1000, 10), nil
}
@souvikhaldar
souvikhaldar / sms.go
Created October 25, 2018 11:37
sending sms to a phone number using gobudgetsms golang library
import (
"github.com/souvikhaldar/gobudgetsms"
"fmt"
)
var smsConfig gobudgetsms.Details
func init() {
smsConfig = gobudgetsms.SetConfig(BsmsUsername, BsmsUserId, BsmsHandle, "", 1, 0, 0)
}
@souvikhaldar
souvikhaldar / goUuid.go
Created October 25, 2018 11:40
Generate Random UUID using Golang and gouuid
import "github.com/nu7hatch/gouuid"
func randToken() (string, error) {
// Using UUID V5 for generating the Token
u4, err := uuid.NewV4()
UUIDtoken := u4.String()
if err != nil {
logrus.Errorln("error:", err)
return "", err
}
@souvikhaldar
souvikhaldar / redisget.go
Last active October 25, 2018 11:55
Retrieving the value from Redis using key in golang
// GetValue the value corresponding to a given key
func GetValue(key string) (string, error) {
value, arghhh := redisClient.Get(key).Result()
if arghhh != nil {
return "", arghhh
}
return value, nil
}
originalNum, e := GetValue(otp.SmsNonce)
package main
import (
"fmt"
"time"
)
func say(s string) {
for i := 0; i < 5; i++ {
time.Sleep(100 * time.Millisecond)
package main
import "fmt"
func main() {
ch := make(chan int, 2)
ch <- 1
ch <- 2
ch <- 3
fmt.Println(<-ch)