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 / redisSET.go
Created October 25, 2018 11:25
Setting key value pair in redis using go-redis
import "github.com/go-redis/redis"
// Client is setting connection with redis
var redisClient = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
// SetValue sets the key value pair
func SetValue(key string, value string, expiry time.Duration) error {
@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)