2 Nov 2021

Get One Line or Count the Number of Lines, Words, Characters in PowerShell

收藏到CSDN网摘

PowerShell is replacing cmd.exe in the new Windows operating systems, it's more efficient and powerful than its predecessor. The only drawback might be that the commands are much longer than what we used to see in cmd.exe. Counting the lines, words, even the characters are very useful - well, sometimes at least. This task can be easily done using some GUI software such as MS Word, Notepad, or vim if you prefer. PowerShell is capable of doing these jobs as well. Here is how ~

20 Oct 2021

Upgrade PowerShell to the Latest Version

收藏到CSDN网摘

From time to time, the MS PowerShell prompts new version message as long as it was started. An usual way to upgrade would be dive into MS's github repository to download the latest release. Then, a standard installation process can be carried out the deploy the latest version on your system. However, as we are already inside the commandline there is another way of doing the same thing using one line of command.

17 Jun 2021

Image 2 ASCII - ascii art generator

收藏到CSDN网摘

Converting images to ASCII, aka. ASCII art, has been explored by developers long time ago back to the time of DOS age. It is more about having fun but there are also some really good publications around this topic. Someone implemented online services to convert uploaded images to ASCII art like THIS one

The first answer under THIS QUESTION has a very detailed explanation and experiments of different approaches to this problem. A simple and straightforward approach is to do a pixel-2-text mapping from the image the the result ASCII text file. To avoid making the text file overcrowded, developers use to have some carefully selected character lists to reduce the intense level (number of chars used). So the process is more like a classification process: 

(1) find out which category the current pixel falls into; 
(2) pick up the character that represents the current category; 
(3) walking through the image pixel by pixel and repeat the process to generate the result text file.

28 Apr 2021

How to test if a point is inside a sector?

收藏到CSDN网摘

If we have a sector (partial circle) defined by the centre C, radius R, starting angle point S, and ending angle point E. How can we test if a given point P is inside or outside the sector? The idea is to define 2 function: the one is to test if one vector can be obtained by rotating from another vector clockwise (or anti-clockwise if needed); the other is to test if the distance from the point to the centre is less than or equal to the radius. Then, the problem becomes 3 tests: (1) clockwise rotation from starting vector to the point; (2) anti-clockwise rotation from the ending vector to the point; and (3) the distance from P to C is less than R.

How to test if a point is inside of a triangle?

收藏到CSDN网摘

To determine if a point P is inside or outside a given triangle defined by 3 vertices P1, P2, and P3. The edges can be calculated first as 3 vectors: P12 = P1-P2; P23 = P2-P3; P31 = P3-P1. Then, its a simple task.

12 Jan 2021

Instant Update Plots in Jupyter Notebook

收藏到CSDN网摘

Jupyter Notebook is a very effective toolkit for both teaching and learning. The interactive mode is straightforward for demonstrating the logic behind the code blocks and explaining how the programme works segment by segment. With the help of powerful Matlab-equivalent matplotlib library, data plotting can be easilly implemented. However, from time to time, you might miss Matlab's `hold on` capability that enables the user draw on and update the plot instantly without producing multiple figures that flood your screen. In Jupyter notebook, if the plt.show() was called without a loop it will produce multiple outputs as many as your loop count, which is not convenient. To make it works in the same way as Matlab's `hold on`, all we need to do is: