Skip to main content

Posts

Showing posts from 2020

Creating a prayer times action on Google Home

Saving a lot of time during the COVID-19 shutdown gave me the chance to do something I wanted to try for a while, getting my Google Home Mini to tell me the prayer time instead of looking at a screen. So this weekend I got to play with a dummy piece of code I made during the week and finalize my test version of my own prayer times assistant. So far, I can only ask about the next prayer or name a specific prayer to know its time. Important note: you cannot replicate the following project without a premium account on Firebase to enable calls to external APIs. Here is what I had to do in simple words: 1- Create a new Dialogflow agent Dialogflow is where I started my project with creating a blank agent with nothing but a Welcome intent. 2 - Modify the default welcome intent For the sake of having fun, I changed the way of addressing the user to say the magic word: "Salam! How can I help you?" plus accepting similar magic words like "Assalm Alaykom"....

Retry ruby code with exceptions multiple times

This problem I faced is pretty simple. A method calling an external API or resource which might throw a random error or fail intermittently. So I want to simple retry because this error is ignorable if it happens one or two times. Now the standard ruby's retry and redo keywords are not helping here. Because the retry will keep retrying endlessly and I want to raise the error after a few retries, and the redo requires a flag to make it stop. So my solution to retry my ruby code for a few times if a specific exception happens was as simple as a method with the retry logic and accepting a block to keep my code cleaner. And whenever I need to retry a not-so-reliable API, I wrap my code in this method as a block and choose the exception to retry when it happens and how many times to retry. # whatever method I am using def do_something_with_tolerance_to_errors response = with_error_retry(WhateverException, 2) do # my code goes here end end # my retry handler def with_...

How investigate a failed Docker build

While working on a recent task, I got stuck with a Dockerfile which was failing to build. The failing container was failing at one step of building with native extensions of some Ruby gems. I wanted get into the container to see what the logs were saying. This is the code snippet I used to do so: Step 1: Get the container ID by running $ docker ps -a I could look for the  CONTAINER ID  of the failing container. Step 2: Commit container to an image Using the container ID from the previous step, commit the container to create an image with its current state $ docker commit ca73ac766f36 sha256 5b4586632f690964d3a2e2b958cf6d211bc924e47e80a9bc4a84c53779f39f79 Step 3: Run the image Using the sha256 code from the previous step, run the image with bash and debug the image however you want. You don't have to use the full sha256 string $ docker run -it 5b4586632f [bash -il] And that's it!