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
@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);
@leandronsp
leandronsp / main.rb
Created December 4, 2021 21:50
How to reduce time complexity of nested loops
require 'faker'
require 'benchmark'
def generate_groups
(1..1_000).map do |id|
{ id: id, name: Faker::Educator.primary_school }
end
end
def generate_users(groups_ids)
@leandronsp
leandronsp / sum_range.rb
Created December 4, 2021 15:30
Sum all numbers in a consecutive range
require 'benchmark'
def sum_range_using_for_loop(min, max)
range = (min..max)
sum = 0
for n in range
sum = sum + n
end
@Envek
Envek / login_helpers.rb
Created October 11, 2021 06:42
Signing-in user for integration tests via cookie-only session with Rails, Devise, Capybara, and Cuprite
# spec/system/support/login_helpers.rb
# See this blog post for setup guide: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
module LoginHelpers
def login_as(user)
# Craft session cookie to make request authenticated (to pass even routing constraints)
# Compilation of these:
# - https://dev.to/nejremeslnici/migrating-selenium-system-tests-to-cuprite-42ah#faster-signin-in-tests
# - https://turriate.com/articles/2011/feb/how-to-generate-signed-rails-session-cookie
# - https://github.com/rails/rails/blob/43e29f0f5d54294ed61c31ddecdf76c2e1a474f7/actionpack/test/dispatch/cookies_test.rb#L350
# backup
docker run -v [volume]:/volume --rm loomchild/volume-backup backup - > [backupfile.tar.bz2]
# restore
cat [backupfile.tar.bz2] | docker run -i -v [volume2]:/volume --rm loomchild/volume-backup restore -