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
Adithya Hebbar
System Analyst
Jupyter Labs
• To install Jupyter Labs in Mac using Homebrew:
Code
brew install jupyterlab
• To run Jupyter lab:
Code
jupyter lab
This will open JupyterLab in your default web browser.
#python #homebrew
Published
Author
Giritharan
System Analyst
The fields_for helper in Rails creates form bindings without rendering a tag. This is particularly useful for rendering fields for additional model objects within a single form.
Imagine you have a Book model with an associated Author model. You can create a single form for both the Book and Author models using the fields_for helper.
rails db:prepare in Ruby on Rails, This command sets up and prepares the database for my application, ensuring everything's ready to go, including populating the database. #rails #databasesetup
Published
Author
Soniya Rayabagi
Handling Terraform State Errors with S3 Backend: We use an S3 bucket to store our Terraform state. If Terraform fails to update the state, it creates an errored.tfstate file in your working directory. Reapplying will cause errors because the resources already exist. To fix this, push the errored state back to S3: terraform state push errored.tfstate
#devops #terraformstateS3 #errorhandling
Published
Author
Syed Sibtain
System Analyst
In Ruby, exception handling is done using begin, rescue, ensure, and end blocks. Here's a brief overview of how they work in a general Ruby context:
Code
begin # Code that might raise an exceptionrescue SomeExceptionClass => e # Code that handles the exceptionensure # Code that will always run, regardless of whether an exception was raisedend
begin: Marks the beginning of a block of code that might raise exceptions.
rescue: Specifies what to do if a specific exception is raised. We can rescue multiple exception types by chaining rescue blocks.
ensure: An optional block that will always execute, regardless of whether an exception was raised or rescued. It's useful for cleanup code that must run no matter what.
#ruby #rails
Published
Author
Syed Sibtain
System Analyst
Using Ruby's built-in URI::MailTo::EMAIL_REGEXP for email validation is generally better than using a custom regular expression due to its robustness, reliability, and maintenance by the Ruby core team.
Fixing Image Rendering in Rails with Active Storage How to fix the error PG::UndefinedTable: ERROR: relation "active_storage_attachments" does not exist
This error occurs because Active Storage in Rails relies on specific database tables (e.g., active_storage_attachments and active_storage_blobs) to store metadata about attached files. If these tables do not exist, Rails cannot store or retrieve the necessary metadata for file attachments, resulting in the mentioned error.
By following these steps, we ensure that the necessary Active Storage tables are created, allowing Rails to store and retrieve image metadata correctly.
Run Active Storage Installation:
Code
rails active_storage:install
Migrate the Database:
Code
rails db:migrate
Restart the Rails Server:
Code
rails server
Then in views we can simply use the helper and render the image