JSONb with Ruby on Rails

I needed to get something from the database in my job. I tried the current query using PSequel and it gave an error. SELECT * FROM declarations WHERE data->>’some_data’ IS NOT NULL; The way I got the results was through the console with the following: bundle exec rails console declarations_ids = [] Declaration.find_each do |d| […]

Read More JSONb with Ruby on Rails

find in Ruby

So, I was working and found this nice idea on the code base about using the find for mail dunnings. This will be simplified to the max in order to keep the post short. In the Payments table we have the following columns: payment_reminder_sent_at first_dunning_sent_at last_dunning_sent_at What this code do is, find in the current […]

Read More find in Ruby

Format currency field with JavaScript

Last month I got a solution to format the currency fields from Wundertax’s declarations This is the function: var formatCurrency = function(element) { $this = $(element); var number = $this.val() number = number.replace(/[^0-9,.]/g, ”) if (number === ”) { number = ‘0,00’ } else { splitted_number = number.split(/[\,.]/g) if (splitted_number.length > 2) { decimal_numbers = […]

Read More Format currency field with JavaScript

HTTP with ruby

In my job we recently decided to use an email management tool called getResponse which I started to build the adapter to user with its API. One of the first things I did was to test the creation of an email with curl: curl -X POST https://api3.getresponse360.pl/v3/contacts -d ‘{“email”: “adnilson@frontline.cv”, “campaign”: { “campaignId”: “G” } […]

Read More HTTP with ruby

Holidays helper in Ruby on Rails

Today, while doing a calendar I found a module on Rails called Holidays. I will use the Rails console to demonstrate: bundle exec rails c Loading development environment (Rails 5.0.1) [1] pry(main)> Holidays.on(Date.tomorrow, :pt) => [{:date=>Wed, 01 Nov 2017, :name=>”Dia de Todos-os-Santos”, :regions=>[:pt]}] [2] pry(main)> Holidays.on(Date.today, :pt) => []

Read More Holidays helper in Ruby on Rails

Solving easy problems with Ruby

I got this problem from here Implement a group_by_owners function that: Accepts a hash containing the file owner name for each file name. Returns a hash containing an array of file names for each owner name, in any order. For example, for hash {‘Input.txt’ => ‘Randy’, ‘Code.py’ => ‘Stan’, ‘Output.txt’ => ‘Randy’} the group_by_owners function should return {‘Randy’ => [‘Input.txt’, ‘Output.txt’], ‘Stan’ […]

Read More Solving easy problems with Ruby

How to remove Docker files

I have been using docker for a while in a project and thank god it exists. There is no need in installing many project dependencies. In this case this is a Ruby on Rails 3 project, yes very old. Everything was fine until my root partition “/” was out of space! I thought to myself […]

Read More How to remove Docker files