Skip to main content

Posts

Showing posts from 2020

Resetting to initial State with React Hook

 Resetting to the initial state after form submission or cancelling a form submission is an integral part of the user experience when creating forms in ReactJS. This morning I was trying to find a way to reset the form I was working on. I found this to be the most effective way to reset a form // declaring the initial state const initialState = { fname: "", lname: "", email: ""} const [eachEntry, seteachEntry] = useState(initialState); const {fname, lname, email} = eachEntry ... // function to handle onSubmit event const handleSubmit = event => {     event.preventDefault();     axios.post('http://some.url/api', {          // some javascript object      }). then(() => {          event.target.reset();      } } return(     <div>          <form onSubmit={handleSubmit}>          // some form input ...

Using dotenv to hide credentials in ExpressJS

This is a quick tutorial on using dotenv in JavaScript Development When building apps, we continually need access to databases. To access those databases, we need to be authenticated to be authorized to access the resources stored. In Web Development/app building, especially when storing code in a publicly accessible repository like GitHub, we should be conscious of our credentials. The way to get around storing your code on without credentials on GitHub is by using dotenv. dotenv is a JavaScript package that enables users to and access credentials safely. In your server.js file, add the following code const express = require(“express”); const app = express(); const dotenv = require('dotenv') ... dotenv.config() ... const password = process.env.[variable_name] ... app.listen(3000, () => console.log(“server has started at port 3000”)); In the home directory, create a .env file. In the .env file create the variable name referenced in the using the following format. varia...

Web Development

For the past three months, I've been part of the Pacifica Prime BootCamp run by SwitchMaven. During my time there, I've learnt a lot about Web Development. I would like to think I'm a Full-Stack Web Developer but I have a lot to learn still. We've learnt about: HTML, CSS, JavaScript, Express JS and React JS. I will be putting out articles about those topics as I get more confident with each topic. There's so much to learn and I hope this can be a good resource for some.

Robocopy

I recently became fascinated with a tool called Robocopy. It is a command-line utility for copying files/folders that is very robust. The name in itself is Rob ust Copy. Now for those of you SysAdmin guys, you would know how to use a command-line/terminal window. But for you average dudes and dudettes, this might be a bit tricky. Not difficult, just different 😃 Now this utility can copy files especially in Windows, with a lot more information than just the file data. It can copy files/directories: over a network with resume capabilities. Useful if you have remote file servers. preserving date and time stamps. Amazing for backups. It even has a backup switch that extends this capability 😮 and skipped already copied files/directories and more Like all command line utilities, you can get more information about the usage by typing robocopy /? into the command-line. Here is a great guide for your reading .

Ransomware

Ransomware Ransomware has been in the news lately over the past few years. It has been featured in some of my favourite tv show dramas like The Blacklist and more. What is Ransomware? Ransomware is a virus attack of a computer system in which files are encrypted and a ransom demand is displayed. Business houses are the most frequented targets for this viral attack. The simplest form of this attack is just renaming the file extensions and displaying a ransom message for it to be renamed back. The most sophisticated would be locking down the filesystem with encryption and displaying an error message. The most popular ransomware of recent was WannaCry. The exploit was allegedly leaked from the United States National Security Agency. More information about WannaCry can be found here The best defences against ransomware are: User awareness. Informed users decrease the attack surface with which systems can be attacked. File System defences. Volume Shadow Copy and ZFS are the tw...

Intermittent Fasting: My experience

Intermittent fasting has become a topic of interest lately as a result of a push towards healthier lifestyles. In this article, I will briefly discuss what intermittent fasting is, the logic behind it and my personal experiences with this practice. Intermittent fasting is the practice of eating at set intervals of time and fasting the others. The most common practice is to eat within an eight hour window, usually between 10 am and 6 pm, and fast the other sixteen hours. Intermittent fasting does not really suggest which foods to avoid. The restriction is based on time. Therein lies the attraction. Followers can continue to consume their usual foods. I believe the change would be eventual as the choice of foods would gravitate towards a more sustaining type until the fasting window is completed. There also is no restriction for the timing of the fast. It would really depend on each persons preference and lifestyle. The most common windows are: 10 am to 6 pm noon to 8 pm Su...