Tim

Basic how to log to a file in Rust with log4rs

In this article, we will take look at how you can use and configure log4rs to log to a file in your Rust program. Specifically, we will look at some of the options using YAML to configure the logging. What is log4rs From the crate description: “log4rs is a highly configurable logging framework modeled after Java’s Logback and log4j libraries.” For the log4rs crate’s page click here. Why log4rs What is good about log4rs? It offers an easy way to log to a file and it is highly configurable using a YAML config file, as well as through code. However,…

Rust Web3 connect to Ethereum blockchain: how to

In this article for semi-beginners, we are going to learn how to connect to Ethereum with the web3 crate and Rust. We will connect using a WebSocket and then retrieve the balance of our account. Finally, we will use a token smart contract to retrieve information about the token. Please note that we will be using the Rinkeby test network for our interactions. So, if an address for a smart contract or token doesn’t seem to work, make sure that you are using the Rinkeby network. Please look at my GitHub for the full project: rust-web3-basics-tutorial. Please also see this…

Easy to set up Ethereum connection and wallet

In this short article, we look at an option for an easy way to set up an Ethereum node connection and a wallet. We will also look at how to get test Eth for testing purposes. These are the things we need to test and use the applications that interact with the Ethereum blockchain. Which we will develop in other articles. The easiest way is to use services and apps. In this article, we will look at infura.io for Ethereum node connections and metamask for wallets. The information in this post is a prerequisite to follow my article on Rust…

Crypto triangle arbitrage dashboard: how to, part 1

This article is part 1 of a series that will explain how to build a crypto triangle arbitrage dashboard using Rust and React. In this part 1, we will build the backend for the triangle arbitrage dashboard. The backend will gather data about trades for 3 coin pairs from the Binance WebSocket API. Then, it will calculate potential profits if we were to trade the pairs in sequence. Triangle arbitrage attempts to take advantage of price discrepancies between 3 assets that form a triangle on the same exchange. An example trade would be: BTC -> ETH -> BNB -> BTC.…

Warp data update loop: easy how to

What does “Rust Warp data update loop” mean? This article will describe how to create an infinite loop that sends data to clients connected to your WebSocket server in a thread separate from the main thread. This is useful when you want to build a system that periodically retrieves data from one or more sources and then needs to actively push that data to your client application. For example, a frontend dashboard that displays the data. The completed code project can be found on my GitHub, click here. This article will use the project from the following article: Rust Warp…

Rust Warp WebSocket server: learn how to now

In this article we will build a WebSocket server with Rust, using the warp framework. We will slowly go through the code building a simple version at first, and then add a bit more functionality to it. At the end of this article, we will be able to receive messages from the client and send something back in response. We will use this project as a base for future articles to build upon. We add a continuous data update loop to this project in the follow-up article Warp data update loop: easy how to. The repository with the complete Rust…

Easily connect to Binance WebSocket streams with Rust

In this article, we will look at how to connect to Binance WebSocket streams with Rust. We will be using the tungstenite library to make a WebSocket connection. For this tutorial, we will only use the public market data channels, so there is no need to register for an API key. Go to my Github to find the complete project here. This article is one of the first steps in a series of articles for building a triangle arbitrage dashboard using Binance cryptocurrency trading streams. Other articles in this series: The next step can be found at: Rust Warp WebSocket…

Vue.js and Tiptap Menu Bubble: how to build

In this tutorial we will learn how to set up a simple text editor using Vue.js and Tiptap, in particular we’ll be recreating the Menu Bubble example seen here https://tiptap.dev/menu-bubble. We will also add extra functionality to load and save a text file. There are no step by step instructions on how to set up that example in the documentation, so I wanted to write a quick tutorial about it. The example on the tiptap website uses custom svg files for the icons, but fontawesome has some nice icons so let us use those instead. Fontawesome is a very nice…

Text highlighting for a Vue.js text editor: how to

In this article we will look at a way to implement a Vue.js text editor that will allow highlighting selected text. For this we will be using Vue.js and the tiptap library. We will be building on a project from a previous article about the tiptap library: Vue.js and tiptap menu bubble: how to build. The completed project can be found in my github repository here. Prerequisites We will be using a previous project as a base. So, please download that and install the dependencies if you want to follow along: Highlighting extension To implement a Vue.JS text editor with…

Mocking in python tests: practical examples

What is mocking when it comes to python tests? Mocking is a way to simulate and control the behavior of functions or objects. Typically this type of control is necessary when unit testing code that deals with systems external to our own code. Why mock external systems? The main issue is with external systems unpredictability, we have limited control over the state of these external systems, making tests potentially very brittle. For example when code reads data from disk or a database. If there is a piece of functionality that reads and modifies files on disk we would have to…