<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Gaurish Sharma Live | Sharing What I Have Learned</title>
    <link>http://www.gaurishsharma.com</link>
    <atom:link href="http://www.gaurishsharma.com/feed.xml" rel="self" type="application/rss+xml" />
    <description>Learning by Doing & Sharing What I have learned</description>
    <language>en-us</language>
    <pubDate>Tue, 15 Oct 2024 06:36:56 +0000</pubDate>
    <lastBuildDate>Tue, 15 Oct 2024 06:36:56 +0000</lastBuildDate>

    
      <item>
        <title>Evaluation of iPaaS</title>
        <link>http://www.gaurishsharma.com/2023/09/evaluation-of-ipaas.html</link>
        <pubDate>Thu, 07 Sep 2023 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;&lt;strong&gt;Introduction to iPaaS:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Integration Platform as a Service, or iPaaS, is a suite of cloud services that enables users to create, manage, and govern integration flows connecting a range of applications and data sources. It’s designed to streamline connectivity and ensure seamless data transfer across multiple systems, devices, and environments. As businesses increasingly move to the cloud and adopt Software as a Service (SaaS) applications, the need for iPaaS solutions to bridge the gaps between these systems becomes paramount.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Evaluation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MuleSoft&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Features:&lt;/p&gt;

&lt;p&gt;Offers Anypoint Platform that connects apps, data, and devices across on-premises and cloud computing environments.
Powerful API-led connectivity approach.
DataWeave, a transformation language and framework.
Anypoint Exchange, a library for reusable IT assets.
Support for microservices architecture.
Maturity:
Acquired by Salesforce in 2018, MuleSoft has a rich history and has been a leader in the industry for over a decade.
Architecture:&lt;/p&gt;

&lt;p&gt;Uses a hybrid approach, allowing integrations in both cloud and on-premises systems.
API-centric architecture promoting reusable components.
AI Capabilities:&lt;/p&gt;

&lt;p&gt;Offers Anypoint Monitoring, which provides advanced insights through machine learning.
Other Observations:&lt;/p&gt;

&lt;p&gt;Integration with Salesforce makes it a preferable option for businesses already using Salesforce.
Relatively steeper learning curve for new users.
&lt;strong&gt;Dell Boomi&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Features:
AtomSphere platform for cloud-to-cloud, SaaS-to-SaaS, cloud-to-on-premises, on-premises-to-on-premises and B2B integration.
Boomi Flow for workflow automation and app development.
Master Data Hub to ensure data integrity.
Maturity:
Established in 2000 and acquired by Dell in 2010, it has a longstanding presence in the market.
Architecture:
Atom-based architecture, where “Atoms” are runtime engines and can be deployed in multiple environments.
AI Capabilities:
Boomi’s Insight feature provides AI-driven recommendations to assist users in building integration processes.
Other Observations:
Has a user-friendly drag-and-drop interface.
Strong community and a vast library of pre-built connectors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workato&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;
Recipe-based approach, where integrations are designed as recipes.
Offers a marketplace of prebuilt connectors and integration solutions.
Workflow automation with support for multiple business apps.
Maturity:
Founded in 2013, it’s younger than the others but has quickly gained traction.
Architecture:
Cloud-native platform but can connect with on-premises applications through on-prem agents.
AI Capabilities:
Offers Workbot, an AI-driven bot that integrates with chat platforms like Slack and Microsoft Teams.
Automation recipes leverage machine learning for data mapping and transformation.
Other Observations:
Known for its simplicity and agility.
Widely adopted by businesses for its ease of use and quick time-to-value.
Observations &amp;amp; Recommendations:&lt;/p&gt;

&lt;p&gt;Complexity and Learning Curve: MuleSoft, though powerful, can be complex and may require more time to onboard. Workato, on the other hand, is known for its ease of use and quick integration setups.&lt;/p&gt;

&lt;p&gt;Architecture Fit: Dell Boomi’s Atom-based architecture is versatile and can be a good fit for complex hybrid setups. Businesses purely focusing on cloud might find Workato more aligned with their needs.&lt;/p&gt;

&lt;p&gt;AI Capabilities: All three platforms are integrating AI in their offerings, but the way they do it varies. Workato’s Workbot and AI-driven automation recipes stand out in terms of direct business application.&lt;/p&gt;

&lt;p&gt;Integration Needs: If a business is already using Salesforce or is planning to, MuleSoft might be a natural choice due to its tight integration. Dell Boomi and Workato offer a broad spectrum of connectors which makes them suitable for various integration scenarios.&lt;/p&gt;

&lt;p&gt;**Conclusion: **The best iPaaS solution largely depends on the specific needs and preferences of the enterprise. It’s essential to analyze the existing IT landscape, integration requirements, and future scalability before making a decision.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Using Python to Establish SSL/TLS Encrypted Connections to AWS RDS MySQL 5.7</title>
        <link>http://www.gaurishsharma.com/2023/03/using-python-to-establish-ssl-tls-encrypted-connections-to-aws-rds-mysql-5-7.html</link>
        <pubDate>Sun, 26 Mar 2023 21:54:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;Are you trying to connect to your AWS RDS MySQL database using Python? If so, you might encounter some challenges due to the additional security measures provided by AWS, such as Transport Layer Security (TLS). In this tutorial, we’ll show you how to connect to your AWS RDS MySQL database on Python with TLS enabled.&lt;/p&gt;

&lt;h2 id=&quot;why-encrypt-internal-mysql-connections&quot;&gt;Why encrypt internal Mysql connections?&lt;/h2&gt;
&lt;p&gt;In today’s security landscape, enabling encryption at all layers of an application is of utmost importance. This means that sensitive information should be encrypted in transit as well as at rest. Furthermore, it is crucial to adopt a “zero trust” approach to application security. This approach means that access to resources should not be granted based solely on the user’s network location or credentials. Instead, all requests for access should be authenticated and authorized before any access is granted. This strategy helps prevent unauthorized access, reduces the risk of data breaches, and enhances overall security posture.&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;Before we start, make sure that you have the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;An AWS RDS MySQL database instance&lt;/li&gt;
  &lt;li&gt;Python 3.x installed on your local machine&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql-connector-python&lt;/code&gt; package installed on your local machine&lt;/li&gt;
  &lt;li&gt;IAM user credentials with access to your AWS RDS instance&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;enable-tls-in-aws-rds&quot;&gt;Enable TLS in AWS RDS&lt;/h2&gt;

&lt;p&gt;Before we can connect to our AWS RDS MySQL database with TLS enabled, we need to configure our database instance to use SSL/TLS encryption. To do this, follow these steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Log in to your AWS Management Console.&lt;/li&gt;
  &lt;li&gt;Navigate to the RDS service.&lt;/li&gt;
  &lt;li&gt;Select your MySQL instance.&lt;/li&gt;
  &lt;li&gt;Click on the “Modify” button.&lt;/li&gt;
  &lt;li&gt;Under “Advanced Settings,” find the “SSL/TLS” option.&lt;/li&gt;
  &lt;li&gt;Set the “SSL/TLS” option to “Enabled.”&lt;/li&gt;
  &lt;li&gt;Click on the “Continue” button and apply the changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you’ve completed these steps, your AWS RDS MySQL instance will be configured to use SSL/TLS encryption.&lt;/p&gt;

&lt;h2 id=&quot;connect-to-aws-rds-mysql-on-python-with-tls&quot;&gt;Connect to AWS RDS MySQL on Python with TLS&lt;/h2&gt;

&lt;p&gt;To connect to our AWS RDS MySQL database on Python with TLS enabled, we need to use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql-connector-python&lt;/code&gt; package, which can be installed via pip:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;mysql-connector-python
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, we need to create a Python script that connects to our AWS RDS MySQL database. Here’s an example script that you can use:
&lt;script src=&quot;https://gist.github.com/gaurish/784be8b6bf44010307fac1aaa9961fcc.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;Replace the placeholders (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;db_username&amp;gt;&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;db_password&amp;gt;&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;db_endpoint&amp;gt;&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;db_name&amp;gt;&lt;/code&gt;) with your own values.
Python code snippet above demonstrates how to establish a secure TLS connection to an Amazon Web Services (AWS) Relational Database Service (RDS) instance running MySQL 5.7. The code makes use of the ssl and mysql-connector-python libraries to establish the secure connection.&lt;/p&gt;

&lt;p&gt;The code begins by importing the necessary libraries and defining the credentials and endpoint of the AWS RDS instance to which the secure connection needs to be established. The next step is specifying the path to trusted CA certificates that will be used to verify the server’s identity. This trusted CA certificate is provided by AWS RDS on their documentation page.&lt;/p&gt;

&lt;p&gt;Once the SSL context has been created, the mysql-connector-python library is used to create a connection object that uses the SSL context to establish a secure connection to the AWS RDS instance. The code then prints the version of the MySQL server that it has connected to, which serves as a confirmation that the secure connection has been established successfully.&lt;/p&gt;

&lt;h2 id=&quot;documentation-links&quot;&gt;Documentation Links&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html&quot;&gt;AWS Doc - Using SSL/TLS to encrypt a connection to a DB instance&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://dev.mysql.com/doc/connector-python/en/connector-python-introduction.html&quot;&gt;Official docs for Python lib from Mysql&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;

</description>
      </item>
    
      <item>
        <title>Use AWS CLI With Multiple Accounts and MFA</title>
        <link>http://www.gaurishsharma.com/2017/12/use-aws-cli-with-multiple-accounts-and-mfa.html</link>
        <pubDate>Sun, 17 Dec 2017 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;Hello Readers,
I am back to blogging after gap of years. This is part of my new year resolution of executing on the my original vision for this blog - “Sharing what I have learned”. Can’t believe its been a decade. However, this new year will give me fresh vigor to restart blogging.&lt;/p&gt;

&lt;p&gt;Back to Topic,
The Use-Case that I would be explaining today makes following assumtions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;You have multiple AWS Accounts&lt;/strong&gt; - These days, most compnaies follow AWS Multiple Account Security Strategy where they have seperate accounts their development and production resources with Cross-Account access . In addition, at some people will create seperate a “Jump AWS Account” where only IAM is configured in Jump account &amp;amp; for every other purpose, the users are expected to login to different AWS account(development AWS account, Production AWS Account etc).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multi-Factor Authentication(MFA) is required&lt;/strong&gt; - AWS Multi-Factor Authentication (MFA) is a security best practice that adds an extra layer of protection on top of your user name and password. In this case, cross-account access is protected using MFA. With MFA enabled, when a user signs in to an AWS website, they will be prompted for their user name and password (the first factor—what they know), as well as for an authentication code from their AWS MFA device (the second factor—what they have).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;CrossAccount Assume Role between Development &amp;amp; Production Account is setup&lt;/strong&gt; on AWS web Console. You are able to login to “Jump AWS Account” which could be a seperate account or same as your development acccount.  From this “Jump AWS Account”, We assume you are able to Jump to production aws account from AWS Web Console using “&lt;em&gt;Switch Role&lt;/em&gt;” feature.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;http://www.gaurishsharma.com/AWS_Management_Console.png&quot; alt=&quot;Screenshot of Switch Role Feature in AWS Console &quot; /&gt;&lt;/p&gt;

&lt;p&gt;If the above three are already given then please continue.  In later tutorials, I might talk about how to setup multiple AWS accounts with  Cross Account Access along with MFA but that’s a seperate tutorial. For now we will assume that you already have that work.  If not, please stop &amp;amp; first complete  the step #1, #2, and #3.&lt;/p&gt;

&lt;h3 id=&quot;goal---setup-aws-cli-for-multiple-aws-accounts-with-cross-account-access-along-with-mfa&quot;&gt;Goal - Setup AWS CLI for Multiple AWS Accounts with Cross Account Access along with MFA&lt;/h3&gt;
&lt;p&gt;The AWS Command Line Interface (CLI) is a python cased CLI application that allows you to manage your AWS services., same way as AWS Web console. But where the AWS CLI really shines is that you can use it to control multiple AWS services from the command line and automate them through scripts. Automatition is hard to do from Web console but its easy to write a shell script that automates routine tasks like launching a new instances, searching given IP address belongs to which instances.&lt;/p&gt;

&lt;p&gt;Our goal for this tutorial is going to be that you are able to have cross access to Development, Production or any other aws account you may have using single Access Key ID, Access Key Secret &amp;amp; MFA Token devise that is registered on your “Jump AWS Account” using AWS Security Token Service (STS)’s  &lt;a href=&quot;http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html&quot;&gt;Assume-Role&lt;/a&gt; feature.&lt;/p&gt;

&lt;h2 id=&quot;step-1---configure-secret-key--secret-id-&quot;&gt;Step 1 - Configure Secret Key &amp;amp; Secret ID 🔑&lt;/h2&gt;
&lt;p&gt;Download &amp;amp; install AWS CLI  as &lt;a href=&quot;https://aws.amazon.com/cli/&quot;&gt;documented on AWS CLI Website&lt;/a&gt;, for Linux/Mac, its as simple as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ pip install awscli&lt;/code&gt;. Next we will configure AWS CLI with Access Key ID, &amp;amp; Access Key Secret from “Jump AWS Account”. Please login to your “Jump AWS Account”, got IAM &amp;amp; generate Access Key ID, &amp;amp; Access Key Secret if you haven’t already done . Once you have them, please run aws configure &amp;amp; set them in on your machine.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ aws configure
AWS Access Key ID [None]: AKIAJE2IKK4QQPJWD9TT
AWS Secret Access Key [None]: ilNxOf7JK7VIopEov35+ne/cPWApNZyQtO3hRGHH
Default region name [None]: us-east-1 #your fav region
Default output format [None]: 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Based on this, AWS CLI will create two files: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.aws/credentials&lt;/code&gt; &amp;amp; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.aws/config&lt;/code&gt;. they should look like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cat ~/.aws/config

[default]
region = us-east-1
output = text

$ cat ~/.aws/credentials

[default]
aws_access_key_id = AKIAJE2IKK4QQPJWD9TT
aws_secret_access_key = ilNxOf7JK7VIopEov35+ne/cPWApNZyQtO3hRGHH
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To confirm, everything is setup correctly. Let fetch the user using the secret key id &amp;amp; Secret access key, it should return info similar to shown below:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ aws iam get-user --profile gaurish
{
    &quot;User&quot;: {
        &quot;Path&quot;: &quot;/&quot;,
        &quot;UserName&quot;: &quot;gaurish&quot;,
        &quot;UserId&quot;: &quot;AIWAJLPBAQHB8EH75KFDI&quot;,
        &quot;Arn&quot;: &quot;arn:aws:iam::111111111111:user/gaurish&quot;,
        &quot;CreateDate&quot;: &quot;2017-12-10T07:12:04Z&quot;,
        &quot;PasswordLastUsed&quot;: &quot;2017-12-17T08:59:02Z&quot;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If you do not get above output then, the AWS Access Key ID &amp;amp; AWS Secret Access Key are incorrectly setup in Setup #1. Please verify &amp;amp; try again.&lt;/p&gt;

&lt;h2 id=&quot;setup-2---get-mfa-device-details&quot;&gt;Setup 2 - Get MFA device details&lt;/h2&gt;
&lt;p&gt;Next step, is to get MFA device serial Number as shown below:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ aws iam list-mfa-devices
{
    &quot;MFADevices&quot;: [
        {
            &quot;UserName&quot;: &quot;gaurish&quot;,
            &quot;SerialNumber&quot;: &quot;arn:aws:iam::111111111111:mfa/gaurish&quot;,
            &quot;EnableDate&quot;: &quot;2017-12-17T09:59:02Z&quot;
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;However, if you get output similar to given below:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ aws iam list-mfa-devices
{
    &quot;MFADevices&quot;: []
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then you hasn’t configured MFA which you should do as &lt;a href=&quot;http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_enable_virtual.html&quot;&gt;per the doc&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;step-3---get-role-arn&quot;&gt;Step 3 - Get Role ARN&lt;/h2&gt;
&lt;p&gt;An IAM role is a authorization tool that lets a user gain additional permissions, or get permission to perform actions in a different account.So idea here is that you create a Role in your target account, say in Production account which users in your “AWS Jump Account” can assume . You will have to create this Role in your production account, if not already done.More information can be found in &lt;a href=&quot;http://docs.aws.amazon.com/cli/latest/userguide/cli-roles.html&quot;&gt;Assume-Role Documentation &lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;From Step 3, you should have have role arn which will be somewhat like this:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arn:aws:iam::222222222222:role/JumpAccountDeveloperAccess&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;step-4---set-role-arn--mfa-in-aws-cli&quot;&gt;Step 4 - Set Role ARN &amp;amp; MFA in AWS CLI&lt;/h2&gt;
&lt;p&gt;The role arn of production aws account we have from #3 is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arn:aws:iam::222222222222:role/JumpAccountDeveloperAccess&lt;/code&gt; &amp;amp; MFA serial number from step #2 is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arn:aws:iam::111111111111:mfa/gaurish&lt;/code&gt;. Now all we got to do set these in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.aws/config&lt;/code&gt; for production profile, then we will be able to access production using credentials “AWS Jump Account”. this is how the config will look after edits:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[default]
region = us-east-1
output = text
[profile production]
mfa_serial = arn:aws:iam::111111111111:mfa/gaurish@gmail.com
role_arn = arn:aws:iam::222222222222:role/JumpAccountDeveloperAccess
region = us-east-1
source_profile = default
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, let’s try to see user logged into details:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ aws sts get-caller-identity --profile production
Enter MFA code:
{
    &quot;UserId&quot;: &quot;AROBJE5V62ESHW3JBJO5M:AWS-CLI-session-1513512076&quot;,
    &quot;Account&quot;: &quot;222222222222&quot;,
    &quot;Arn&quot;: &quot;arn:aws:sts::222222222222:assumed-role/JumpAccountDeveloperAccess/AWS-CLI-session-1513512076&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first time we do this we will be prompted for our MFA code. By default, it won’t have to be re-entered for 1 hour. However, if we execute commands for a different account, we will be asked to enter our code again. Further, instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--profile production&lt;/code&gt; on every call which gets tiring, you can just export &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;export AWS_PROFILE=production&lt;/code&gt; &amp;amp; then all subsequent calls will use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;production&lt;/code&gt; profile.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ aws sts get-caller-identity
{
    &quot;UserId&quot;: &quot;AROBJE5V62ESHW3JBJO5M:AWS-CLI-session-1513512076&quot;,
    &quot;Account&quot;: &quot;222222222222&quot;,
    &quot;Arn&quot;: &quot;arn:aws:sts::222222222222:assumed-role/JumpAccountDeveloperAccess/AWS-CLI-session-1513512076&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;to switch back, you can &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;export AWS_PROFILE=default&lt;/code&gt;,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ aws sts get-caller-identity
{
    &quot;UserId&quot;: &quot;AIDAJFFF4RORRWDXZDVSG:AWS-CLI-session-1513512166&quot;,
    &quot;Account&quot;: &quot;111111111111&quot;,
    &quot;Arn&quot;: &quot;arn:aws:sts::111111111111:assumed-role/JumpAccountDeveloperAccess/AWS-CLI-session-1513512166&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you have gotten this far, then you have completed the tutorial. with this, Command line scripts that now you can write can easily be used in batch files or scripts, which is great for automation. now, think of all the common operations you have to do  on AWS Web Console&amp;amp; automate them via AWS CLI.&lt;/p&gt;

&lt;p&gt;More Power to you!&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Guide for Using ARel in Rails Where ActiveRecord Doesn't Cut It</title>
        <link>http://www.gaurishsharma.com/2015/09/guide-for-using-arel-in-rails-where-activerecord-doesnt-cut-it.html</link>
        <pubDate>Sun, 27 Sep 2015 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;ARel is a database agnostic library that ActiveRecord record uses under the covers. It can be used to generate advanced SQL queries.&lt;/p&gt;

&lt;h2 id=&quot;activerecord-public-api&quot;&gt;ActiveRecord Public API&lt;/h2&gt;
&lt;p&gt;ActiveRecord handles majority of the use-cases pretty well. for example, you want to use ActiveRecord for:&lt;/p&gt;

&lt;h3 id=&quot;searching-for-equality&quot;&gt;Searching for equality&lt;/h3&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;hello&apos;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE &quot;posts&quot;.&quot;title&quot; = &apos;hello&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;searching-for-nulls&quot;&gt;Searching for NULLs&lt;/h3&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE &quot;posts&quot;.&quot;title&quot; IS NULL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;searching-for-either-of-given-values&quot;&gt;Searching for either of given values&lt;/h3&gt;
&lt;p&gt;suppose I want to search where title is ‘hello’ OR ‘hi’ OR ‘howdy’. pass all options as an array works&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;hello&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;hi&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;howdy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE &quot;posts&quot;.&quot;title&quot; IN (&apos;hello&apos;, &apos;hi&apos;, &apos;howdy&apos;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;searching-for-either-given-values-or-nulls&quot;&gt;Searching for either given values or NULLs&lt;/h4&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;hello&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;hi&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;howdy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE ((&quot;posts&quot;.&quot;title&quot; IN (&apos;hello&apos;, &apos;hi&apos;, &apos;howdy&apos;) OR &quot;posts&quot;.&quot;title&quot; IS NULL))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;searching-for-range-where-values-are-between-given-starting--end-values&quot;&gt;Searching for Range, where values are BETWEEN given starting &amp;amp; end values&lt;/h3&gt;
&lt;p&gt;suppose I want to search all posts published in last 2months&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;publishing_date: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;months&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ago&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;today&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (&quot;posts&quot;.&quot;publishing_date&quot; BETWEEN &apos;2014-04-09 04:25:23.704466&apos; AND &apos;2014-06-09&apos;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;searching-for-not&quot;&gt;Searching for NOT&lt;/h3&gt;
&lt;p&gt;Starting Rails 4, ActiveRecord has &lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods/WhereChain.html#method-i-not&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not&lt;/code&gt;&lt;/a&gt; which will negate the query, so all of the above queries when appended with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not&lt;/code&gt;, will work like this:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;hello&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (&quot;posts&quot;.&quot;title&quot; != &apos;hello&apos;)&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (&quot;posts&quot;.&quot;title&quot; IS NOT NULL)&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;hello&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;hi&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;howdy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (&quot;posts&quot;.&quot;title&quot; NOT IN (&apos;hello&apos;, &apos;hi&apos;, &apos;howdy&apos;))&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;title: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;hello&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;hi&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;howdy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (NOT ((&quot;posts&quot;.&quot;title&quot; IN (&apos;hello&apos;, &apos;hi&apos;, &apos;howdy&apos;) OR &quot;posts&quot;.&quot;title&quot; IS NULL)))&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;publishing_date: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;months&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ago&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;today&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (NOT (&quot;posts&quot;.&quot;publishing_date&quot; BETWEEN &apos;2014-04-09 04:58:40.232850&apos; AND &apos;2014-06-09&apos;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What about queries with that require &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LIKE&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt;(less than), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt;(greator than), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;=&lt;/code&gt;(less than equal to), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;=&lt;/code&gt;(greator than equal to) operators?&lt;/p&gt;

&lt;p&gt;As you might have guessed ActiveRecord doesn’t support generating queries with above operators, so what you do?&lt;/p&gt;

&lt;h3 id=&quot;more-operators-that-you-might-need&quot;&gt;More operators that you might need:&lt;/h3&gt;
&lt;p&gt;While working with SQL databases, you might feel the need to use the following operators.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;LIKE&lt;/strong&gt;:  used when to search a specific pattern&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt;(less than)&lt;/strong&gt;: Less than&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt;(greator than)&lt;/strong&gt;: Greater than&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;=&lt;/code&gt;(less than equal to)&lt;/strong&gt;: Less than or equal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;=&lt;/code&gt;(greator than equal to)`&lt;/strong&gt;: Greater than or equal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But ActiveRecord doesn’t support them. you could use “strings”. But what if your queries need certain amount of conditional in ruby? Enter ARel - ActiverRecord’s private API&lt;/p&gt;

&lt;h3 id=&quot;arel-methodspredicates-that-are-available-for-above-5operators&quot;&gt;Arel methods/predicates that are available for above 5operators&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Like&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;matches&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Less than&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lt&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Greater than&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gt&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Less than or equal&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lteq&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Greater than or equal&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gteq&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To be correct, &lt;a href=&quot;https://github.com/rails/arel/blob/master/lib/arel/predications.rb&quot;&gt;there are more&lt;/a&gt; but they are rarely used.&lt;/p&gt;

&lt;p&gt;Before we see each of the methods in details, lets first look on how to install/use ARel gem.&lt;/p&gt;

&lt;h3 id=&quot;how-do-i-install-arel&quot;&gt;How do I install ARel?&lt;/h3&gt;
&lt;p&gt;if you are using Rails/ActiveRecord, its already installed &amp;amp; configured! Every ActiveRecord model is backed by an Arel Table. try calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arel_table&lt;/code&gt; method on any ActiveRecord model. Object retuned will be instance of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Arel::Table&lt;/code&gt; as shown in the example below.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arel_table&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#&amp;lt;Arel::Table:0x00000101740160 @name=&quot;posts&quot;, @engine=Post(id: integer, title: string, body: text, publishing_date: date, published: boolean, created_at: datetime, updated_at: datetime), @columns=nil, @aliases=[], @table_alias=nil, @primary_key=nil&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;h4 id=&quot;matchlike-operator&quot;&gt;Match/Like operator&lt;/h4&gt;
&lt;p&gt;Use this when you want to match a part of the string, so instead of this:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;title like ?&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%welcome%&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# SELECT &quot;posts&quot;.* FROM &quot;posts&quot;  WHERE (title like &apos;%welcome%&apos;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;you can do this&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;matches&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;%welcome%&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#arel = Post.arel_table&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Will skip string examples for brevity’s sake&lt;/p&gt;
&lt;h4 id=&quot;less-than-operator---lt&quot;&gt;Less Than Operator - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lt&lt;/code&gt;&lt;/h4&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:created_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lt&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ago&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_sql&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;&quot;SELECT `posts`.* FROM `posts`  WHERE (`posts`.`created_at` &amp;lt; &apos;2015-09-26 16:19:31&apos;)&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;greater-than-operator---gt&quot;&gt;Greater Than Operator - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gt&lt;/code&gt;&lt;/h4&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:created_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gt&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ago&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_sql&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;&quot;SELECT `posts`.* FROM `posts`  WHERE (`posts`.`created_at` &amp;gt; &apos;2015-09-26 16:19:31&apos;)&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;less-than-or-equal-operator---lteq&quot;&gt;Less than or equal Operator - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lteq&lt;/code&gt;&lt;/h4&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:created_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lteq&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ago&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_sql&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;&quot;SELECT `posts`.* FROM `posts`  WHERE (`posts`.`created_at` &amp;lt;= &apos;2015-09-26 16:19:31&apos;)&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;greater-than-or-equal-operator---gteq&quot;&gt;Greater than or equal Operator - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gteq&lt;/code&gt;&lt;/h4&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:created_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gteq&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ago&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_sql&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;&quot;SELECT `posts`.* FROM `posts`  WHERE (`posts`.`created_at` &amp;gt;= &apos;2015-09-26 16:19:31&apos;)&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;real-world-use-case&quot;&gt;Real world Use-Case&lt;/h2&gt;
&lt;p&gt;Consider the following AR scope&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String version&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find_valid_phones_to_whom_we_can_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;duplicate: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;notification_type = &apos;mobile&apos; OR notification_type = &apos;phone&apos; OR notification_type = &apos;office_phone&apos;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# fetches only those records whose contact number is valid&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;whitelisted&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# contact number should not start from 800, (800)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# an array of numbers where we don&apos;t want to send sms&lt;/span&gt;
      &lt;span class=&quot;no&quot;&gt;BLACKLISTED_NUMBER_PREFIXES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;empty?&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;(contact NOT LIKE &apos;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;%&apos; AND contact NOT LIKE &apos;(&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;)%&apos;)&quot;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;(contact NOT LIKE &apos;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;%&apos; AND contact NOT LIKE &apos;(&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;)%&apos;)&quot;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# contact number should not be more than 10 characters&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;NOT length(contact) &amp;gt; 10&quot;&lt;/span&gt;

      &lt;span class=&quot;n&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot; AND &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Arel Version&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find_valid_phones_to_whom_we_can_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;duplicate: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;notification_type: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;mobile&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;phone&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;office_phone&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# fetches only those records whose contact number is valid&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;whitelisted&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;contact&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arel_table&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:contact&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# contact number should not be more than 10 characters&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;has_valid_length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Arel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Nodes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;NamedFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;length&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contact&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lteq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# contact number should not start from 800, 888 etc&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contact&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;does_not_match_any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;BLACKLISTED_NUMBER_PREFIXES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;has_valid_length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see above, Arel version reads better.&lt;/p&gt;

&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping Up&lt;/h2&gt;
&lt;p&gt;Arel full fledged query generator which generate any SQL query. So question is should you use it?&lt;/p&gt;

&lt;p&gt;Like all things in computer science. the answer is &lt;em&gt;it depends&lt;/em&gt; on the use-case. Here is how I like to think about it:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;SQL that ActiveRecord can generate: Use ActiveRecord.&lt;/li&gt;
  &lt;li&gt;SQL that ActiveRecord can’t generate but doesn’t have dynamic conditional logic. Use Strings.&lt;/li&gt;
  &lt;li&gt;SQL that ActiveRecord can’t generate &amp;amp; also have dynamic conditional logic based on paremeters: Use AREL as shown in the above real-world example&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To conclude, I would say Arel is tool that every rails developer should have in their toolbox.&lt;/p&gt;

&lt;p&gt;Lastly,
This is a blog post written after an year’s gap. so any feedback/comments/questions are welcome by tweeting to me at &lt;a href=&quot;https://twitter.com/gaurish&quot;&gt;@gaurish&lt;/a&gt;&lt;/p&gt;

</description>
      </item>
    
      <item>
        <title>Getting Rails Test Suite Running on JRuby</title>
        <link>http://www.gaurishsharma.com/2014/04/getting-rails-test-suite-running-on-jruby.html</link>
        <pubDate>Sun, 27 Apr 2014 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;This post is about Issue #11700 - Getting Rails Test Suite to run on Rails. Incase you don’t have time to read the full post, see the following presentation.&lt;/p&gt;

&lt;script async=&quot;&quot; class=&quot;speakerdeck-embed&quot; data-id=&quot;eebd7710970e013157f47aa36fe2d40f&quot; data-ratio=&quot;1.77777777777778&quot; src=&quot;//speakerdeck.com/assets/embed.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;prologue&quot;&gt;Prologue&lt;/h2&gt;
&lt;p&gt;You are a ruby developer &amp;amp; want to run rails on anything other than CRuby/MRI which is the de-facto ruby implementation written in C. Reasons could the that you are having problems with GC, need fully multi-threaded env(no GVL/GIL) or you just curious like me. so, you research a bit &amp;amp; find that there is this thing called JRuby which is implemntation of ruby programming language that runs of battle-tested &amp;amp; rock solid &lt;a href=&quot;http://en.wikipedia.org/wiki/Java_virtual_machine&quot;&gt;JVM&lt;/a&gt;. JVM is the same VM which is used by Java &amp;amp; all other JVM based languages like scala, closure, JPython etc.&lt;/p&gt;

&lt;h3 id=&quot;installing-jruby&quot;&gt;Installing JRuby&lt;/h3&gt;
&lt;p&gt;Installing JRuby seems seems quite simpler compared MRI/CRuby as its only dependancy of JRuby is the JVM. so, download &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html&quot;&gt;JDK 7 from oracle&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://jruby.org/download&quot;&gt;download/install JRuby from jruby.org&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;you-liked-jruby&quot;&gt;You liked JRuby&lt;/h3&gt;
&lt;p&gt;lets assume you tried JRuby on Devloplement machine &amp;amp; liked JRuby because:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;You need for specific Java libraries &amp;amp; JRuby Allows you to call any Java library from ruby.&lt;/li&gt;
  &lt;li&gt;want to real Concurrency, not GVL/GIL contrainted provided by CRuby/MRI.&lt;/li&gt;
  &lt;li&gt;Better GC which helps with long running processes&lt;/li&gt;
  &lt;li&gt;Better Performance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So next question you ask is:&lt;/p&gt;

&lt;h2 id=&quot;does-rails-support-jruby&quot;&gt;Does Rails support JRuby?&lt;/h2&gt;
&lt;p&gt;Yes. Rails runs on JRuby out of the box but its on different Level of support that rails test suite fails to run, it fails. Current status is &lt;em&gt;allowed failures&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;We consider any bugs on JRuby to be real bugs that need fixed, we just don’t actively run the test suite against JRuby&lt;/em&gt;
                        – &lt;strong&gt;Steve Kalbnik&lt;/strong&gt; (Rails Core Committor) on &lt;a href=&quot;https://github.com/rails/rails/issues/11700#issuecomment-21955029&quot;&gt;#11700&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But as rails is open-source, which means you can help to get test suite running. Pull Request are welcome.&lt;/p&gt;

&lt;h2 id=&quot;how-to-run-rails-test-suite-on-jruby&quot;&gt;How to Run Rails Test Suite on JRuby&lt;/h2&gt;
&lt;h3 id=&quot;grab-rails-code&quot;&gt;Grab Rails Code:&lt;/h3&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git clone http://github.com/rails/rails.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;switch-to-jruby&quot;&gt;Switch to JRuby&lt;/h3&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;rvm use jruby &lt;span class=&quot;c&quot;&gt;#if using rvm&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ruby &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt;
ruby 1.7.12 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;1.9.3p392&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 2014-04-15 643e292 on Java HotSpot&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;TM&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 64-Bit Server
 VM 1.7.0_51-b13 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;darwin-x86_64]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;bundle-dependencies&quot;&gt;Bundle Dependencies&lt;/h3&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /path/to/rails/checkout
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;bundle &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;run-tests-on-particular-component&quot;&gt;Run Tests on particular component.&lt;/h3&gt;
&lt;p&gt;To run tests only for particular component(ActionPack, ActiveRecord, etc.).  All you need to do is to cd into that component directory &amp;amp; run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rake test&lt;/code&gt;. For example, run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActiveSupport&lt;/code&gt; tests you can:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;activesupport
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;rake &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;run-a-particular-test&quot;&gt;Run a particular test&lt;/h3&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;activesupport
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ruby &lt;span class=&quot;nt&quot;&gt;-vIlib&lt;/span&gt;:test &lt;span class=&quot;nt&quot;&gt;--client&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;/multibyte_chars_test.rb
ruby 1.7.12 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;1.9.3p392&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 2014-04-15 643e292 on Java HotSpot&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;TM&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 64-Bit Server
 VM 1.7.0_51-b13 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;darwin-x86_64]
/Users/gaurish/.rvm/gems/jruby-1.7.12@rails-dev/gems/minitest-5.3.3/
lib/minitest.rb:46 warning: &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; interpreted as grouped expression
Run options: &lt;span class=&quot;nt&quot;&gt;--seed&lt;/span&gt; 21522

&lt;span class=&quot;c&quot;&gt;# Running:&lt;/span&gt;

lib/rational.rb is deprecated
.........................................................................
..............F....

Finished &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;1.735000s, 53.0259 runs/s, 195.3890 assertions/s.

  1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; Failure:
MultibyteCharsExtrasTest#test_tidy_bytes_should_tidy_bytes
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;/multibyte_chars_test.rb:657]:
&lt;span class=&quot;nt&quot;&gt;---&lt;/span&gt; expected
+++ actual
@@ &lt;span class=&quot;nt&quot;&gt;-1&lt;/span&gt; +1 @@
-&lt;span class=&quot;s2&quot;&gt;&quot;a€a&quot;&lt;/span&gt;
+#&amp;lt;ActiveSupport::Multibyte::Chars:0xXXXXXX @wrapped_string&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;€a&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;


92 runs, 339 assertions, 1 failures, 0 errors, 0 skips
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Okay, so now you have found a failing test. now, get this to &lt;span style=&quot;color:green&quot;&gt;green&lt;/span&gt; &amp;amp; submit a Pull Request. And please don’t forget to mention issue &lt;strong&gt;#11700&lt;/strong&gt; in your PR, so everyone can track it that you are working on the changes.&lt;/p&gt;

&lt;p&gt;For more info, please see:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html&quot;&gt;Contributing to Rails Guide&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/rails/rails/issues/11700&quot;&gt;Issue #11700 - Getting Test Suite to run JRuby&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://groups.google.com/forum/#!forum/rubyonrails-core&quot;&gt;Send any Questions to rails core&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/rails/rails/issues/new&quot;&gt;Report Rails Bugs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jruby/jruby/issues/new&quot;&gt;Report JRuby Bugs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
      </item>
    
      <item>
        <title>Installing Ruby from Source on Ubuntu 12.04 LTS</title>
        <link>http://www.gaurishsharma.com/2014/03/installing-ruby-from-source-on-ubuntu-12.04-lts.html</link>
        <pubDate>Tue, 11 Mar 2014 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;If you need to install ruby on server, I would suggest Compiling it from source because:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;When Source gets compilied on machine, you can apply compiler optimizations &amp;amp; get best possible performance&lt;/li&gt;
  &lt;li&gt;Its a global install &amp;amp; available system side&lt;/li&gt;
  &lt;li&gt;Its easiest way to install ruby.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;here-is-what-we-will-do&quot;&gt;Here is what We will do:&lt;/h2&gt;
&lt;p&gt;Compile &amp;amp; Install Ruby &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2.1.1&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;here-is-what-you-will-need&quot;&gt;Here is what you will need:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Server running Ubuntu 12.04 with root access to it.&lt;/li&gt;
  &lt;li&gt;basic command line know-how&lt;/li&gt;
  &lt;li&gt;15mins of your time&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;step-0-update-your-system&quot;&gt;Step 0: Update your System&lt;/h2&gt;
&lt;p&gt;It always a good idea to install all latest available patches for security &amp;amp; compatibility.&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get update
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get upgrade &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;step-1-install-required-dependancies&quot;&gt;Step 1: Install required Dependancies&lt;/h2&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;build-essential libssl-dev libffi-dev libyaml-dev &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
git libtool libxslt-dev libxml2-dev libpq-dev gawk curl pngcrush imagemagick &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
python-software-properties libreadline libreadline-dev

&lt;span class=&quot;c&quot;&gt;# If you&apos;re on Ubuntu &amp;gt;= 12.10, change:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# python-software-properties to software-properties-common&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;step-2-install-ruby-from-source&quot;&gt;Step 2: Install Ruby from Source&lt;/h2&gt;

&lt;p&gt;Download source tarball&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Extract &amp;amp; CD into it&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;xf ruby-2.1.1.tar.gz
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;ruby-2.1.1/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, last step do infamous configure, make &amp;amp; make install&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./configure &lt;span class=&quot;nt&quot;&gt;--disable-install-doc&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;make &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; make &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If everything went well, you should have latest ruby installed&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ruby &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt;
ruby 2.1.1p76 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;2014-02-24 revision 45161&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;x86_64-linux]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note: Incase of upgrade to newer version, just do the step 2 again. changing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.1.1&lt;/code&gt; with the latest version no.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>life is awesome</title>
        <link>http://www.gaurishsharma.com/2014/02/life-is-awesome.html</link>
        <pubDate>Sat, 01 Feb 2014 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;blockquote&gt;
  &lt;p&gt;When life gives you a lemon, you make a lemonande&lt;/p&gt;
&lt;/blockquote&gt;
</description>
      </item>
    
      <item>
        <title>Create WebServer in Ruby with just 1 line of code</title>
        <link>http://www.gaurishsharma.com/2014/01/create-webserver-in-ruby-with-just-1-line-of-code.html</link>
        <pubDate>Sat, 04 Jan 2014 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;If you ever need a WebServer for quickly sharing of files or hosting static content, here is a ruby one-liner:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ruby &lt;span class=&quot;nt&quot;&gt;-run&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; httpd &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; 3000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This would spinup a simple webserver good for development &amp;amp; quick file sharing on Port 3000. works on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ruby v2&lt;/code&gt; &amp;amp; above&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Tips on MultiThreading & Concurrency in Ruby</title>
        <link>http://www.gaurishsharma.com/2013/12/tips-on-multithreading-and-concurrency-in-ruby.html</link>
        <pubDate>Mon, 09 Dec 2013 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;If you are a rubyist, chances are that you might have faced some problem which was slower/not possible using traditional single thread approach. so here are are few tips what might help you when working with thread in Ruby.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Threading is hard. Don’t use thread, until you really need them. Threading opens can of worms.&lt;/li&gt;
  &lt;li&gt;If you do opt to use Threading, don’t share/change data between multiple threads. You will get crazy data which will be different on every run.&lt;/li&gt;
  &lt;li&gt;If you want to share/change data in critical section, use  semaphore/mutex, so you can lock parts of code should change as part of a “transaction”, so other threads waiting to change the data would be blocked.&lt;/li&gt;
  &lt;li&gt;set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Thread.abort_on_exception = true&lt;/code&gt;. By Default, ruby will continue even if there is a error in a child thread. Never giving you chance to view the exception raised. Setting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Thread.abort_on_exception = true&lt;/code&gt; will abort ALL threads if an exception is raised, giving you a chance to debug. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Thread.abort_on_exception&lt;/code&gt; is a global flag so set in your config or on top of the file BEFORE any threading code.&lt;/li&gt;
  &lt;li&gt;Never use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Thread#Join&lt;/code&gt; without a timeout. Join does not return untill ALL running threads exit. Which means if you have a thread which is waiting on something, join will also keep waiting endlessly. solution: Use a sensible timeout value. example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t.join(5)&lt;/code&gt; where 5 is seconds.&lt;/li&gt;
  &lt;li&gt;Ruby’s Core Data Structures are NOT tread-safe. It is another way of saying – data structures like Array, Hash are not fit to use when writing treaded code. fortunately, there are third-party libs which are atomic &amp;amp; work exactly like Hash, Array ruby. notable one is &lt;a href=&quot;https://github.com/headius/thread_safe&quot;&gt;thread_safe gem&lt;/a&gt; is also used by rails.&lt;/li&gt;
&lt;/ol&gt;
</description>
      </item>
    
      <item>
        <title>Find the greatest product of five consecutive digits in the 1000-digit number in Ruby</title>
        <link>http://www.gaurishsharma.com/2013/08/find-the-greatest-product-of-five-consecutive-digits-in-the-1000-digit-number-in-ruby.html</link>
        <pubDate>Thu, 15 Aug 2013 00:00:00 +0000</pubDate>
        <author>Gaurish Sharma</author>
        <description>&lt;p&gt;I recently started problems on &lt;a href=&quot;http://projecteuler.org&quot;&gt;Project Euler&lt;/a&gt; &amp;amp; came across problem #8:&lt;/p&gt;

&lt;p&gt;Q. Find the greatest product of five consecutive digits in the 1000-digit number.the number is&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Apart from the fact the number is akwardly large, solving this in ruby is easy&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/\d/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:to_i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each_cons&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n&lt;/code&gt; that huge number in string format.&lt;/p&gt;

&lt;p&gt;If you notice the above program gives the product of greatest five consecutive digits of a 1,000digit number on just one line. Amazing!&lt;/p&gt;
</description>
      </item>
    

  </channel>
</rss>
