Skip to content

Instantly share code, notes, and snippets.

View olivierbuffon's full-sized avatar
💎
Doing awesome stuff with Ruby on Rails

Olivier Buffon olivierbuffon

💎
Doing awesome stuff with Ruby on Rails
View GitHub Profile

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
import { useMemo } from 'react';
import {
ApolloClient,
HttpLink,
ApolloLink,
InMemoryCache,
NormalizedCacheObject,
concat,
} from '@apollo/client';
import { createPersistedQueryLink } from '@apollo/client/link/persisted-queries';
@stevegeek
stevegeek / action_policy_authorization_client.rb
Last active September 25, 2023 15:27
Avo Authorization client for`action_policy`
# frozen_string_literal: true
module Avo
class ActionPolicyAuthorizationClient
include ActionPolicy::Behaviour
def authorize(user, record, action, policy_class: nil)
authorize!(record, to: action, with: policy_class, context: {user: user})
rescue ActionPolicy::NotFound => error
raise NoPolicyError.new error.message
@zealot128
zealot128 / lspconfig-tailwind-rubyfiles.lua
Last active December 18, 2024 22:46
Neovim Tailwindcss with custom files (Ruby, ViewComponents, Phlex etc.)
local lspconfig = require('lspconfig')
-- https://github.com/tailwindlabs/tailwindcss-intellisense/issues/737
lspconfig.tailwindcss.setup {
--on_attach = on_attach,
--flags = lsp_flags,
filetypes = { "aspnetcorerazor", "astro", "astro-markdown", "blade", "clojure", "django-html", "htmldjango", "edge", "eelixir", "elixir", "ejs", "erb", "eruby", "gohtml", "haml", "handlebars", "hbs", "html", "html-eex", "heex", "jade", "leaf", "liquid", "markdown", "mdx", "mustache", "njk", "nunjucks", "php", "razor", "slim", "twig", "css", "less", "postcss", "sass", "scss", "stylus", "sugarss", "javascript", "javascriptreact", "reason", "rescript", "typescript", "typescriptreact", "vue", "svelte", "ruby" },
init_options = {
userLanguages = {
@mabenson00
mabenson00 / cheatsheet.rb
Last active October 2, 2025 16:36
Rails Postgres ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@itkrt2y
itkrt2y / association.rb
Last active September 3, 2024 11:45
Association dataloader with graphql-ruby
# official docs: https://graphql-ruby.org/dataloader/sources.html
# app/graphql/sources/association.rb
class Sources::Association < ::GraphQL::Dataloader::Source
def initialize(association_name, scope = nil)
@association_name = association_name
@scope = scope
end
def fetch(records)
-- Eviline config for lualine
-- Author: shadmansaleh
-- Credit: glepnir
local lualine = require 'lualine'
-- Color table for highlights
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
@jesster2k10
jesster2k10 / README.md
Last active September 12, 2025 13:27
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:

@Tamal
Tamal / git-ssh-error-fix.sh
Last active October 31, 2025 02:02
Solution for 'ssh: connect to host github.com port 22: Connection timed out' error
$ git clone [email protected]:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
$ # This should also timeout
$ ssh -T [email protected]
ssh: connect to host github.com port 22: Connection timed out
$ # but this might work
@cdesch
cdesch / rails_generator_cheat_sheet.md
Last active November 13, 2025 15:54
Rails Generator CheatSheet

Cheat Sheets are greate but they are not a substitute for learning the framework and reading the documentation as we most certainly have not covered every potential example here. Please refer to the Rails Command Line Docs for more information.

Command Line Generator Info

Reference

You can get all of this information on the command line.

rails generate with no generator name will output a list of all available generators and some information about global options. rails generate GENERATOR --help will list the options that can be passed to the specified generator.