06 May 2018
In this article, let’s explore on how to use GraphQL implementation with Rails and ReactJS to build a simple app which would do the followings:
- Login with an email & password using graphql
- List all books with title, author name & number of comments
We would also explore how to deal with N+1 query problem with GraphQL
27 Oct 2017
I set a rule in our company that we cannot have a long running process running in Rails controller as it will easily prolong the occupation of one of the puma/unicorn server instances. We usually have a limited number of puma/unicorn server instances and it is a bad idea of having one of them occupied for more than 1 second, as the more and the long time the puma/unicorn server instance is occupied, the less throughput we would have. This could result in slow site and bad user’s experience.
One of the common tasks that can occupy the puma/unicorn server instance for a very long time is generating a CSV report task. The usual process is that a user would click on a generate CSV file button and wait there until the file is fully generated on the server and then trigger a download through Rails
send_data command in a controller. In this article, I am going through on how we can solve this problem by making the report generation happen in the background and only trigger the download once it is finished generating on the server.
07 Oct 2017
I was recently tasked to deploy a NextJS app into a ubuntu server. The requirement was that the deployment needs to be fast and as reliable as possible. Although I have been using mina for some of the apps, mina still does not really support multiple server instances deployment, which is quite a disappointment. Luckily, capistrano 3 supports multiple server deployment out of the box and pretty fast, reliable to be chosen as a deployment tool for all our projects. In this article, I am going to go through how I use Capistrano 3, Node Version Manager (NVM) and PM2 (a Node JS process manager) to deploy reliably a NextJS project.
30 Sep 2017
For Rails developers, we are all familiar with pagination. I am using and happy with Kaminari to do pagination. However, there is a problem, quite a serious problem with Kaminari is that I could not use Kaminari to perform pagination on the famous
find_by_sql function as
find_by_sql simply returns a Ruby array while Kaminari requires an ActiveRecord::Relation in order to append the pagination query portion. In this article, let’s go through how I still can do pagination on
find_by_sql without using Kaminari.
17 Sep 2017
Handle file upload in React is not a trivial topic, especially with multiple files upload. In this article, I would like to go in depth how we can make use of React, FormData to upload to Rails smoothly. The features that we are going to build in this article will include
- Single/Multiple File Upload.
- Accept certain file types.
- Show progress bar when files are being uploaded
- Preview the files before they are uploaded
- How Rails can handle to multiple file uploads
03 Sep 2017
I have been purchasing SSL for my client applications using various service provider like Trustico, RapidSSL. However, the process of generating the SSL is quite a lengthy, time consuming and troublesome process. Recently, I found out that, we can actually generate SSL from a service provider - Let’s Encrypt, a service that lets you generate free SSL certificate for free without a lot of hassle like a common SSL service provider. In this article, I am going to go through how to use this to generate an SSL certificate for one of my domain name.
19 Aug 2017
13 Aug 2017
It is quite a trend now that we use Rails API combining with a front end framework like ReactJS, AngularJS or VueJS. This is also a good way for us to streamline the data serving. All data flowing out from Rails app will just be JSON. This sparks my huge interest of finding a way to cache the returned json so that it can return faster without hitting the database. In this article, I would like to share a way on how to do effective cache json.
08 Aug 2017
Since the day I started deploying to a remote server until recently, I have always had to load database from staging server or production server into my local Rails development environment for some debugging purposes. However, it is not a simple process and usually occupy some of my times with quite a bit of manual commands.
Recently, I have decided this have to be changed and that moment I have started writing a Ruby gem just to do this mundate task.
07 Aug 2017
Regular Expression can be overlooked by Ruby developer sometimes. However, if we know how to make use Regular Expression, it could be extremely useful and save a lot of our time dealing with ruby strings problem. In this article, I am going through some basic knowledge of Regular Expression in Ruby and how we can fully utilise it for our benefit.