Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
manjeettahkur / camelcase.go
Created November 30, 2018 07:06
camelCase method in golang
/*
Title:
Break camelCase
Description:
Write simple .camelCase method (camel_case function in PHP or CamelCase in C#) for strings. All words must have their first letter capitalized without spaces.
Examples:
"hello case".camelCase() => HelloCase
"camel case word".camelCase() => CamelCaseWord
Kata Link:
https://www.codewars.com/kata/break-camelcase
@manjeettahkur
manjeettahkur / kata01.js
Last active February 10, 2024 08:20
Given the triangle of consecutive odd numbers
Description:
Given the triangle of consecutive odd numbers:
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
@manjeettahkur
manjeettahkur / slice_pass_by_ref.go
Created January 11, 2023 08:34
In go language everything is pass by value even slice. but in slice case slice header pass by value so both headers point to the same back array
package main
import "fmt"
func main() {
a := []byte{'A', 'M', 'N', 'J', 'E', 'E', 'T'}
b := s(a)
b[0], b[1] = b[1], b[0]
fmt.Println(string(a))
@manjeettahkur
manjeettahkur / mutex.go
Created January 11, 2023 08:25
Which snippet of code acquire more locks
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var mu sync.Mutex
// Slice rules in go programming language
starting cap growth factor
256 2.0
512 1.63
1024 1.44
2048 1.35
4096 1.30
package main
1. Query to your local database to check that cloudtrail data is present in the local database.
IF yes
// It means you have stored some data from cloudtrail before.
// And now you are going to do request to cloudtrail for new trail events.
// Note - At a time of the first request you don't have a token (i.e. next-token)
GOTO Step 3
ELSE
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
@manjeettahkur
manjeettahkur / jsonUnmarshalText.go
Created July 6, 2022 10:05
unmarshal text in go programming language
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
)
@manjeettahkur
manjeettahkur / add_array_concurrent.go
Last active June 5, 2022 09:36
This is an example using the Go programming language. With channels With Waitgroups and With Sequentials
func addConcurrent(numbers []int) int {
var v int64
goroutines := runtime.NumCPU()
totalNumbers := len(numbers)
lastGoroutine := goroutines - 1
stride := totalNumbers / goroutines
var wg sync.WaitGroup
wg.Add(goroutines)
@manjeettahkur
manjeettahkur / .golangci.yaml
Created June 1, 2022 01:57
Code conventions, Practice and Tooling Group -- Linter Settings
linters-settings:
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf