Kubernetes Rails Sidekiq Liveness Probe

Before we dive into the details, I'd like to say that you may don't need a Sidekiq liveness probe if you only get a few Sidekiq instances on production and it's integrated with an error tracking system. Better to keep things simple. The Issue The only issue I've encountered on Production about Si

Days Off-set at Chengdu WeWork

Days before the Chinese Spring Festival of 2020, I traveled to Chengdu city to avoid the annual travel peak. I'd like to thanks WeWork's policy to allow me to work remotely. Daily syncing goes really well on Slack and Wechat as what we always did in HQ. While keeping work on the track, it's also a g

RabbittMQ Dealing with Failure

Goal To figure out a sample, but an implementable way of handling RabbitMQ failure. We are going to set up a RabbitMQ cluster on your local device with HAProxy as a load balancer, and synchronizing queues between different RabbitMQ nodes will also be included. Setup Environment In this post, I'm go

Java RGB to CMYK Converter

As we already talked about the implementation of how to convert a color pixel value from RGB to CMYK, now I'd like to show you how to convert it from CMYK to RGB. Question RGB to CMYK color matching. Write a java program RGBtoCMYK that reads in four command line inputs R, G, B between 0 and 255,

Java CMYK to RGB Converter

Almost everyone knows the RGB color model, red, green and blue, especially as a software engineer. It's widely applied in many industries. The CMYK, stands for "Cyan Magenta Yellow Black", is mostly used in paper print. Today we are going to create a java program to convert a color from C

Java Fibonacci Word

Fibonacci Word means the next word is concatenated up by the two words before it. Sn = S(n-1) · S(n-2) 0 01 010 01001 Question Write a program FibonacciWord.java that prints the Fibonacci word of order 0 through 10. f(0) = "a", f(1) = "b", f(2) = "ba", f(3) = "b

Rails on Kubernetes Deployment Tutorial

Kubernetes is different from Docker Swarm, it has Pods and running Containers inside Pods. Here is a simplified Kubernetes architecture diagram. In this tutorial, we are going to go through all the steps from setup Kubernetes on your local device to run Rails on a local Kubernetes cluster. Activat

Using N2N VPN to Enable NAS Remote Accessing

Background I have multiple devices including a NAS, a Raspberry Pi, and two MacBooks in different networks, my home and office. All I need is that I want to let all these devices can be accessed in any of those networks. After searching on the internet, I found out n2n should be the one I looked fo

Error: Docker Error response from daemon: Container id is not running

Issue The following lines is an example of how to reproduce this error. # Pull the latest version of alpine image from docker hub ➜ docker pull alpine # Create a container from the alpine image and get on to the terminal of that container ➜ docker run -it --name alpine_bash alpine ash ➜ exit # in

Error: An error occurred while installing nokogiri, and Bundler cannot continue on Ubuntu

Issue I got this error on when try to install nokogiri on a Ubuntu 18.10 server. It seems like I've not install the required packages correct on the system. Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /root/alert/vendor/bundle/ruby/2.5.0/gems/nokogir

ERROR: Error Installing Nokogiri: Invalid Gem: Package is Corrupt on Mac

Issue This error came out when I'm trying to bundle install Rails with rbenv on my MacBook, after retry several times, finally got this solution to install Nokogiri successfully. -> bundle Bundler::GemspecError: Could not read gem at /Users/username/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/cach

The Behaviors of Dependent Destroy on Rails ActiveModel

what is dependent :destroy Dependent is an option of Rails collection association declaration to cascade the delete action. The :destroy is to cause the associated object to also be destroyed when its owner is destroyed. Code Preparation First, the DB shemas and Rails Model should be ready for the

Rails GraphQL Beginner Tutorial - Part 1

Goal This article is the first post of rails GraphQL beginner serial, I'm going to create a demo to show how to use GraphQL in Rails by querying book records in DB. First of all, let's list all the thing we need to know about the following steps. The graphql gem. A table named books. ID NAME

My Mid-Year Coding Review 2019: Magic Tips for Coding

This article is a brief review of the last half year in my professional life, and all these topics are flowing in my mind for months. It's better to release the reins, let the paw-prints appear on the paper. I took a long work gap, which went through the whole hot summer last year, to have a vacati

Java Load Balancer Simulator Based on Random Array Queue

Thinking of there are hundreds of thousands of users request a website at the same time, we must have multiple servers to make sure our service is stable and won't out of usage. You may ask how could we distribute requests to these different servers, the answer is Load Balancer. Load Balancer is a

Java Merging Two Sorted Queues in Ascending Order

A sorted queue means the items in this queue are in descending order or ascending order. If we insert the items into a new queue one by one and keep the previous order, the new queue should also be sorted. Question 4.3.42 Merging two sorted queues. Given two queues with strings in ascending order,

Ring Buffer - Java Implementation of Circular Queue Using Fixed-length Array

Ring Buffer also is known as Circular Queue is a type of linear data structure. It following the FIFO rule of Queue, but it doesn't have an ending position. The last inserted item can overwrite the existing items, the front and rear are connected together like a ring and often used as Buffer in the

Using Java Queue to Solve the Josephus Problem

Question 4.3.39 Josephus problem. In the Josephus problem from antiquity, n people are in dire straits and agree to the following strategy to reduce the population. They arrange themselves in a circle (at positions numbered from 0 to n 1) and proceed around the circle, eliminating every mth person

Java Implementation of Random Array Queue

Question 4.3.37 Random queue. A random array queue is a collection that supports the following API: Write a class RandomQueue that implements this API. Hint : Use a resizing array. To remove an item, swap one at a random position (indexed 0 through n-1) with the one at the last position (index n-1)

Evaluating Arithmetic Expressions

What is Infix, Postfix and prefix expression Infix express means that the operator is in between the two operands of what it is working on. Prefix expression notation requires that all operators precede the two operands that they work on. Postfix, on the other hand, requires that its operators come

Java Stack Implementation

What is Stack Code Example of Stack import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Scanner; class Stack<Item> implements Iterable<Item> { private int n; private Node first; private class Node { private Item item; private

Java Postfix Calculator

What is Postfix expression Postfix is a expression of Arithmetic Expressions in which the operands are placed before their operators. There are no precedence rules, no parentheses needed. It's much easier for us to calculate Postfix Expression by using stack. Steps of Evaluating Postfix [^1] Push

Java Infix Calculator

What is Infix expression Infix notation is the common arithmetic and logical formula notation, in which operators are written infix-style between the operands they act on, as the examples below: 1+2 3+4 A fully parenthesized infix arithmetic expression is an infix arithmetic expression where every

Java Queue Implementation

What is Queue Code Example of Java Queue class Queue<Item> { private int size; private Node first; private Node last; private class Node { Item item; Node next; } public Queue() { size = 0; first = null; last = null; }

Give Your Laravel Application a Better Performance

In this benchmark, I did nothing with Laravel itself, I'm just want to see the different behaviors of the different optimization ways. First of all, I'd like to put the conclusion here. The OPcache is a good choice to speed up your PHP project. From the two pics below, it seems like I didn't get the

The Right Way to Upgrade PHP to 7.1+

Laravel Framework has been upgraded to Laravel 5.6. It's quite important to follow the steps of official releases for the framework you are working on. I have seen several projects stuck on some old versions of  PHP and never can upgrade to the latest version again. Upgrading PHP version for your pr

A Simple Docker Tutorial for PHP Developers

Why you should choose docker You may not care about the continuous deployment or environment isolation, but you do really care about the simplicity and the convenience of development as a developer. You may also hear about the performance issue of Docker from some review articles. If you are not goi

The Import Things You Should Know about Laravel Cache

Caching is a strategy that aims to get a higher performance of an application. Here are some experiences that I have learned during working on Laravel. Different storage drives must be used in particular situations Laravel provides file storage as default and it has a convenient way to implement oth

A Brief History of PHP Autoloading

What is autoloading in PHP? Autoloading is a functionality to help developers including PHP classes automatically. In the ancient times, we need to include all the files one by one in the bootstrap file. This olden style may also slow down the initialization of an application. Olden style <?php

Speeding up Unit Tests with Laravel

We suffered the slowness of the unit testing that was integrated with Laravel migration until last week. The tests execution time on my Mac is 21 minutes in average and more than one hour on our DEV server. we are annoyed with the huge time occupation in each release. Because we may deploy serval ti

Unit Testing API with Guzzle

At the beginning of this post, I’d like to show you how to test APIs by using Laravel or Guzzle. The different is functions provided by Laravel can only be used to test the features built on Laravel. For example, if you have a page for file uploading and you want to test it, it’s very simple by usin

Things I've Learnt from Refactoring

Currently, there are lots of sites based on WordPress running steadily in our company, except the project which I'm working on threw out so many issues. since all of us were tired and bored with endless hotfixes, it's time for us to refactor this project, or there would be more and more features imm