Creează un cont pentru a te abona la acest blog și a-i urmări articolele pe pagina Lectură.
-
Rate limiting examples 🙌🏼 With Rails 8 upgrade, developers can now leverage built-in rate-limiting controls directly within their controllers 🚀 Advantages Prevents Abuse: Rate limiting deters spamming, brute-force attacks, and abusive behavior by controll…
-
Clear development log while start server 🗑 Do you find yourself manually clearing your Rails development logs often?
-
Passing argument with Array#first and Array#last Methods Did you know that you can pass an argument to the Array#first and Array#last methods to return a specific number of elements from the beginning or end of the array?
-
A better way to Convert a URL Query String to a Hash ✨ In Ruby on Rails, you might need to work with URL query strings when building web applications that interact with external APIs or handle user input.
-
Validate keys of hash using `assert_valid_keys` 🚧 Have you heard of the assert_valid_keys method for the Hash class in Rails?
-
Using `pluck` instead of `all` Instead of using the all method, which loads all records into memory, use the pluck method to retrieve specific columns from the database.
-
Use render with `respond_to` You can use the render method to display content in a different format such as JSON or XML.
-
Difference between `to_s` and `to_str` 🙌🏼 Let’s take an example of to_s and to_str here.
-
Numerical validation using `validates_comparison_of` 🙌🏼 Do you know you can use validates_comparison_of with Rails 7.0 that provides a way to easily validate comparisons with another value, proc, or attribute?
-
Usage of invert_where for inverting entire where clause 🙌🏼 With Rails 7.0, you can use invert_where to invert an entire where clause instead of manually applying conditions 💣 Reference - Rails PR #40249 Code snippet 📌 # Version: Rails 7.0 class User scope…
-
Usage of authenticate_by for preventing timing-based enum attacks ⏳ 🙌🏼 Add authenticate_by when using has_secure_password. authenticate_by is intended to replace code like the following, which returns early when a user with a matching email is not found:…
-
Freezing string to improve performance 🙌🏼 Advantage - If you freeze string object, it’ll not allocate new memory and it improves app performance by saving time for garbage collection 🔥 Reference - Ruby Optimization with One Magic Comment Code snippet 📌 def
-
Always use is_a?
-
Use of xxx_changed?
-
Multiple each_xxx method on string 🙌🏼 Do you know there are multiple each_xxx methods available on String?
-
values_at method to retrieve multiple non-sequential values 🙌🏼 Do you know you can use values_at to retrieve multiple non-sequential values from array or hash?
-
Using underscore to make large number more readable ⚡️ Do you know we can use underscore to make large number more readable in ruby?
-
Numerical comparison using `range` and `between` 😊 Do you know we can use range or between to do numerical comparison in ruby?
-
Different ways to call a method in Ruby!
-
Customize default getter/setter methods(attr_accessor) ✌🏼 Wanted to customize default getter/setter methods available in ruby called attr_accessor?
-
Recently, the Indian govt announced vaccination for 18-45 age group from 1st May ✨ Anyone who wants to vaccinate in this age group can visit official website or install Arogya Setu App from Google Play to book a slot for vaccination.
-
Symbols can best be described as identities.
-
Use customized starting index with each_with_index while using Enumerator 🙌🏼 In your Ruby on Rails project, you can use each.with_index(starting-index) instead of each_with_index if you wanted to customize starting index of enumerator(Array) Code snippet 📌
-
𝗥𝘂𝗯𝘆 𝟯.𝟬 is released and here are list of improvements ⚡️ 📌 In some benchmarks Ruby3.0 is three times faster than Ruby2.0 📌 Lot many performance improvements in Method Based Just-in-Time Compiler 📌 With Ractor, along with Async Fiber, Ruby will be a real…
-
Easy way to clean Sidekiq Jobs Cheat-Sheet 💣 Easy way to clean Sidekiq Jobs Cheat-Sheet 💣 Code snippet 📌 ❯ require 'sidekiq/api' # Clear retry set ❯ Sidekiq::RetrySet.new.clear # Clear scheduled jobs ❯ Sidekiq::ScheduledSet.new.clear # Clear 'Dead' jobs ❯…
-
Image from Unsplash There are certain characteristics that differentiate great developers from good developers.
-
Array operations in Ruby 🗄 Easy way to get the intersection, union, and subset of arrays in Ruby 👇🏼 Code snippet 📌 x = [1, 1, 2, 4] y = [1, 2, 2, 2] # intersection x & y # => [1, 2] # union x | y # => [1, 2, 4] # difference x - y # => [4]
-
Handy numerical methods 🔖 Handy numerical methods you can use on daily basis in comparison statements in Ruby 🧮 Code snippet 📌 ❯ num = 10 ❯ num.even?
-
Difference between `merge` & `deep_merge` 🤔 Use deep_merge instead of merge if you want to merge two hash objects recursively 🌟 Code snippet 📌 ❯ person1 = { name: 'Rishi', address: { area: 'Baner' } } ❯ person2 = { name: 'Rishi', address: { city: 'Pune' }…
-
Image from unsplash.com I’ve been nominated in the 2020 #Noonies, Hacker Noon’s annual awards!
-
List all TODO tasks from Ruby on Rails Project 🔖 To get all # TODO tasks from your Ruby on Rails project you can use rake notes It’ll search for comments beginning with a specific keyword and also give filename and line 📋 Code snippet 📌 # list down all co…
-
Better way to write website(URL) Validation ✨ Use URI::regexp(%w(http https)) in your Ruby on Rails model, to increase readability of website(URL) validation.
-
Like operator in MongoDB 🧩 A good way to use operator LIKE in Ruby on Rails while using MongoDB 💡 Code snippet 📌 # app/models/mongoid/base_model.rb module Mongoid module BaseModel extend ActiveSupport::Concern module ClassMethods def _search_(k, v) if k &&
-
Better way to split an array using Partition ⛓ Imagine you could, in one line, split an array into two arrays based on a condition 🤔 Now stop imagining, you can do exactly that with partition 🤩 Code snippet 📌 # ok: let's split an array to an odd array and…
-
Safe Navigation Operator (&.)
-
Better way to write Email Validation ✨ Use URI::MailTo::EMAIL_REGEXP in your Ruby on Rails model, to increase readability of email validation.
-
Convert Array of Hashes to Hash!
-
Rails console from one of my Rails Project It´s better to wait for a productive programmer to become available than it is to wait for the first available programmer to become productive. — Steve McConnell What is ~/.irbrc file?
-
Image from unsplash.com In last few years, social media has made the world a more connected place.
-
Image from unsplash.com After a few years of continuous development, your rails application becomes larger and it’s good practice to do some cleanup.
-
Credits: Google Images whenever gem is used when there’s need of run specific job at particular intervals, say - - send invoices - send daily reports - send reminder notifications etc..
-
Credits: Google Images Validations They are used to ensure that only valid data is saved into your database. i.e. check user email presence, check email uniqueness etc.
-
Workspace is used to organize your apps into tasks. i.e. you may keep your chat applications in one workspace and coding ide into other workspace.
-
Hello!