Skip to content

Instantly share code, notes, and snippets.

View frankyston's full-sized avatar
🎯
Ruby on Rails is Fun

Frankyston Lins frankyston

🎯
Ruby on Rails is Fun
View GitHub Profile
@kyrylo
kyrylo / colorized_logger.rb
Last active November 9, 2024 16:06
Nice colorized logs for Rails apps! With this initializer, you can instantly colorize your Rails development logs. Just copy and paste the code, and it’ll work. https://x.com/kyrylosilin/status/1852308566201237815
# frozen_string_literal: true
# config/initializers/colorized_logger.rb
# This initializer adds color to the Rails logger output. It's a nice way to
# visually distinguish log levels.
module ColorizedLogger
COLOR_CODES = {
debug: "\e[36m", # Cyan
info: "\e[32m", # Green
warn: "\e[33m", # Yellow
@frankyston
frankyston / httparty.rb
Created October 9, 2024 19:03 — forked from jeffdonthemic/httparty.rb
HTTParty Examples
options = { :body =>
{ :username => 'my',
:password => 'password'
}
}
results = HTTParty.post("http://api.topcoder.com/v2/auth", options)
##
## example for post with papertrail and basic auth
##
# In your Gemfile
gem "localhost"

# Then, depending on your desired server
gem "falcon"
gem "puma"
@lazaronixon
lazaronixon / medical_record.rb
Last active June 22, 2024 17:01
Api upload
class MedicalRecord < ApplicationRecord
enum kind: %i[ imaging results notes ]
belongs_to :patient, class_name: "User", inverse_of: :medical_records
has_one_attached :document, dependent: :detach
scope :with_kind, -> (kind) { where kind: kind }
after_create_commit :deliver_updation
@peterc
peterc / embedding_store.rb
Last active December 28, 2023 06:27
Using SQLite to store OpenAI vector embeddings from Ruby
# Example of using SQLite VSS with OpenAI's text embedding API
# from Ruby.
# Note: Install/bundle the sqlite3, sqlite_vss, and ruby-openai gems first
# OPENAI_API_KEY must also be set in the environment
# Other embeddings can be used, but this is the easiest for a quick demo
# More on the topic at
# https://observablehq.com/@asg017/introducing-sqlite-vss
# https://observablehq.com/@asg017/making-sqlite-extension-gem-installable
@thiagofm
thiagofm / pattern_matching_magic.rb
Created September 5, 2022 11:11
Pattern Matching Magic
# Creating a complex hash, with nested keys
my_complex_hash = {
users: [
{name: "Yukihiro Matsumoto", age: 57},
{name: "Kabosu the Shiba Inu", age: 16},
{name: "Thiago Massa", age: 33}
]
}
@st0012
st0012 / debugging_challenge.md
Last active August 29, 2022 07:35
Debugging Challenge

Introduction

This challenge tests if you can locate the cause of a Rails issue in 5 iterations (script execution). Although it's a Rails issue, prior knowledge on Rails is not required.

The 5 iterations limit may feel constraining, but it is intentional. If you can't locate the cause within the limitation, that's totally fine.

After the challenge, there's a simple questionnaire. If you can answer the questions, it'll help me prepare my talk for RubyKaigi. Any feedback will be appreciated 🙏

I recommend allocating 1.5 hr for the challenge and the questions

@faermanj
faermanj / aws-nuke.yml
Last active May 8, 2023 15:59
Limpando sua conta da AWS com aws-nuke
accounts:
"192912639870": {} # ccsandbox
account-blocklist:
- "192912699999"
resource-types:
excludes:
- IAMGroup
- IAMGroupPolicy
@hopsoft
hopsoft / README.md
Last active January 14, 2024 11:58
Smart Heroku Review Apps managed by GitHub Actions

Smart Heroku Review Apps managed by GitHub Actions

This gist aims to provide a simple solution for managing Heroku Review Apps with GitHub Actions due to the security incident that continues to disrupt Heroku's GitHub integration. Watch the demo to learn more.

Demo Video

.github
├── workflows
│   ├── heroku_review_app_create.yml
@leandro
leandro / curry.js
Last active December 20, 2021 15:04
A curry function on JS
const curry = (fn, arity = null) => {
const realArity = fn.length;
const providedArity = arity === null ? realArity :
(arity > realArity ? realArity : arity);
return (...args) => {
const argsUsed = args.length > providedArity ? providedArity : args.length;
const finalFn = fn.bind(this, ...args.slice(0, argsUsed));
return realArity === argsUsed ? finalFn() : curry(finalFn);