Skip to content

Instantly share code, notes, and snippets.

@brunolkatz
brunolkatz / convert_pixel_color.go
Created July 26, 2021 19:21
change a pixel #ff00ff color to transparency with golang
package main
import (
"fmt"
"image/color"
"image/png"
"os"
"path/filepath"
"strings"
)
@brunolkatz
brunolkatz / remove_accents.go
Created November 24, 2020 18:15
Remove accents (PT-BR)
func RemoveAccents(s string) string {
rep := strings.NewReplacer(
"Š", "S",
"š", "s",
"Đ", "Dj",
"đ", "dj",
"Ž", "Z",
"ž", "z",
"Č", "C",
"č", "c",
@brunolkatz
brunolkatz / get_tags_struct.go
Created October 30, 2020 19:39
Get golang struct tags, returning name of field, value of tag and the index in struct
package main
import (
"errors"
"fmt"
"reflect"
)
type User struct {
Id int `json:"Id" queryStr:"Id"`
@brunolkatz
brunolkatz / reflect_indirect_map_interface.go
Last active October 30, 2020 19:46
Scan a map[string]interface{} and fill without passing the ptr in function parameter using reflect.Indirect function.
package main
import (
"errors"
"fmt"
"reflect"
)
func main() {
@brunolkatz
brunolkatz / getWeeksStartAndEndInMonth.ts
Created January 27, 2020 18:58
Return a array of weeks in a month, with start and end date or day.
/**
* Return a array of weeks in a month, with start and end date or day.
* @param _month number Define the month (WARNING: month start at 0 in javascript)
* @param _year number Define the year
* @param returnDate boolean Define if returns a Date class in returned array or not
* @return Array<{start: number, end: number}>
*/
public getWeeksStartAndEndInMonth(_month: number, _year: number, returnDate: boolean = false) {
const lastDay = new Date(_year, _month + 1, 0);
let weeks: Array<{start: number, end: number}> = [];