Skip to content

Instantly share code, notes, and snippets.

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

Hernan Reyes hernanhrm

🏠
Working from home
View GitHub Profile
@hernanhrm
hernanhrm / alacritty.toml
Created July 12, 2024 02:15
alacritty config
import = ["/home/hernan/.config/alacritty/themes/themes/gruvbox_material_medium_dark.yaml"]
live_config_reload = true
[colors.bright]
black = "#353539"
blue = "#b9aeda"
cyan = "#f591b2"
green = "#9dc6ac"
magenta = "#ecaad6"
red = "#ffae9f"
@hernanhrm
hernanhrm / tmux-sessionizer.sh
Created July 9, 2024 13:01
tmux sessionizer
#!/usr/bin/env bash
session=$(echo -e "$(find ~/code -mindepth 2 -maxdepth 2 -type d | awk -F/ '{print $(NF-1) "/" $NF}' | fzf-tmux -p 55%,60% --no-sort --border-label)")
session_name=$(basename "$session" | tr . _)
if ! tmux has-session -t "$session_name" 2> /dev/null; then
tmux new-session -s "$session_name" -c "/home/hernanreyes/code/$session" -d
fi
@hernanhrm
hernanhrm / .tmux.conf
Created July 8, 2024 13:57
TMux config
unbind r
bind r source-file ~/.tmux.conf
setw -g mode-keys vi
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
# List of plugins
func main() {
var warriors = Warriors{}
warriors = append(warriors, NewMRSatan())
warriors = append(warriors, NewGoku())
executeWithoutIPS(warriors)
}
type Goku struct{}
func NewGoku() *Goku {
return &Goku{}
}
func (g Goku) Kick() {
println("Goku kicks")
}
type MRSatan struct{}
func NewMRSatan() *MRSatan {
return &MRSatan{}
}
func (m MRSatan) Kick() {
println("MRSatan kicks")
}
type Warrior interface {
Kick()
Punch()
Transform()
}
type Warriors []Warrior
func executeWithoutIPS(warriors Warriors) {
for _, warrior := range warriors {
// GetEmployees returns a list of employees with a pre-signed URL to their profile picture
// to make the example easier to follow, I have a mock data with a list of employees,
// so we don't need to use a database
func (u FileManager) GetEmployees() ([]Employee, error) {
for i, _ := range employees {
preSignedURL, err := u.service.Presign(employees[i].Picture)
if err != nil {
return nil, fmt.Errorf("filemanager.GetEmployees(): %w", err)
}
func (s Service) PresignV2(key string) (string, error) {
req, _ := s.S3.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(key),
})
signedURL, err := req.Presign(time.Minute)
if err != nil {
return "", fmt.Errorf("s3.SignKey(): %v", err)
}
// Presign signs a key object with an expiry time
func (s Service) Presign(key string) (string, error) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s.s3.amazonaws.com/%s", s.Bucket, key), nil)
if err != nil {
return "", fmt.Errorf("s3.Presign.http.NewRequest(): %w", err)
}
// we sign the request with the signTime and a time expiration of 1 day
_, err = s.Signer.Presign(req, nil, "s3", *s.Session.Config.Region, time.Hour*24, getSignTime())
if err != nil {