Vim Backup-Copy

While writing a custom version of the tail -f command in C, I stumbled upon an interesting behavior in the Vim/Neovim text editors. The purpose of the program is to continuously print any new data appended to the end of a file—just like tail -f, which is commonly used for watching log files. In my implementation, I have something like this: const char *filename = argv[1]; int fd = open(filename, O_RDONLY); if (fd == -1) { perror("open"); return 1; } The open() function, provided by #include <fcntl.h>, returns a file descriptor—a small, nonnegative integer that acts as an index into the process’s table of open file descriptors. ...

June 12, 2025 · 4 min · Deni Andrian Prayoga

Generate Ranged Random Integer in Javascript

Here I will show you a simple way to generate a ranged random integer number in javascript. Since javascript doesn’t have built in function to generate ranged integer number, we will create one. function randInt(left, right) { return Math.floor(Math.random() * (right - left + 1)) + left; } And that’s it, this is just me passing by and dropping some code snippets. See you later. Stay safe!

October 26, 2024 · 1 min · Deni Andrian Prayoga

Merge Pdf in Linux using pdfunite

Merging pdf files in Linux is really simple, you can use a command line called pdfunite. Open a terminal and type the following pdfunite --help in my system, it prints pdfunite version 24.06.0 Copyright 2005-2024 The Poppler Developers - http://poppler.freedesktop.org Copyright 1996-2011, 2022 Glyph & Cog, LLC Usage: pdfunite [options] <PDF-sourcefile-1>..<PDF-sourcefile-n> <PDF-destfile> -v : print copyright and version info -h : print usage information -help : print usage information --help : print usage information -? : print usage information Let’s say we want to merge three pdf files head.pdf, body.pdf, and foot.pdf into one file named all.pdf. Using pdfunite we can effortlessly merge all those pdf files like so ...

October 24, 2024 · 1 min · Deni Andrian Prayoga

Replicating Right Click Behavior using Vanilla Javascript

The idea is simple. First, disable the default event handler for right click in the browser. Second, create a custom event handler for right click event. Implementing the first idea, we can do something like the following. window.addEventListener("contextmenu", (event) => { event.preventDefault(); }); from here we can easily add any custom code for event handler to our liking, here I will just log “Right Click detected!” into the console. window.addEventListener("contextmenu", (event) => { event.preventDefault(); console.log("Right Click detected!"); }); You can create additional html elements and put it into the window to act as the replacement for the default context menu. ...

October 24, 2024 · 1 min · Deni Andrian Prayoga

Javascript Promise Simplified

Promise has three different states: pending, resolve, and reject. When you first create a promise, it will be in pending state. This promise can be either “fulfilled” thus it will be resolved or it can be “rejected” thus it will be rejected. In other word, if promise resulted in success it resolve, else it reject. To create a promise in javascript is really simple. const myPromise = new Promise(function (resolve, reject) { // do something }); What you do inside the promise will decide whether it will resolve or reject. ...

October 21, 2024 · 2 min · Deni Andrian Prayoga

Dummy File Watcher in C

In this article we will build a dummy file watcher using C programming language. We say dummy file watcher because to build a proper file watcher, we need to utilize os internal features which is a bit more complex. Instead, we will create an infinite loop that checks a given directory every 0.5 second and see if something has changed. First thing we need to do is to create a function that tells if something has changed in a given directory. ...

July 6, 2024 · 2 min · Deni Andrian Prayoga
Source: DALL-E

Review of Pointer in C

In this short article we will review pointers in C programming language, if you are new to this kind of topic please read the tutorial of pointers for beginners first, try this tutorial for example. Defining Pointer There are several ways to define a pointer in C. int* p; int x = 5; p = &x; // p pointer to address x we can assign the address right away like so int x = 5; int* p = &x; Dereferencing Pointer Use * to dereference a pointer, this will return the value that the address of pointer is pointing at holds. ...

July 3, 2024 · 2 min · Deni Andrian Prayoga
Source: [unsplash](https://unsplash.com/photos/a-building-with-a-clock-on-the-side-of-it-YWR9NKDHnls)

Dynamic Array in C Simplified

Array data structure is really useful, it can used to to store value with same data types, we can access it really easy, updating the value of array is also a trivial thing to do. One of the most important use of array is that is it used to implement other more complex data structures such as linked list, binary tree and hash tables. But what is greater than array? Yup, dynamic array. ...

July 2, 2024 · 4 min · Deni Andrian Prayoga
Source: [unsplash](https://unsplash.com/photos/black-computer-keyboard-DuHKoV44prg)

Linux Hard Link and Soft Link in a Nutshell

Definition Before we talk about hardlink and softlink in linux, we must first know what is inode and filename, and what’s the difference between the two. What is inode? Your computer needs a way to ’labelize’ files in its filesystem. Remember, everything is a file in linux. One way to do this is to put a unique integer value to the file. This unique integer value is what we called the inode number, which is a number that’s used to identify an inode. The inode is a data structure that describe a file-system object. ...

June 24, 2024 · 5 min · Deni Andrian Prayoga
Source: [unsplash](https://unsplash.com/photos/white-and-black-star-print-textile-4993XnXQKHY)

Pointer and Const in C++

The following paragraphs are the summary of pointer and const in C++, I always forget about this topic so I decided to create a post about it. Regular Pointers Regular pointers are pointers the we usually use when working with pointers in C++. int main() { int x = 5; int* ptr = &x; // regular pointer to x x = 6; // *ptr would be 6 // we can change the value at the address being held *ptr = 1; // x and *ptr would be 1 int y = 88; ptr = &y; // changing the address that ptr is pointing at return 0; } Pointer to a const value I won’t explain what is it and the rest of the it since it is easier to explain it using code rather than using words. (The definitions are still confusing to me💀) ...

June 15, 2024 · 2 min · Deni Andrian Prayoga