Skip to main content

Posts

Showing posts from July, 2021

Several Useful Linux Tools

The following tools may have been installed in your Linux because some are basic tools. But, if we installed any Linux distribution from the Docker registry which is shipped with only minimal programs, these following tools may be not available by default. net-tools This tool provides tools for network-related tasks such as ifconfig . software-properties-common If you want to enable add-apt-repository command, this tool is required. nano This text editor is usually already available. ca-certificates A deb package that contains certificates provided by the Certificate Authorities. It also contains an updater tool that can be used as a cronjob if needed. gnupg2 GNU Privacy Guard is GNU's tool that can be used to encrypt data and to create digital signatures. GnuPG is a complete replacement for PGP. It includes an advanced key management facility and is compliant with the proposed OpenPGP Internet standard. openssh-client Tools for generating authentication keys and

Persisting Data and Replication in Redis

As we know, Redis is an in-memory key-value store database. If our data is stored in our host memory (RAM), how can we restore all values from the last state of our system in case of system reboot or power outages? Redis provides two options for persisting our data. The first is by creating a snapshot and the second is by appending each write action into a file. The second is also called the append-only-file (AOF) method. Applying those options is as trivial as updating several lines of the Redis configuration file. Redis performs snapshotting with certain rules by default. Enabling the auto-snapshot method with different rules is done by configuring the following lines in the /etc/redis/redis.conf file. save 300 10 save 30 1000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir /var/lib/redis The line save 300 10 means snapshot will be automatically updated in the background if at least 10 writes have occurred within 300 seconds. The li

Utilizing HTTP/2 Push for Faster Page Load in Node.js

HTTP/2 has several advantages over HTTP/1 that I've mention in my earlier post . In this post, I want to show how push-request can be performed using Node.js to create an HTTP/2 server. Push request is used to push static files such as scripts and styles so that the client can consume those static files as soon as possible without the need to request them first. In this example, several built-in Node modules are required and an external module for ease of content-type setting named mime . Let's install it first. npm init npm i --save mime HTTP/2 encodes all headers of a request and it presents several new headers for identifying a request such as :method and :path . For more clarity, I call some constants related to the HTTP/2 header from the http2.constants property. Let's create the server.js file. const http2 = require('http2'); const { HTTP2_HEADER_PATH, HTTP2_HEADER_METHOD, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_CONTENT_LENGTH, HTTP2_

Utilizing Ref Attribute for Referring HTML or React Elements

For accessing the DOM node of an HTML element or referring a React element, we can utilize the ref attribute. In React, we can utilize React.crateRef() function or React.useRef() hook for generating an object that has access to the referred DOM node. Several cases may be faced while we are developing React application. 1) Referring HTML Element . class RefHtml extends React.Component { constructor(props){ super(props); this.textInput = React.createRef(); } render() { return ( <div> <input type="text" ref={this.textInput} /> <button onClick={()=>{this.textInput.current.focus();}}>Focus</button> </div> ); } } 2) Referring React Element (Class Component) . class ReferredElement extends React.Component { constructor(props){ super(props); this.state = {status: "inactive"}; } setActiveState() { this.setState({status: "active"}); } render() {

Serving Single-Page React App with Docker

If you build a single-page application using React while your app only gets backend data through API access, it will be convenient to utilize the Create-React-App toolchain. For serving your app to the public, you actually just need to serve the generated static files. Serving static files can be easier when you utilize a container for shipping a web server. Initiate react project then build the app. npx create-react-app my-app cd my-app npm run build Create Nginx server configuration for your app site.conf . server { listen 80; server_name my-app.localhost; index index.html; root /app; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; try_files $uri $uri/ index.html =404; } Create a Dockerfile for building containerized web server. # syntax=docker/dockerfile:1 FROM nginx:latest WORKDIR /app COPY ./build . COPY ["./site.conf", "/etc/nginx/conf.d/"] Build the image and run the container. docker build -t my-servic

Create HTTP/2 Client-Server on Node.js

Node.js has support for building HTTP2 communication. HTTP2 has better efficiency compared to HTTP1.1 as described in my earlier post . In this example, we will build a client-server program that utilizes the HTTP2 module. Create server application server.js . const http2 = require('http2'); const server = http2.createServer(); server.on('stream', (stream, headers) => { stream.respond({ status: 200, 'content-type': 'text/html' }); stream.end('<html><head><title>Hello</title></head><body><p>Hello World</p></body></html>') }); server.listen(6000); Create client application client.js . const http2 = require('http2'); const client = http2.connect('http://localhost:6000'); const request = client.request({ ':path': '/' }); let str = ''; request.on('data', (chunk)=>{ str+=chunk; }); request.on('end',

Film Thriller, Horror, dan Misteri Asia Terbaik

Dulu saya sudah pernah menulis beberapa film misteri yang menurut saya bagus di " Film Misteri Asia Terbaik ". Ini adalah beberapa film lainnya yang sangat cocok ditambahkan ke dalam daftar. 1. The Wailing (2016) Beberapa peristiwa kematian dan pembunuhan terjadi di sebuah desa. Seorang polisi setempat mulai menyelidiki kasus-kasus tersebut. Seorang kakek yang tinggal sendiri di gunung dicurigai sebagai penyebabnya. Namun, dugaan baru muncul bahwa ada makhluk lain yang menghantui yang mampu mencelakai dukun yang sedang dimintai bantuan untuk menyelesaikan masalah. Siapa yang benar dan siapa penyebab kasus-kasus di desa itu terjawab di akhir film. 2. Bedevilled (2010) Seorang perempuan berlibur ke tempat tinggal masa kecilnya di desa di sebuah pulau. Dia bertemu dengan teman perempuannya di masa kecil yang masih menetap di desa itu yang telah mengalami banyak diskriminasi oleh warga desa itu. Akibat berbagai kejadian dan besarnya rasa kecewa, sang teman berubah menjadi seorang