/blog/index.xml

From Ruby to Python - Bundler and Poetry

From Ruby to Python - Bundler and Poetry

Ruby and Python are two popular programming languages known for their simplicity, readability, and extensive libraries. Both languages offer package managers to handle dependencies and streamline project development. In the Ruby ecosystem, we have Bundler, while in Python, I have come to rely on Poetry. Let’s look at these two tools, exploring their features, usage, and benefits.

Dependency Management

Bundler

Bundler, the Ruby dependency manager, uses a Gemfile to define project dependencies and their versions. Bundler resolves the dependencies and installs the required gems (libraries) into the project.

Poetry

Poetry, the Python dependency manager, employs a pyproject.toml file to define dependencies, versions, and other project metadata. Poetry resolves the dependencies and installs them into the virtual environment, which isolates the project from the system Python installation.

Read More

Postgres - Use temporary table to query from CSV

Postgres - Use temporary table to query from CSV

If you need to compare the contents of a large CSV file the to data in your existing database, you might want to take advantage of temporary tables. A temporary table exists only for the duration of the database session or transaction in which it is created. These tables can be useful for storing intermediate or temporary data that you need to compare to your live data but don’t want to persist in the database permanently.

Let’s look at an example:

CREATE TEMPORARY TABLE temp_uploaded_orders (
  order_id INT,
  store_id TEXT,
  settled BOOLEAN
);

Read More

Postgres Tricks - Convert jsonb string to hhmmss from seconds

Postgres Tricks - Convert jsonb string to hhmmss from seconds

We sometimes need to convert strings to dates to intervals and back to string in Postgres. One common set of queries I reach for is to convert “seconds” field into something that is readable by human. Most of us read times in the “hh::mm::ss” format and don’t like to do math in our head.

Here’s a simple query with to_char to convert seconds into this format:

 SELECT TO_CHAR('95 second'::interval, 'HH24:MI:SS')
 -- "00:01:35"

Read More

tobr - Generate a branch name form story title

If you are lazy like me and thinking of branch names is mentally taxing, it is time for a tool. I’ve been using this small ruby script for over 3 years to generate branch names. The script looks like this:

#!/usr/bin/env ruby
# Usage: tobr "Add customer phone Number"

text = ARGV.first || ""
puts text.gsub(" ","_").downcase

Read More

Enum Methods comparison in Ruby/ Javascript and Elixir

Enum Methods comparison in Ruby/ Javascript and Elixir

all?

The all? method in Ruby returns a boolean value (true/false) if all the objects in the list either return true or satisfies the block condition.

Ruby

Enumerable#all?

No block:

>> [ true, "dog", "bear", 19 ].all?
=> true
>> [ nil, true, "hello" ].all?
=> false

With a block:

>> %w(cat dog squirrel bear).all? { |word| word.length >= 3 }
=> true
>> %w(cat dog squirrel bear).all? { |word| word.length <= 3 }
=> false

Elixir

Enum.all? No block:

>> Enum.all?([ true, "dog", "bear", 19 ])
true
>> Enum.all?([ nil, true, "hello" ])
false

With a block/fn:

>> Enum.all?(["cat", "dog", "squirrel", "bear"], fn word -> String.length(word) >= 3 end)
=> true
>> Enum.all?(["cat", "dog", "squirrel", "bear"], fn word -> String.length(word) <= 3 end)
=> false

Javascript

Array.prototype.every()

Only with callback support:

> [ true, "dog", "bear", 19 ].every(x => x)
true
> [null, true, "hello" ].every(x => x)
false

> ["cat", "dog", "squirrel", "bear"].every(word => word.length >= 3)
true
> ["cat", "dog", "squirrel", "bear"].every(word => word.length <= 3)
false

Read More