Skip to content

Instantly share code, notes, and snippets.

View oliveira-andre's full-sized avatar
🖲️
Coding

André Oliveira oliveira-andre

🖲️
Coding
View GitHub Profile
@oliveira-andre
oliveira-andre / turbo_morph_compatibility.js
Created April 11, 2025 20:43
Turbo Morph compatibility
import { Controller } from "@hotwired/stimulus";
export default extends Controller {
connect() {
this.reconnect = this.reconnect.bind(this);
window.addEventListener('turbo:morph', this.reconnect);
myLibrary.create();
}
disconnect() {
@oliveira-andre
oliveira-andre / infinite_scrolling_hotwire.md
Created April 10, 2025 15:07
Infinite Scrolling with Hotwire turbo frames

Infinite Scrolling With Hotwire turbo frames (NO JS)

We gonna use Pagy for pagination

bundle add pagy

include defaults on application_controller.rb

include Pagy::Backend
@oliveira-andre
oliveira-andre / websocket_real_time_messages.md
Last active April 10, 2025 14:57
Websocket Real-Time Messages Rails 8+

Websocket Real Time messages

on your rails app 8+ include this turbo_stream_from it will open a websocket subscription with action cable

<%= turbo_stream_from :todos %>

Sending custom messages manually with action cable

ActionCable.server.broadcast "todos", "Hello"
@oliveira-andre
oliveira-andre / authentication.md
Last active April 8, 2025 23:58
Custom Authentication for Rails

Create rails 8+ project

rails new test-auth

Generate the authenticator folders

rails g authentication
@oliveira-andre
oliveira-andre / sls_commands_cheat_sheet.txt
Last active December 8, 2024 16:43
Serverless Framework Commands Cheat Sheet
# you can use sls to as an alias to serverless
serverless = sls
# check version
sls -v
# init project
sls
# deploy project
@oliveira-andre
oliveira-andre / .bashrc
Created October 19, 2023 17:08
.bashrc from parrot
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
@oliveira-andre
oliveira-andre / clean_cache_docker.md
Created September 17, 2021 13:51
This was created when my containers doesn't build because of not enough space left in cache

How to clean docker cache

Removing simple cache to just free some space in device

sudo docker image prune -f && sudo docker container prune -f

Removing all cache

nginx by docker

simple nginx, with same welcome page

docker run --name static-demo-page -p 80:80 -d nginx

changing welcome pages

docker run --name static-demo-page -v /var/www/html:/usr/share/nginx/html:ro -p 80:80 -d nginx

gitlab via docker

install and run docker:

sudo docker run --hostname gitlab.oliveira-andre.dev --publish 8443:443 --publish 8080:80 --publish 2200:22 --name gitlab --restart always -v logs:/var/log/gitlab -v data:/var/opt/gitlab gitlab/gitlab-ce:latest

show logs

@oliveira-andre
oliveira-andre / easy_webhook_telegram_bot.md
Created August 9, 2021 04:23
in my search i didnt find a simple way to make one telegram bot with sinatra, then i make one very simple

create the route to configure webhook

get '/' do
  require 'telegram/bot'
  TOKEN = 'your token'
  HOOK_URL = 'https://example.com'
  bot = Telegram::Bot::Api.new(TOKEN)
  puts bot.set_webhook(url: HOOK_URL)