Skip to content

Instantly share code, notes, and snippets.

View alexyslozada's full-sized avatar
🏠
Working from home

Alexys Lozada alexyslozada

🏠
Working from home
View GitHub Profile
@alexyslozada
alexyslozada / Spinner Go
Created September 21, 2018 19:16
Crear un spinner en consola con Go
package main
import (
"fmt"
"time"
)
func main() {
spinner(150 * time.Millisecond)
}
@alexyslozada
alexyslozada / .gitlab-ci.yml
Created October 2, 2018 23:29 — forked from moemoe89/.gitlab-ci.yml
Example Gitlab CI Setup for Go-Lang
image: golang:1.8.1
variables:
BIN_NAME: go-practice-ci
ARTIFACTS_DIR: artifacts
GO_PROJECT: gitlab.com/go-practice-ci
stages:
- build
- test
@alexyslozada
alexyslozada / recursive-cte.sql
Last active October 5, 2018 14:32
Consultar recursivamente una tabla con la estructura de árbol
/*
Original Data:
id idparent jobNO
--------------------------------
1 0 1
2 1 2
3 1 3
4 0 4
5 4 5
6 5 6
@alexyslozada
alexyslozada / flag-slice.go
Created October 29, 2018 00:35
Cómo leer un slice de datos de un flag
// Field structura de un tipo de campo del modelo
type Field struct {
Name string
Type string
NotNull string
}
// Helper estructura que permite procesar los campos digitados
type Helper struct {
Fields []Field
@alexyslozada
alexyslozada / Go - Genera los días festivos de Colombia
Last active December 16, 2019 23:00
Genera los días festivos de colombia dado un año
// Genera los días festivos de colombia dado un año
// Basado en los artículos:
// https://www.festivos.com.co/calculo y https://elpais.com/elpais/2017/04/12/el_aleph/1492008750_544261.html
package main
import (
"fmt"
"time"
)
@alexyslozada
alexyslozada / social_security_date_sql.go
Last active March 13, 2021 16:20
Calcula el último día hábil de acuerdo a los dos últimos digitos de un nit
// Este archivo me permite generar el SQL que se inserta en la tabla de social_security_date
// OJO: debe revisarse los festivos del año.
package social_security_date
import (
"fmt"
"log"
"sort"
"time"
)
@alexyslozada
alexyslozada / filter.go
Last active August 18, 2021 14:38
How to process a raw json
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"regexp"
"strconv"
@alexyslozada
alexyslozada / sse_handler.go
Created September 21, 2021 14:17
How to create a handler to SSE
func (h *Handler) Subscribe(c echo.Context) error {
var epoch = time.Unix(0, 0).Format(time.RFC1123)
c.Response().Header().Set(echo.HeaderContentType, "text/event-stream")
c.Response().Header().Set("Cache-Control", "no-cache")
c.Response().Header().Set("Connection", "keep-alive")
c.Response().Header().Set("Expires", epoch)
c.Response().Header().Set("Cache-Control", "no-cache, private, max-age=0")
c.Response().Header().Set("Pragma", "no-cache")
c.Response().Header().Set("X-Accel-Expires", "0")
@alexyslozada
alexyslozada / prepare-fields.sh
Created November 4, 2021 04:16
How to prepare some files with some parameters
#!/bin/bash
# Get the provider name
name=""
read -p "Write the provider name: " name
# Ask to dev if want to remove comments with <<>>
removeComments="N"
read -p "Do you want to remove the helpers comments? [y/N]: " removeComments
@alexyslozada
alexyslozada / download-from-browser.js
Created June 21, 2022 22:24
How to export / download data as text / csv file
// This data is a mock from your real data
const data = [{"name": "apple"}, {"name": "onion"}, {"name": "banana"}]
// We want to write this data into a string
const dataToString = data => {
let resp = ""
data.forEach(e => resp += e.name + "\n")
return resp
}