Skip to content

Instantly share code, notes, and snippets.

@javier-menendez
javier-menendez / gx_app.rb
Created September 13, 2024 17:34 — forked from jhjguxin/gx_app.rb
Mongoid localized fields, and how use it
# encoding: UTF-8
class GxApp
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Sequence
store_in session: "gxservice"
field :name, type: String, default: "Guanxi.me"
field :version, type: String
@javier-menendez
javier-menendez / README.md
Created September 9, 2024 19:34 — forked from jesster2k10/README.md
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@javier-menendez
javier-menendez / DEPLOY_WITH_KAMAL_ON_DEDICATED_SERVER.md
Created September 6, 2024 13:24 — forked from n-studio/DEPLOY_WITH_KAMAL_ON_DEDICATED_SERVER.md
Deploy a web app on a dedicated server with Kamal

Notes

This guide uses Kamal 1.8.1

Motivation

Kamal was designed with 1 service = 1 droplet/VPS in mind.
But I'm cheap and I want to be able to deploy multiple demo/poc apps apps on my $20/month dedicated server.
What the hell, I'll even host my private container registry on it.

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@javier-menendez
javier-menendez / readme.md
Created February 29, 2024 04:07 — forked from acidtib/readme.md
kamal + github actions

Example of Kamal deployment from Github Actions.

Add your applications .env variables to the Github repo as a repository secret, you can find this under the repo settings => secrets and variables => actions

https://github.com/username/repo_name/settings/secrets/actions

you are going to need an ssh private key that your deployment server is aware of (add public key to servers .ssh/authorized_keys) and add the ssh private key as a repo secret

create action workflows

@javier-menendez
javier-menendez / sqlite3_disable_referential_to_rails_5.rb
Last active July 11, 2024 22:33
Rails 5 initializer for disable foreign keys during `alter_table` for sqlite3 adapter
require 'active_record/connection_adapters/sqlite3_adapter'
#
# Monkey-patch for disable foreign keys during `alter_table` for sqlite3 adapter for Rails 5
#
module ActiveRecord
module ConnectionAdapters
class SQLite3Adapter < AbstractAdapter