Skip to content

Instantly share code, notes, and snippets.

View thiagozs's full-sized avatar
:octocat:
Have a nice day

Thiago Zilli Sarmento thiagozs

:octocat:
Have a nice day
View GitHub Profile
@thiagozs
thiagozs / hamburger.html
Last active March 8, 2024 20:59
HTML hamburger menu tailwindcss javascript
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<!-- FONTS -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
@thiagozs
thiagozs / duration_totext.go
Last active December 19, 2023 17:23
BairesDev Transform duration to Text
package main
import "fmt"
func solution (seconds int) string {
if seconds == 0 {
return "now"
}
@thiagozs
thiagozs / food_ratings.go
Created December 19, 2023 14:28
BaieresDev golang challenge
package main
import "fmt"
func solution (n int, ratings [][]int) int {
dishRatings := make(map[int][2]int)
for i := 0; i < n; i++ {
dishID, rating := ratings[i][0], ratings[i][1]
@thiagozs
thiagozs / echo-ratelimit.go
Created November 28, 2023 15:12
Poc Redis Rate Limit middleware
package main
import (
"context"
"fmt"
"net/http"
"time"
"github.com/go-redis/redis/v8"
"github.com/labstack/echo/v4"
@thiagozs
thiagozs / paseto_exthex.go
Created September 21, 2023 20:44
Paseto secret external Hex
package main
import (
"fmt"
"aidanwoods.dev/go-paseto"
)
func main() {
@thiagozs
thiagozs / file-opening-flags-go.md
Created September 18, 2023 12:26
File-opening flags in Go

File-opening flags in Go (By Adebayo Adams)

Go provides file-opening flags represented by constants defined in the os package. These flags determine the behavior of file operations, such as opening, creating, and truncating files. The following is a list of the flags and what they do.

  1. os.O_RDONLY: Opens the file as read-only. The file must exist.

  2. os.O_WRONLY: Opens the file as write-only. If the file exists, its contents are truncated. If it doesn't exist, a new file is created.

  3. os.O_RDWR: Opens the file for reading and writing. If the file exists, its contents are truncated. If it doesn't exist, a new file is created.

@thiagozs
thiagozs / show_create_table.sql
Last active September 18, 2023 12:52
Postgres show create table script
CREATE OR REPLACE FUNCTION public.show_create_table(
in_schema_name varchar,
in_table_name varchar
)
RETURNS text
LANGUAGE plpgsql VOLATILE
AS
$$
DECLARE
-- the ddl we're building
@thiagozs
thiagozs / Makefile
Created August 23, 2023 17:23
Makefile with golang-migrate
BINARY_NAMES="golang-migrate|migrate"
DATABASE="mysql://root:password@tcp(localhost:3306)/test"
.PHONY: checkdeps help
help: ## Displays the help for each command.
@grep -E '^[a-zA-Z_-]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
dbu: ## Migrates the database to the latest version.
migrate -database="$(DATABASE)" -path=migrations -lock-timeout=20 -verbose up
@thiagozs
thiagozs / golang_template_tips.md
Created August 1, 2023 15:50
Golang template tips

How to use Go text templates

October 20, 2021 7 min read2011

Using Golang Templates

Templates are files that define a specific pattern and give room for automation, be it a simple text file or an HTML file for a webpage. If it provides space for customization, it is a template.

You can write programming logic to parse simple templates, but as the level of customization in your template increases, the programming logic you need to customize increases, making it less feasible to write template parsing logic.

@thiagozs
thiagozs / install_zsh.sh
Created June 27, 2023 21:25
Install zsh script
#!/bin/bash
# Update package lists
sudo apt-get update
# Check if Zsh is installed, and if not, install it
if ! command -v zsh &> /dev/null
then
echo "Zsh is not installed. Installing..."
sudo apt-get install -y zsh