RSSAmplifier

Blog

John Pili - Software Developer, Blogger and an aspiring Entrepreneur.

Recent content on John Pili - Software Developer, Blogger and an aspiring Entrepreneur.

johnpili.comRSS feed ↗59 posts

Latest posts

Mount and unmount a LUKS volume using Bash functions

I have a LUKS encrypted volume that I only need from time to time. Opening it manually means typing the cryptsetup command, then the mount command, and remembering the correct device and mapper names every single time. Closing it is worse because a leftover shell sitting inside the mount point will keep the volume busy and the unmount will fail. The usual advice here is to add an /etc/crypttab and…

Postgres Initial Linux Configuration Guide

Accessing psql sudo -i -u postgres psql Create a new database and user Create a new user: CREATE USER theusername WITH PASSWORD 'thepassword' ; Create a new database: CREATE DATABASE thedatabase; Grant privileges: GRANT ALL PRIVILEGES ON DATABASE thedatabase TO theusername; Allow Remote Access Edit postgresql.conf , usually located in /etc/postgresql/<version>/main/ , and set listen_addresses =…

Bash string manipulation in program arguments

In this code snippet, I would like to run an application with a URL payload based on date and time. This code will be executed in a specific schedule everyday and I would like to dynamically inject the date and time in the program argument when the program executes. ./json2csv rules.json 'ncp' 'http://localhost:8080/api/zget?eid=get-ncp-mv-by-starttime-endtime&starttime;= $( date --date =…

Generate a self-signed certificate for Go

Use OpenSSL generate a self-signed certificate for Golang. In this code snippet I created a certificate with validity of 15 years. openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 5475 Once you create the certificate and key you can use it in your Golang HTTP like this 1 package main 2 3 import ( 4 'log' 5 'net/http' 6 'time' 7 8…

Use Linux diff command for line by line comparison

Use Linux diff command to compare files line by line. This handy tool helps you identify line differences between files and console output. Command diff -y file1 file1 Marker Meaning | = line present in both files but the text differs. < = line present only in the left file. > = line present only in the right file. Examples Comparing two package.json files johnpili@com ~ % diff -y package1.json…

Git Cheat Sheet

Creating or cloning a Repository git init Initializes a new Git repository in the current directory git clone https://git[.]johnpili[.]com/path/to/repo.git Clones a repository using HTTPS protocol from a remote location git clone ssh://git[.]johnpili[.]com/path/to/repo.git Clones a repository using SSH protocol from a remote location git clone git://git[.]johnpili[.]com/path/to/repo.git Clones a…

Change Microsoft SQL Server Data Location

Let&rsquo;s say you have an existing Microsoft SQL data and want to move it to a different disk or directory. Running the query below shows the logical name and the file location of your schema. SELECT name AS FileLogicalName, physical_name AS FileLocation FROM sys.master_files WHERE database_id = DB_ID( 'HR' ); Existing Location FileLogicalName FileLocation HR C:\MSSQL_DATA\OldPath\HR.mdf HR_log…

Recursively delete files with a specific file extension

Delete files with specified file extension recursively. This is useful when you want to remove those temporary files or those unwanted auto-generated artifacts inside nested folders. Be careful when using these commands because it will delete files permanently Linux Bash find . -type f -name '*.tmp' -delete find . -type f -name '*.tmp' -exec rm -v '{}' + Windows Powershell Get-ChildItem * -Include…

Using Unix Domain Socket in Go

You can use Unix Domain Socket aka AF_UNIX for your interprocess communication. Previously, It was only available in a Linux/Unix operating system until Microsoft added it in Microsoft Windows in the beginning of Insider build 17063 . It offers better throughput and improved security package main import ( 'log' 'net' 'net/http' 'os' 'os/signal' 'syscall' ) func main () { socketPath := 'uds.sock'…

Check JPA Query Type

I am developing a repository as a service application . An application that let users create their endpoints with queries via a web interface. This application uses either Hibernate or Eclipselink as a JPA provider. The challenge is to check if the supplied user string (query) is a native SQL or a JPQL and that Eclipselink and Hibernate handles this differently, so I decided to wrap it behind this…

Using Vue without a build step

Background I would like to share my experience using Vue 2 without a build step in my project and the key factors behind this approach. I started experimenting with Vue.js ( Vue 2 ) back in 2020. One of the nice features of Vue is the ability to use the framework directly into HTML page without a build tool (compilation). This particular feature was the deciding factor in selecting this framework…

Set HTTP Request Body Size in Go

Use http.MaxBytesReader to limit and control the size of the HTTP request body. This is a good practice to prevent abuse and save bandwidth. In the example below, I set a 20 bytes HTTP request body size limit. package main import ( 'github.com/julienschmidt/httprouter' 'io' 'log' 'net/http' 'time' ) func main () { router := httprouter . New () router . HandlerFunc ( http . MethodPost , '/' , func…

Boot Linux without a splash screen

If you prefer to boot up your Linux machine with the boot messages rather than the distro splash screen. You can enable that by editing the file /etc/default/grub and set the value of GRUB_CMDLINE_LINUX_DEFAULT to an empty string. Example: GRUB_DEFAULT = 0 GRUB_TIMEOUT = 5 GRUB_DISTRIBUTOR = ` lsb_release -i -s 2> /dev/null || echo Debian ` GRUB_CMDLINE_LINUX_DEFAULT = '' GRUB_CMDLINE_LINUX = ''…

Start a React project without using CRA

Let&rsquo;s start a React project without using create-react-app (CRA) . CRA is a good project starter but for those who wants a complete control over the building process, we will have to use bundler tools like webpack or yarn . Prerequisites React.js knowledge Installed and configures NodeJS Installed node package manager (npm) Steps Using the command-line, let us follow the following steps:…

The Pragmatic Programmer - It&#39;s your life

A sound bite from The Pragmatic Programmer: Your Journey To Mastery, 20th Anniversary Edition (2nd Edition) Interested? You can grab a copy of this book from Amazon. https://www.amazon.com/Pragmatic-Programmer-journey-mastery-Anniversary/dp/0135957052

Change your SSH server port to reduce brute force attacks

Reduce SSH brute force attacks by changing your default SSH server (sshd) port from port 22 to a different one. Below is a sshd log example of a brute force attacks. Changing the port You can change the default port by editing the sshd configuration file. sudo nano /etc/ssh/sshd_config Find the line that say #Port. Remove the # symbol and set the port number you prefer. Refer to the image below as…

Rsync with different SSH port

Some Linux servers were security hardened by changing the default SSH port from port 22 to a different port number. To use rsync with a different SSH port, add &lsquo;ssh -p 12345&rsquo; in the rsync parameters. Push rsync -azvP -e 'ssh -p 12345' SOURCE USER@HOST:DEST Pull rsync -azvP -e 'ssh -p 12345' USER@HOST:SOURCE DEST

Golang with reCAPTCHA

Google’s reCAPTCHA is one of the tool we can use to stop malicious internet bots from abusing our web applications. It comes in two versions, reCAPTCHA v2 and v3. Version 3 uses a score-based method with no user interaction. Version 2 uses a checkbox that will require users to answer a question. In this tutorial we will focus on reCAPTCHA v2. Prerequisite This tutorial requires the following:…

Embed Resources in Go

The go:embed feature was introduce in Go 1.16. It lets you embed resources into the compiled application. Prior to version 1.16, developers uses external tooling to do this. With go:embed you can embed images, webpages, email templates, predefined SQL statements or an entire directory. That&rsquo;s neat! Usage Examples Embedding a text file in a string //go:embed version.txt var version string…

Python batch file MD5 checksum generator and checker

I am backing-up a large number of files to another computer when this idea came to me to write a Python script that generate and validate batch MD5 checksum. Feel free to customize the script according to your needs.

Python rename files that begins with matching string

Do you want to rename a number of files that begins with a specific name or string? I wrote this small Python script that does that. Of course, you can also do this with Bash or Powershell. I hope somebody might find it useful. import os import sys from os import path parameters = sys . argv[ 1 :] if len(parameters) == 0 : print( f 'usage: { sys . argv[ 0 ] } <startswith-string>' ) sys . exit( 0 )…

Active Directory userAccountControl flags

I was creating an Active Directory (AD) security auditing tool in Go and Python when I stumbled upon the UserAccountControl flags. This attribute can hold multiple statuses like ACCOUNTDISABLE , NORMAL_ACCOUNT , or DONT_EXPIRE_PASSWORD . It uses a bit-field; a bit-field is a group of bits with each bit representing a value. It is an efficient way of handling multiple statues of a record. A tool…

Fix Raspberry Pi SSH freezing issue

If your SSH connection to your Raspberry Pi is freezing or unstable, it could be because of OpenSSH TOS (Type of Service). To fix this, add IPQoS cs0 cs0 in the sshd configuration file. Open your /etc/ssh/sshd_config and add IPQoS cs0 cs0 at the bottom of the file. Please refer to the example configuration file below. # $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $ # This is the sshd…

Setup Static IP Address in Debian Linux

Setting up a static IP address in Debian Linux is straightforward. In this guide, I will be configuring the IP address using the old way (ifconfig) and requires that you have system administration rights to do the following steps: Open the network interface file with the following command: sudo vi /etc/network/interfaces Once opened, you might see something similar like this Your interface label…

Allow user or group to run sudo on specific applications in Linux

In some situation, we may want to delegate a sudo capability to Linux users or groups without completely giving them full access to the operating system. We can achieve this by using User_Alias inside the /etc/sudoers configuration file. I will share the simple settings that I used in my RHEL server. ## Sudoers allows particular users to run various commands as ## the root user, without needing…

Remove Source Path From Go&#39;s Panic Stack Trace

I would like to share the Golang’s build flag to remove the source path (GOPATH) from panic stack trace output . In production environments or commercial projects it is sometimes not ideal to display the source path because of privacy, security or other reasons. Below is an example of a stack trace output that reveals the GOPATH location which is located inside the developer’s home directory. In…

Generate text to image in Go

In this blog post, I&rsquo;ll share how to generate text to image in Go programming language (Golang). I have a previous and similar blog post using Python. You can check that post here I created this application to generate images of my Linux configuration files or source code snippets and share it via WhatsApp or other messaging platforms. Another reason is to generate featured images for my…

Create a Linux systemd entry for your application

Systemd is a Linux software suite that handles system services (daemon) and timers; it enables you to start, stop and restart your application using systemctl command. It can also start your application during operating systems boot-up sequence. Note that you will need to have root or sudo privileges for this operation. To create a systemd unit file, create a service file inside the directory…

Linux systemd entry for your Go application

Systemd is a Linux software suite that handles system services (daemon) and timers; it enables you to start, stop and restart your application using systemctl command. It can also start your application during operating systems boot-up sequence. Note that you will need to have root or sudo privileges for this operation. To create a systemd unit file, create a service file inside the directory…

Setup static IP address in Red Hat Enterprise Linux 8

Setting up a static IP address in your RHEL or CentOS is straightforward. Prerequisite This how-to guide requires that you have administrative access to the Linux operating system. Steps Inside the RHEL Operating system, open the terminal and head to /etc/sysconfig/network-scripts . Using ls command, you can see the available network devices in the directory. cd /etc/sysconfig/network-scripts ls…

How to change MySQL’s root to use mysql_native_password in Ubuntu

In some MySQL installation in Ubuntu. You cannot login as root because it is not configured to use mysql_native_password. In this post, I will teach you how to enable mysql_native_password. Log in to MySQL via terminal with sudo mysql -u root Once inside MySQL, we will need to change the default plugin authentication to mysql_native_password and set a password for root. mysql> ALTER USER…

Create MySQL User and Grant Privileges

Let say that you wanted to create a MySQL user for example johnpili and assign privileges. You can do that using the simple code snippet below: mysql> CREATE USER 'johnpili'@'localhost' IDENTIFIED BY 'Pass2Word3r'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'johnpili'@'localhost'; mysql> FLUSH PRIVILEGES;

Login as Jenkins in Linux Terminal

You may need to setup an SSH keys or environment variables to your Jenkins installations. One of the easy way to do this is to setup those environment variables inside the jenkins user account. If you installed Jenkins in CentOS or Ubuntu via YUM or APT; These package managers will setup a jenkins user account without login capability and shell. That means you cannot simply SSH to it. Using your…

Golang Linux Daemon

You build your first Golang web application and running in a remote server via SSH. The problem with that is once the SSH session is terminated it also kill any running programs associated with that SSH session. Using nohup solves this problem but I think this is okay during development and testing phase. A better way to deploy your Golang application into a Linux production environment is create…

Randomly create a time.Sleep in Golang

To randomly create a time.Sleep in Golang you can use the code snippet below. You may want to simulate a load in your web server and have an arbitrary seconds or minutes before getting the reply. package main import ( 'log' 'math/rand' 'time' ) func main () { rand . Seed ( time . Now (). UnixNano ()) for i := 0 ; i < 15 ; i ++ { delta := rand . Intn ( 6 + 1 ) // randomly generates numbers 1 to 6…

Bus Seat Reservation User Interface Concept using Vue.js

In response to this facebook post . I created a simple bus seat reservation user interface using Vue.js and SVG. I started by preparing an SVG image of the bus seat and then render the SVG elements using Javascript (VueJS). You can use a raster image (sprite) for this but I prefer to use vector graphics (SVG) because it allows me to control the stroke and background color programmatically. The bus…

MySQL Query – List Records That Don’t Exist From Another Table

Suppose you want to retrieve a list of products that are not in promotion. SELECT * FROM product t1 LEFT JOIN promo_product t2 ON t1.idProduct = t2.product_idProduct WHERE t2.idPromoProduct IS NULL

HTML drop-down placeholder

Do you ever wanted to have an HTML drop-down with default selected value (placeholder) that the user cannot re-select once they selected any valid value options? It can be done easily by adding selected and disabled attributes on the option element. Code Snippet < select > < option value = '' selected = 'selected' disabled = 'disabled' >-- SELECT --</ option > < option value = 'ACTIVE' >ACTIVE</…

Create Android Studio Shortcut on Ubuntu 18.04

You can easily create an Android Studio shortcut by creating an desktop entry using the following the steps below. In this guide, my Android Studio is installed in /opt/android-studio folder. Your folder location may differ. Open terminal and type cd ~/.local/share/applications Create a .desktop file using your favorite text editor nano android-studio.desktop My .desktop file looks like this…

How to clear your local Maven repository

I was building a multi-module project and I faced with this annoying problem with maven that keeps using old version of the maven project even though I uses mvn install -U. I usually delete my local .m2 repository folder but I found a much cleaner way to do it. mvn dependency:purge-local-repository

How to change Full Disk Encryption (LUKS) password on Ubuntu 18.04

Did you enabled the full disk encryption (LUKS) on Ubuntu 18.04? I would like to share how you can change the LUKS password. LUKS stands for Linux Unified Key Setup developed in 2004 by Clemens Fruhwirth. Similarly, Apple’s macOS have FileVault and BitLocker for Microsoft Windows operating system. In the terminal you can check the drives or partition with LUKS by using this command lsblk My result…

Make your old laptop usable again with Linux

Revive your old laptop back in service using Lubuntu a light-weight version of Ubuntu. I bought this Lenovo IdeaPad S10-3 in 2012 when I was working in Muscat, Oman. This netbook has a blazing Intel Atom processor 1.66GHz, a 2GB DDR3 RAM, and 10″ LCD screen. I was initially thinking of giving it away because when I installed Ubuntu or CentOS it is sluggish and keeps on lagging. Then I stumble upon…

Completely Delete USB Flash Drive Partition in macOS using diskutil

You may want to completely erase the partition table of your USB flash drive, including the boot record. In macOS you do easily do that using diskutil. During this COVID-19 lockdown in Malaysia, I wanted to use my weekend time in installing Linux on an old laptop. It turns out that old laptop only supports MBR and not GPT boot record and FAT32 instead of EX-FAT. I have to then delete the partition…

Load balancing and redundant Internet connection using TP-Link ER6020

Overview I started my homelab journey in 2017, set up a small server to host my files and to test my web applications. Today, I am giving my small network a bit of an upgrade by having a redundant Internet connection using a TP-Link ER6020 . I appreciate that TP-Link made their enterprise network devices affordable. If you are living in Kuala Lumpur and thinking of buying TP-Link&rsquo;s…

Golang SQLite Simple Example

In this post, I will show you a simple example how to use SQLite in Go (Golang). SQLite is one of the popular embedded, file-based database in the market used by companies like Apple, Airbus, Google, Skype, Autodesk and Dropbox. You can check out the list of well-know SQLite user in this link https://www.sqlite.org/famous.html Requirements Knowledge in Terminal or command prompt An installed Go…

Generate text to image in Python

Today, I will show you how you can generate image and add text using Python. I was working on a project requires to generate an image for facebook og:image (featured image) and since this project is source code sharing tool adding a source code snippet into the featured image make sense. I used this library on skypaste.com to generate the featured image like shown below: This project requires…

Connect to Windows Shared Folder on Ubuntu 18.04 LTS

In this post I will show you how to access Windows Shared folders from Ubuntu Linux. Install Samba sudo apt install samba In Nautilus file browser, Click Other Locations from the left panel and then enter the url of the windows share or IP address. Enter user credential if required. In common windows share settings putting WORKGROUP in the domain field will be enough Once you’ve successfully…

How to create a bootable Ubuntu USB in macOS with UNetbootin

In this guide I will teach you how to create a bootable Ubuntu USB on macOS with UNetbootin. Since UNetbootin is also available for Windows and Linux, this tutorial can be use on those operating system as well with minor differences. Ubuntu Linux is one of the most user-friendly Linux distribution in the market. I remember back in 2001 the Linux installation process was cumbersome and only for…

Neofetch is visually pleasing command-line system information tool

I saw neofetch on reddit. I installed it on my Ubuntu box. It is a really nice looking command line system information tool. I can now show it off to Windows Admin here in the office. Neofetch – A command-line system information tool written in bash 3.2+ Neofetch Screenshot

Screen recording in Ubuntu 18.04 using Kazam

Part of my work is to screen record (screencast): software demos and programming tutorial. I am also a MacOS user and in Mac I used ScreenFlow for screencasting. Since using Ubuntu as my primary operating system at work. I wanted continue my screencasting work. I once used Kazam in mid 2019 and it can handle the basic screen recording requirement we will need, mostly. It is open-source and…