Error.message in try catch block in JS
Error class in JS has the message property.
We should try to throw Error object instead of other random stuff like boolean, string etc.
This includes errors thrown from Promise.reject()
E.g. In the codes below, test(f1)
works while test(f2)
does not.
JS has no overloading
JS has no overloading.
Instead, the later function overwrites the earlier ones.
E.g. In the codes below, the output will be no param
.
some tips of changing a class component to a functional component
There are some reasons we may want to convert a class component to a functional component.
E.g. Hooks are only available in functional components like const queryString = useLocation().search;
This can be quite useful in React Router.
Some tips for cookies in web requests
Usually each web API request sends with a cookie, and the response has a new cookie that is used by next request.
However if we use document.cookie
to get the cookie it may not be accurate if there’re multiple requests and responses.
button tag vs input type="button" tag
There are some key differences between <button/> and <input type=”button” />:
React homepage setup
To update my earlier blog post PUBLIC_URL in React is not dynamic , I have found a solution to it.
Outlook web add-in traps
- Cache of the Outlook add-in needs to be cleared before any update of it can apply
- Reinstall the add-in
for /d %d in ("%LOCALAPPDATA%\Microsoft\Office\16.0\Wef\*") do @rmdir /s /q "%d"
del /s /f /q /a:h %LOCALAPPDATA%\Packages\Microsoft.Win32WebViewHost_cw5n1h2txyewy\AC\#!123\INetCache\*
rmdir /s /q %userprofile%\AppData\Local\Microsoft\Outlook\HubAppFileCache
References:
MS docs to clear cache
Some ways to clear cache
Postgres SQL skills
E.g.1:
Postgres connection maxed out for Hikari Connection Pool
Error:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: sorry, too many clients already
npm install failed in Azure pipeline
Error:
#8 [4/5] RUN npm install
#8 18.80 npm ERR! code EMFILE
#8 18.80 npm ERR! syscall open
#8 18.80 npm ERR! path /root/.npm/_cacache/index-v5/a0/7a/7e48bcbef3e333c0cda8208f4902ea385bb700f4d8c414525a120c4bba14
#8 18.80 npm ERR! errno -24
#8 18.80 npm ERR! EMFILE: too many open files, open '/root/.npm/_cacache/index-v5/a0/7a/7e48bcbef3e333c0cda8208f4902ea385bb700f4d8c414525a120c4bba14'
#8 18.85
#8 18.85 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-24T20_54_30_709Z-debug-0.log
#8 ERROR: process "/bin/sh -c npm install" did not complete successfully: exit code: 232
Code Signing Certificate
There’s an industry wide change of where to store the private key of a code signing certificate. Most if not all CAs have adopted and announced this change, e.g. DigiCert: https://knowledge.digicert.com/generalinformation/new-private-key-storage-requirement-for-standard-code-signing-certificates-november-2022.html
Move from MySql to PostgreSQL
Things to be changed as migrating from MySql to PostgreSQL
PUBLIC_URL in React is not dynamic
Symptom
PUBLIC_URL
is a system variable defined in file .env and used by Create React App.
Once we run npm run build
, this is the base URL as a static string.
It cannot be dynamically set in a configuration file at run time.
As a result, if two builds are using different PUBLIC_URL then they have to be built separately, which is bad for containerization.
solution
So far I have found no solution
MongoDB upgrade error in .NET
Upgrading MongoDB driver in .NET project causing dependent assembly error
Docker-compose port mapping
How to route network traffic from same port to different containers
Azure pipeline pitfalls
Some Azure pipeline pitfalls to be aware of
CSS table max height not working
CSS <td> max-height
is not working for large text
Some hints for Azure pipeline
Below are some hints to use Azure pipeline
Serialize enums to ints with Gson
How to serialize enums to ints instead of strings with Gson?
(Below answer is from chatGPT)
By default, the Gson library serializes enums into strings. However, if you want to serialize enums into integers instead of strings, you can create a custom Gson serializer/deserializer for your enum class. Here’s an example of how you can achieve this:
Null-coalesce operator
What is the output of below? 1? 3? 5? 6?\
some ways to share data among React components
some ways to share data among React components
1.static data of a class
Returning null trap
Problem
In the example below, GetData_1()
throws null pointer exception whereas GetData_2()
returns a value. Why?
React state life cycle
React state life cycle
See the link from offical webiste:
https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/
React state pitfall
setState() may have delayed effect
This is because it is asynchronous method.
Reading this.state may get the wrong state.
React.js basics for beginners
You may want to use npx create-react-app my-app-name
as a starting point.
But there still can be issues like below.
Intellij basics
Intellij intellisense does not recognize classes or methods. How to fix it?
Powershell tips
1. Find cmd parameter needs to be double quoted
Dependency injection via Unity Container
Summary:
UnityContainer is one of the libraries to implement dependency injection in C#.
GitHub Dependabot alerts on old libraries
Problem:
GitHub Dependabot alerts on old libraries, pointing out security vulnerabilities.
grep does not support UTF-16
Problem:
grep command in Linux doesn’t support UTF-16.
Dependency update mechanism
Problem:
Async and await brief summary
Please refer to the link below:
https://saebamini.com/common-async-and-await-misconceptions/
Crash before class instantiation
Is it possible to crash in a class before its constructor runs?
Yes.
One possibility is it cannot load the libraries it’s referencing.
E.g.
If the actual log4net.dll is not under version 1.2.13.0, then the crash will happen.
Tips for beginners using Kotlin in Android Studio
Some tips for beginners developing Android apps using Kotlin in Android Studio
- Useful references:
- Google documentation
https://developer.android.com/topic/architecture
- Google documentation
Java spring-boot configuration error reflect.InaccessibleObjectException
Error message:
17:12:28.224 ERROR [com.Company.program.boot.programApplicationLauncher.main()] o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Cannot load configuration class: com.Company.program.boot.config.ApplicationConfiguration
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:395) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
......
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.ExceptionInInitializerError: null
at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:166) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
......
... 17 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @43905a1d
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
......
... 28 common frames omitted
Code block highlight not working in Jekyll
Triple back ticks ``` used to work but no longer does now.
SQL traps - DISTINCT and IN clauses
Test your knowledge with below questions:
LINQ outer join
Some tips on how to do outer joins in LINQ
Git branching tips
Some tips of Git branching
T-SQL practical tips
Some practical tips against traps in T-SQL
LINQ compared with SQL
LINQ is better than SQL in some ways. https://www.linqpad.net/WhyLINQBeatsSQL.aspx
IEnumerable and yield usage
Below is an example of using IEnumerable and yield.
Microsoft Azure Administrator Associate
Early this month I got the Microsoft Azure Administrator Associate Certificate.
Badge as below.
SQL table joining special skill
An example of SQL table joining special skill
Microsoft Ignite Azure Admin Challenge
Microsoft Ignite Azure Admin Challenge
Ansible variable precedence
Ansible variable precedence
(Bottom has the highest precedence)
Ansible tips
Ansible tips
JavaScript basics
Demo page:
Link to demo
How to fix: chmod doesn't work in WSL
Problem:
After chmod, the permissions got lost due to being overwritten by Windows
How to install Ansible on WSL
1. Update apt
sudo apt-get update
......
Fetched 7978 kB in 1min 41s (79.3 kB/s)
Reading package lists... Done
Docker mistakes some files for folders, and folders for files.
1. Docker mistakes some files for folders, and folders for files.
Ubuntu Docker container missing Chinese
- Ubuntu Docker container doesn’t have Chinese by default.
Solution:- Option 1: install Chinese manually
```bash #Check locale locale -a #Check installed packages dpkg -l | less
- Option 1: install Chinese manually
Docker basics
Commands
Docker version issues
- Failed to upgrade to 2.3.0.5
```bat Attempted to perform an unauthorized operation. at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind) at CommunityInstaller.AutoStartAction.DoAsync(CancellationToken cancelToken) at CommunityInstaller.InstallWorkflow.d__34.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CommunityInstaller.InstallWorkflow. d__29.MoveNext()
GitHub connection issue
- GitHub may have connection error like this:
git push -u origin master fatal: unable to access 'https://github.com/jasonmccb/myWSLSync.git/': Could not resolve host: github.com
A few tips of using WSL
Please reference the bash code example of syncing folders from one drive to another under WSL here:
https://github.com/jasonmccb/myWSLSync.git
- USB disk needs to be mounted MANUALLY from time to time
sudo mkdir /mnt/e sudo mount -t drvfs E: /mnt/e sudo umount /mnt/e
rsync usage
- rsync Linux man page:
https://linux.die.net/man/1/rsync
Setting up Qt, CMake with Visual Studio
A link to CMake set up:
Common programming characteristics
- Please see the table below.
AWS cheat sheet
- AWS cheat sheet is a good reference for basic AWS concepts. It also has a site search function.
https://digitalcloud.training/certification-training/aws-certified-cloud-practitioner/
GitHub tips on changing commit history
Tips
- Use
git help <verb>
to learn the Git commands.
C# Dependency Injection and Singleton
- Why Singleton class needs to be sealed?
https://dotnettutorials.net/lesson/singleton-class-sealed/
In short, internal derived class will be able to create instances.
Algolia implementation
How to install Algolia and push content?
https://community.algolia.com/jekyll-algolia/getting-started.html
Ruby on rails basics
- How to run Ruby program:
ruby test.rb
or
irb
Replace Carriage Return and Line Feed in Notepad++
In the Notepad++ menubar click Edit -> EOL Conversion to format carriage return in entire file.
A link to guide
Review of the GitHub procedure
Summary:
Install Ubuntu on Windows 10
Windows 10 does support Linux subsystem.(A link to guide)
Here’s a summary of how to install Ubuntu on Win 10.
Review and clean up for the whole internship
What have been done:
Presentation has been done
What have been done:
Working on the presentation and report
What have been done:
Working on the presentation and report
What have been done:
Email confirmation is working on database
What have been done:
Company holiday
Company holiday
Public holiday
Public holiday
Confirmation link handling
What have been done:
Email ID generation and usage
What have been done:
Fixed a Thymeleaf error in getting template
What have been done:
(Shifted from Jan.31) Email file names are generated from special data
What have been done:
Fixed the null properties issues for Special import
What have been done:
Fixed Thymeleaf parsing error on single quotation mark
What have been done:
Updated email template and fixed a bug causing error to save special to DB
What have been done:
Annual leave
What have been done:
Fixed a Thymeleaf parsing exception
What have been done:
Product branding
What have been done:
Created email template using Thymeleaf
What have been done:
Added Thymeleaf in Java
What have been done:
Fixed the defects on transitioning method found by 7 test cases
What have been done:
Company holiday
Comany holiday.
Company holiday
Comany holiday.
Added more test cases for the special and email transition funtion
What have been done:
Company holiday
Comany holiday.
Corrected the workflow for emails and special transitioning
What have been done:
JUnit test for state transitioning method
What have been done:
Company holiday
Comany holiday.
Added email state transitioning method
What have been done:
Added 3 more headers in Excel spreadsheet and corresponding reading logic
What have been done:
Implemented the logic to get date cell from Excel
What have been done:
Public holiday
Public holiday.
Public holiday
Public holiday. Went tramping at Orongorongo Track, having a good time.
Public holiday
Public holiday. Happy 2020.
Annual leave
Annual leave. Happy new year.
Corrected the filtering logic
What have been done:
Added email module and related DB query methods
What have been done:
Public holiday
Public holiday. Merry Christmas.
Public holiday
Public holiday. Merry Christmas.
Public holiday
Public holiday. Merry Christmas.
Discussed and confirmed the email system logic
What have been done:
Annual leave
Annual leave.
Fixed the duplicate record bug while importing from Excel to DB
What have been done:
Fixed the bug in Excel writing
What have been done:
Studied about Mongo DB
What have been done:
Fixed MongoDB related issues
What have been done:
Annual leave
Annual leave.
UI improvements
What have been done:
Merged MongoDB branch into master
What have been done:
Fixed logging issues
What have been done:
Sick leave
Nothing has been today as I am on sick leave.
Discussion on the new architecture of the application
What have been done:
Added logger to the program
What have been done:
Reprioritization on business requirements
What have been done:
Production release, using jar instead of GitHub
What have been done:
Fixed issues related to data and format
What have been done:
Misc enhancements
What have been done:
Reading new columns for validation
What have been done:
Improved exception handling
What have been done:
Production release, excel reader enhancement
What have been done:
Enhancement, java script (continued)
What have been done:
Collect data from bars and restaurants
What have been done:
Enhancement - java script
What have been done:
enhancement, webpage and GUI
What have been done:
Tue release, fixed issues caused by configuration and input spreadsheet
What have been done:
Implemented functionalities with top priority listed in issue 14
What have been done:
Review of the week
What have been done:
Define product backlogs and priorities
What have been done:
The beer web is live in production
What have been done:
Diagnose existing problems
What have been done:
Beer web day 1
Day 1 is about setting up the environment and the tools, and also the introduction of the beer web architecture. What have been done: