TILs - Fueling Curiosity, One Insight at a Time

At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.

Published
Author
user-image
Satya
to terminate google chrome sessions -> pkill -9 "Google Chrome" .
#terminate-session
Published
Author
user-image
Satya
Ruby Heredoc Syntax & Rails .squish method:
• Bad - Regular heredoc (<<) keeps all whitespace

Code

query = <<SQL
    SELECT *
    FROM users
SQL
# Result: "    SELECT *\n    FROM users\n"


• Good - Squiggly heredoc (<<) removes leading whitespace

```
query = <<
SQL
SELECT *
FROM users
SQL
# Result: "SELECT \nFROM users\n"
```

• *
Best - Rails .squish removes all extra whitespace/newlines

Code

query = <<~SQL.squish
    SELECT *
    FROM   users
    WHERE  active = true
SQL
# Result: "SELECT * FROM users WHERE active = true"


#ruby-heredoc #rails-squish
Published
Author
user-image
Puneeth kumar
System Analyst
TimescaleDB

When working with time series data like stock prices, website traffic, or error logs, the volume of data grows rapidly over time. In traditional relational databases like PostgreSQL and SQL, this can lead to slower query performance as the dataset becomes larger.

One alternative is to use NoSQL databases, but they come with their own challenges, such as lack of strong ACID compliance, complex querying, and difficulties in handling structured relational data.

TimescaleDB, which is built on top of PostgreSQL, offers a powerful solution by introducing hypertables - a special type of table optimised for time series data. Hypertables enable faster read and write operations, automatic partitioning, and efficient data compression. Additionally, TimescaleDB provides advanced analytical functions, making it easier to perform complex queries for reporting, trend analysis, and forecasting. This makes it a great choice for applications that require efficient storage and analysis of large-scale time series data.

#databases #time_series_data #timescale_db #postgres
Published
Author
user-image
Aditya Vishwakarma
System Analyst
We can't use turbo frame for table rows, because html doesn't allow external tag like turbo frame inside the table.

The workaround this is to just have unique id for element you want to modify and use turbosteam to modify only that element.

#rubyonrails #turbo #turboframes #spa
Published
Author
user-image
Satya
in ruby https://nil.to|nil.to_i => 0 & https://nil.to|nil.to_f => 0.0
#ruby, #nil-conversion
Published
Author
user-image
Sujay
Steps to merge one repo into another

Step 1: Clone Repo1 locally

Code

git clone  repo1
cd repo1


Step 2: Fetch all the branches and commits from Repo2

Code

git remote add repo2 
git fetch repo2


Step 3: Create a branch

Code

git checkout -b merge-repo2


Step 4: Merge keeping full history

Code

git merge --allow-unrelated-histories repo2/main (Since the repositories have separate histories, this option allows Git to combine them, potentially requiring manual conflict resolution)


Step 5: Resolve Merge Conflicts

Code

git add .
git commit -m "Resolved merge conflicts"


#git
Published
Author
user-image
Mohammad hussain
System Analyst
pagy_array This method is the same as the generic pagy method, but specialized for an Array.

Code

require 'pagy/extras/array'
@pagy, @items = pagy_array(an_array)


#CU6U0R822 #ruby
Published
Author
user-image
Mohammad hussain
System Analyst

```
pagy_array
Published
Author
user-image
Nived Hari
System Analyst
each_with_object is an enumerable method in Ruby that allows you to iterate over a collection while building up an object (like an array or hash). Unlike map, which creates a new array, each_with_object lets you modify an existing object in a single pass.

Syntax

Code

collection.each_with_object(initial_object) do |item, object|
  # Modify the object inside the block
end


collection: The array or enumerable you're iterating over.
initial_object: The object that will be modified (e.g., {} for a hash or [] for an array).
item: The current element in the iteration.
object: The object that accumulates the results.
Example Usage
Using each_with_object with a Hash

Code

numbers = [1, 2, 3, 4, 5]
squares = numbers.each_with_object({}) do |num, hash|
  hash[num] = num**2
end

puts squares
# Output: {1=>1, 2=>4, 3=>9, 4=>16, 5=>25}


Why use each_with_object?
• Avoids the need to initialize an empty {} before the loop.
• Eliminates the need to return the object explicitly.

#CU6U0R822 #ruby
Published
Author
user-image
Mohammad hussain
System Analyst
When to use collection_select over select in rails
Use collection_select when you need to populate a dropdown with a collection of ActiveRecord objects. It is built on top of select and provides a convenient way to display object attributes instead of a simple array of strings.
select is used for manually defining options, typically from an array of strings or key-value pairs.
collection_select is specifically designed for selecting records from an ActiveRecord collection, making it useful when working with database associations.

Showing 7 to 9 of 82 results

Ready to Build Something Amazing?

Codemancers can bring your vision to life and help you achieve your goals