Skip to content

Instantly share code, notes, and snippets.

View djale1k's full-sized avatar
🏇
Thinking about starting a ranch farm

Darko Djalevski djale1k

🏇
Thinking about starting a ranch farm
View GitHub Profile
@djale1k
djale1k / csvtomap.go
Created August 25, 2021 11:01
CSV File To Map
// CSVToMap takes a reader and returns an array of dictionaries, using the header row as the keys
func CSVToMap(reader io.Reader) []map[string]string {
r := csv.NewReader(reader)
var rows []map[string]string
var header []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
@djale1k
djale1k / utils.go
Last active January 7, 2025 15:43
Count file lines fast in Go
func LineCounter(r io.Reader) (int, error) {
buf := make([]byte, 32*1024)
count := 0
lineSep := []byte{'\n'}
for {
c, err := r.Read(buf)
count += bytes.Count(buf[:c], lineSep)
switch {