All posts by admin

How to Remove Caches or Temporary Files in Windows

Motivation:

You may want to remove caches to update an application status or fix some issues.
You may need to remove temporary files to get some more free disk space.

Solution:

Try clearing files and folders in the directories below.

  • %USERPROFILE%\AppData\Local\Temp
  • C:\Windows\Temp
  • C:\Users\All Users\Package Cache
  • C:\Windows\SoftwareDistribution\Download
  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

Sometimes you may get permission error when deleting files or folders. If this is true then try the following command before deleting these files and folders.

takeown /f C:\Users\All Users\Package Cache /r /d y
icacls C:\Users\All Users\Package Cache /grant administrators:F /t

How to Quickly and Confidently Read Code?

Motivation:

You need to read existing source code to add your feature or fix a bug or to replicate its functions in another language or system.

Solution:
  1. Try building and running the code without any modification.
  2. Try building and running the code with your inputs.
  3. Try modifying or adding simple UI elements without touching the business logic or data layer.
  4. Try changing a variable name and making sure that the code is not broken.
  5. Try breaking a long method to smaller ones.
  6. Try breaking a large object or file to smaller ones.
  7. Try replacing an algorithm with with a better one.
  8. Try replacing an old component with a newer or better one.
  9. If you get an error when making the changes above then try showing the error on client side.
  10. If you cannot show the error on client side then try identifying the logic flow of the code related to the error, debug information, and learn about new terminologies or concepts in the code.

Example:

const maskPhone = (val) => {
    const x = val.replace(/\D+/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
    return !x[2] ? x[1] : `(${x[1]}) ${x[2]}` + (x[3] ? `-${x[3]}` : ``);
};
export { maskPhone }

If you are not sure about what the JavaScript code above does then try to learn

Another example:

<div class="container">
    <iframe class="responsive-iframe" src="https://www.youtube.com/embed/u9Dg-g7t2l4"></iframe>
</div>
.container {  
    position: relative;  
    overflow: hidden;  
    width: 100%;  
    padding-top: 56.25%; /* 16:9 Aspect Ratio (divide 9 by 16 = 0.5625) */
}
/* Style the iframe to fit in the container div with full height and width */
.responsive-iframe {  
    position: absolute;  
    top: 0;  
    left: 0;  
    bottom: 0;  
    right: 0;  
    width: 100%;  
    height: 100%;
}

If you are not sure about what the HTML and CSS code above  do then try to learn

  • how many ways an element can be placed in a web page (a document),
  • what is the position relationship between an element and its parent,
  • what is the position relationship between an element and its siblings,
  • what is the position relationship between an element and the document root, and
  • what position: relative , position: absolute , overflow: hidden do.

 

 

Software Requirements Lessons Learned

Lessons learned 1: Emerging requirements.

Problem: Requirements do not exist. They are emerging and often become incorrect and therefore constant change of requirements happens.

Context: Our goal is to ensure project’ success and client’s satisfaction. In order to achieve this goal our delivered solution must solve our client’s problems and satisfy our client’s needs. Unfortunately many clients do not know exactly what they want because they want to try a new business process or would like to enhance their current daily business workflow but the new process or workflow has not been defined yet. They would like us to build something for them to try, then if it does not work in real world then they will switch to something else.

The issue becomes even worse when they do not have time to review our prototype and await a quite complete solution.

Sometimes they consider our prototype a complete solution and want us to revise it around their constant changes for production although the architecture limits of the prototype make it very time consuming for such revision or even prevent us from doing such revision. These limits exist because we only build the prototype for the envisioned requirements, not for the endless changes.

Solution: Analysis and communication are critical to ensure that our deliverables match with client’s needs. It does not matter whether we use RUP or Agile process for development. It does not matter whether we use UML, or boxes and lines, or text, or coded prototypes or paper and pen for describing the problems that need to be solved. Our client and analyst must review, refine and confirm problem specification regularly. Otherwise formal requirements should be modeled, reviewed and approved before design begins to ensure that our project will deliver solution to the right problems.

Lessons learned 2: Vague requirements.

Problem: Requirements are described vaguely and therefore are implemented incorrectly and many detailed elements are missing.

Context: Our clients often just give what they have. It can be a video demo of their existing legacy systems, a list of what they want, some screenshots captured from other similar systems, a long conversation in an email thread, some phone calls. We build a solution based on these artifacts and it turns out that they want something completely different or many detailed requirements are missing.

Solution: Our responsibility is to clarify our client’s problems and needs. Again analysis is an important tool to clarify our client’s problems and needs. Early requirements can be described in any form, including phone calls, emails, screenshots, video demo, feature list. However all of them should then be refined properly using use cases, user interfaces, workflows, story map and prototypes for client to review regularly.

Sometimes we are stuck at analysis, especially when we analyze integration or enhancement needs that have not existed yet and require creativity. In this case a dirty prototype and a proof of concept or small technical exercises should be done so that we can have inputs for inspiring ideas for analysis.

How to Use Git

Motivation:

You want to use Git to version your files or share your files with other people.

Solution:
mkdir "D:\NETCORE"
git init
git add *.*
git commit -m "add initial files"
git remote add origin https://github.com/huybien/asp.net-core.git
git push -u origin master
  • Push changes to a remote repository.
git add .
git commit -m "CP form"
git push -u origin master
  • Update (fetch and merge) a local repository.
git pull
  • Force updating (fetch and overwrite) the current repository.
git fetch --all
git reset --hard origin/master
git clean -fd
git pull
  • Force updating (fetch and overwrite) a local repository (e.g. C:\Users\admin\Downloads\code).
git -C C:\Users\admin\Downloads\code fetch --all
git -C C:\Users\admin\Downloads\code reset --hard origin/master
git -C C:\Users\admin\Downloads\code clean -fd
git -C C:\Users\admin\Downloads\code pull
  • Pull (checkout) a remote repository (e.g. https://github.com/huybien/asp.net-core.git) to an empty local folder (e.g. C:\Users\admin\Downloads\code).
cd C:\Users\admin\Downloads\code
git init
git remote add origin -f https://github.com/huybien/asp.net-core.git
git pull origin master
or
git pull origin main
  • Reset (Revert) a local repository to a previous version.
cd C:\Users\admin\Downloads\code
git log --oneline
git reset --hard 4355842
where 4355842 is a version id.

How to Hide Your IP Location using VPN in Windows 10

Motivation:

You have VPN credentials and want to hide your IP location for a specific purpose.

Solution:

  • Setup a VPN connection using your VPN credentials.
  • Type and click View network connections in Search box to open the Network Connections window.
  • Right-click the VPN connection and select Properties in the menu.
  • Select the Networking tab.
  • Click the Internet Protocol Version 4 (TCP/IPv4) row, then click the Properties button.
  • Click the Advanced… button.
  • Select Use default gateway on remote network option.

How to Quickly and Reliably Fix a Bug

Problem:

It may take you much effort to fix a bug. The fix may not be reliable. How can you avoid this situation?

Solution:
  1. Try to reliably reproduce the bug. It is okay if this may not be successful.
  2. Search for an existing solution using the error message, the library or framework name and version, and the operating system name and version. This can save us a lot of effort.
  3. Try to understand all the concepts in the error message.
  4. Debug and log messages to identify the exact location of the source code that causes the issue. In order to to this we need to do the followings.
    • Identifying the flow of the data, i.e. the use case, the entry point and the exit point.
    • Trying to understand the programming language syntax. Do not guess anything.
    • Trying to understand the purpose, inputs and outputs of a library function. Again, do not guess anything.
    • Trying to understand the data structure and a part of the database schema related to the use case.
    • Trying to review some values inside the database if possible.
    • Trying to understand the concepts, algorithms and architecture related to the use case.
    • These steps may be done in parallel and iteratively.
  5. Guess a cause of the problem based on the information retrieved in the third step.
  6. Try to isolate the issue, i.e. try to reproduce the issue using specific code and unit tests, if possible.
  7. Search for or propose a solution for the cause, i.e. propose a fix.
  8. Test the fix.
  9. Repeat from Step 5 to 8 if needed.

How to Fix a Hacked WordPress Website

Problem:

When you visit your WordPress website you are randomly redirected to unwanted websites.

Solution:
  • Log in your website as an Administrator.
  • Go to Appearance >> Theme Editor.
  • Click on the Theme Functions link on the right side.
  • Verify if malicious code was injected into the functions.php file.

Example of malicious code:

<?php
@ini_set('display_errors', '0');
error_reporting(0);
global $zeeta;
if (!$npDcheckClassBgp && !isset($zeeta)) {
  • If yes, then download the functions.php file to your machine via FTP, remove the malicious code, then upload it to your server.
  • If you have several themes in your website then activate them one by one and repeat the procedure for all of them.
  • Open the wp-config.php file.
  • Verify if malicious code was injected into the wp-config.php file.

Example of malicious code:

include_once(ABSPATH . WPINC . '/header.php');
  • If yes, then verify content of the wp-includes/header.php file, and possibly remove the wp-includes/header.php file, then remove the malicious code in the wp-config.php file.
  • Copy a small string of malicious code, for example npDcheckClassBgp, and search for it in the content of all the files using the commands (in Windows) below.
cd C:\inetpub\wwwroot
findstr /s "npDcheckClassBgp" *.*

where C:\inetpub\wwwroot is the path of the parent of your WordPress website.

  • If you find the string in any file then review the content of the file and remove the malicious code.
  • In Windows, stop the website using the command below.
net stop w3svc
  • Delete all the files and folders except the wp-content folder, the wp-config.php, .htaccess, and web.config file.
  • Review and remove all the suspicious contents in your wp-content directory.
  • Go to the wp-content\plugins folder.
  • Delete all the plugins, especially the plugins closed due to Guideline Violation.
  • Manually re-download and unzip all the necessary plugins.
  • Download the latest version of WordPress.
  • Unzip and copy the the latest version of WordPress to the root of your website.
  • In Windows, start the website using the command below.
net start w3svc
  • Log in your website as an Administrator.
  • Remove all the unused plug-ins or themes.
  • Install, activate and configure a CAPTCHA plug-in to protect Login Form, Registration Form, Lost Password Form, Reset Password Form and Comment Form if there is no one.
  • Disable insecure FTP access if there is one.
  • Install and activate the Simple History plugin to review access to your website. After 1 or 2 days, review the access information, and possibly block the malicious IP addresses using the Windows Firewall.
  • Install, activate and configure Cerber Security plug-in to automatically detect and block the malicious IP addresses.

 

How to Fix “The parameter is incorrect” Issue When Disabling the Sync Host OneSyncSvc Service

Problem:

The Sync Host OneSyncSvc service was not started correctly and caused error in the Server Manager.

You wanted to disable this service. However you got the “The parameter is incorrect” error message when disabling it.

Solution:
  1. Click on the Search icon, type regedit, press Enter.
  2. Locate the key below
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OneSyncSvc

3.  Change the Start value from 2 to 4 (Disabled).

4. Restart the server.

 

How to Fix the “We can’t sign into your account” Issue in Windows

Problem:

You remotely connect o a computer using a Windows Domain account and get the error message below.

We can't sign into your account
Solution:
  1. Login the computer as a Local Administrator.
  2. Open C:\Users and delete the folder of the Windows Domain account.
  3. Click Search icon, enter regedit, and press Enter.
  4. Navigate to the path below.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

4. Look for the Profile of the Windows Domain account by reviewing the ProfileImagePath value.

5. Delete the Profile key of the Windows Domain account.

6. Restart the machine.

How to Manually Install PHP 7.4 for Windows Server 2019

Motivation:

To understand how PHP works with IIS in order to be able to update PHP to any version to address compatibility or security issues.

Using a tool to install PHP for IIS, for example Microsoft Web Platform Installer 5.0 https://www.microsoft.com/web/downloads/platform.aspx, restricts us from using only versions supported by the tool.

Solution:

  • Install CGI for IIS.
  • Download VC15 x86 Non Thread Safe package here or under PHP 7.4 section from http://windows.php.net/download/
  • Extract the ZIP file to the C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86 folder.
  • Rename the php-.ini-development file to php.ini.
  • Open the php.ini file and add the following line at the end of the file.
extension=php_wincache.dll
  • Uncomment the following lines
fastcgi.impersonate = 1;

cgi.fix_pathinfo=1;
cgi.force_redirect = 1 (and change the value to 0, i.e. cgi.force_redirect = 0)

extension_dir = "C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\ext"

extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_openssl.dll

error_log = "C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\php_errors.log"

error_log = syslog
  • A sample php.ini file can be download here.
  • Add C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86 to System Path.
  • Download x86 package of WinCache 2.0 for PHP 7.4 here or from https://sourceforge.net/projects/wincache/.
  • Extract and copy the php_wincache.dll file to C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\ext
    folder.
  • Open IIS, click on Server name, double click on Handler Mappings, click on Add Module Mapping, and enter below information
Request path = *.php
Module = FastCgiModule
Executable = "C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\php-cgi.exe"
Name = PHP 7.4
Request Restrictions = File or folder

Open a Command Prompt, execute below command and ensure that NO WARNINGS APPEAR.

php -version
  • Create phpinfo.php file with below content in the website folder and test the result.
<?php
phpinfo();
?>