Retry a command until it fails.
Debugging brittle specs is annoying and time consuming work. Let's automate finding those brittle specs by retrying them until they fail.
Accompanying blog post.
| -- Ansible testing using Assert | |
| When we run Ansible to manage server configurations, we assume (if there is no red errors) that it worked. But if you are developing ansible modules for your systems, and want to take the DevOps approach and work on CICD pipelines, you need to have some tests in there to prove that what you asked ansible to do has actually worked. | |
| One of the best ways to do this within ansible, is to use the Assert module. It asserts that a given expression is true. When you combine this with the output of a command that’s registered to a variable, there is almost no limit to what you can test. | |
| I’m going to use the TDD (Test driven development) method where we create the tests before we start writing any ansible code to manage our systems. I expect the tests to fail. Then we’ll write ansible to pass the tests. That’s it. | |
| This demo will cover the following: | |
| • Create some tests using the command and assert modules. |
| source 'https://rubygems.org' | |
| # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | |
| gem 'rails', '~> 6.0.0' | |
| # Shorten boot time | |
| gem 'bootsnap' | |
| # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder | |
| gem 'jbuilder', github: 'rails/jbuilder' |
| [ | |
| { | |
| "metadata": { | |
| "id": "b689fcc8-d494-4dbf-a228-2c694a578afc", | |
| "publisherId": "alefragnani.Bookmarks", | |
| "publisherDisplayName": "alefragnani" | |
| }, | |
| "name": "Bookmarks", | |
| "publisher": "alefragnani", |
| pragma solidity ^0.6.6; | |
| import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/FlashLoanReceiverBase.sol"; | |
| import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPoolAddressesProvider.sol"; | |
| import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPool.sol"; | |
| contract Flashloan is FlashLoanReceiverBase { | |
| constructor(address _addressProvider) FlashLoanReceiverBase(_addressProvider) public {} | |
| /** |
| #!/bin/bash | |
| # Uninstall all conflicting packages: | |
| for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg --purge -y; done | |
| # Add Docker's official GPG key: | |
| sudo apt-get update | |
| sudo apt-get install ca-certificates curl -y | |
| sudo install -m 0755 -d /etc/apt/keyrings | |
| sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc |
Retry a command until it fails.
Debugging brittle specs is annoying and time consuming work. Let's automate finding those brittle specs by retrying them until they fail.
Accompanying blog post.
Let suppose I have two github accounts, https://github.com/rahul-office and https://github.com/rahul-personal. Now i want to setup my mac to easily talk to both the github accounts.
NOTE: This logic can be extended to more than two accounts also. :)
The setup can be done in 5 easy steps:
| name: Security audit | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| push: | |
| paths: | |
| - '**/Cargo.toml' | |
| - '**/Cargo.lock' | |
| jobs: | |
| security_audit: |
This is another piece of code I've extrapolated from a Ruby on Rails project I'm currently working on. The code implmenets social login with a RoR API-based application, targeted at API clients.
The setup does not involve any browser-redirects or sessions as you would have to use working with Omniauth.
Instead, what it does is takes an access_token generated on client-side SDKs, retireves user info from the access token
and creates a new user and Identity in the database.
This setup works with native applications as described in the Google iOS Sign In Docs (see Authenticating with a backend server)
| # Run this file to auto generate a csv file based on the data passed in the products | |
| # variable. I created this based on an API call that I parsed in the format of an array | |
| # of hashes like the example in order to quickly generate a csv file for uploading. | |
| require "csv" | |
| products = [{"sku"=>"sku001", "name"=>"Item 1", "dimensions"=>"1 x 1 x 1"}, | |
| {"sku"=>"sku002", "name"=>"Item 2", "dimensions"=>"2 x 2 x 2"}, | |
| {"sku"=>"sku003", "name"=>"Item 3", "dimensions"=>"3 x 3 x 3"}, | |
| {"sku"=>"sku004", "name"=>"Item 4", "dimensions"=>"4 x 4 x 4"}] |