Posts

Removing duplicate lines in a text file using notepad++

Image
First ensure the TextFx plugin has been installed in your version of notepad++. Some example text: I then copy and paste that block of text to ensure there are duplicate lines: Removing the duplicates involves THREE steps: 1. If you have not already done so, ensure the appropriate TextFX plugin is checked. Select TextFX > TextFX Tools > Sort outputs only UNIQUE at column lines: 2. Select ALL of your text (select Control + A) 3. Select TextFX > TextFX Tools > Sort lines case sensitive (at column): See that the duplicate lines have been identified and removed:

Using robocopy to transfer files: tips and tricks

Image
1. To copy a single file [code language="xml"] robocopy c:\this_folder d:\that_folder file.txt [/code]   2. To copy multiple files [code language="xml"] robocopy c:\this_folder d:\that_folder file1.txt file2.txt [/code]   3. To copy all files of a given extension [code language="xml"] robocopy c:\this_folder d:\that_folder *.txt [/code]   4. To copy the contents of an entire directory Robocopy creates the d:\that_folder\a directory and copies the files from the c:\this_folder\a directory into it. Use the E/ switch to copy the entire directory tree under c:\this_folder\a [code language="xml"] robocopy c:\this_folder\a d:\that_folder\a /E [/code]   5. To exclude existing files from the copy A really good tip taken from this GitHub link : This can save a lot of time particularly if you have to copy many large sized files. [code language="xml"] robocopy c:\this_folder d:\that_folder /E /XC /XN /XO [/code] /E - ...

How to remove lines containing specific text in Notepad++ using the Bookmarks method

Image
How to use Notepad++ to remove all lines containing a specific text. First install Notepad++ if you have not already done so, given that it really is a powerful piece of software: https://notepad-plus-plus.org/download/ Now we can demonstrate an example with the following XML-style text: Suppose we wish to remove all lines containing the text "wpdm" To do this select Control+F to fire up the Find dialog. Select the Mark tab, enter the text you wish to search for and make sure the Bookmark line checkbox is set: Select the Mark all button and close the dialog. Observe that all lines containing "wpdm" are bookmarked: To remove the bookmarked lines, select Search > Bookmarks > Remove bookmarked lines: So that the bookmarked lines are removed as shown:

How to programmatically control access to files in C# using FileSecurity objects

Image
A quick demonstration on how to control access to files in real-time. As described in the Microsoft documentation , the control access to a file can be added or removed by obtaining the FileSecurity object from that file, then modified, and then applied back to the file. In this example I choose to change the file access properties of a simple icon file "icon.ico": So that before modifying the properties it can be opened straightforwardly as follows: To demonstrate how we can alter the access properties in real-time, create a C# console application in Visual Studio and add the following code. Note the use of WindowsIdentity.GetCurrent() api used to obtain the necessary username/domain details of the current Windows user: [code language="csharp"] using System; using System.IO; using System.Security.AccessControl; using System.Security.Principal; namespace FileControlAccess { class Program { static void Main(string[] args) { ...

Using OpenCV for image handling operations

1. Load an image and display it [code language="cpp"] //Loads image and displays #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> int main() { cv::Mat image = cv::imread("spots2.jpg", CV_LOAD_IMAGE_COLOR); if( false == image.data ) { std::cout << "Could not open or find the image" << std::endl ; return -1; } cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); cv::imshow( "Display window", image ); cv::waitKey(0); return 0; } [/code] 2. Add a trackbar to blend two images [code language="cpp"] #include <cv.h> #include <highgui.h> const int alpha_slider_max = 100; int alpha_slider; double alpha; double beta; cv::Mat src1; cv::Mat src2; cv::Mat dst; void on_trackbar( int, void* ) { alpha = (double) alpha_slider/alpha_slider_max ; beta = ( 1.0 - alpha ); cv::add...

Handling mouse event commands in Listview controls in WPF / MVVM

Image
Some instructions on how to intercept events when clicking on Listview controls in WPF / MVVM. Step 1: Create a new WPF application in Visual Studio Step 2: Ensure necessary resources are added System.IO.Compression System.IO.Compression.FileSystem System.Windows.Interactivity Step 3: Add the MainWindowViewModel class MainWindowViewModel.cs [code language="csharp"] using System.Collections.Generic; using System.Windows; using System.Windows.Input; namespace ListviewEvent { public class Item { public Item(string name, string matches) { Name = name; Matches = matches; } public string Name { get; set; } public string Matches { get; set; } } public class ItemHandler { public ItemHandler() { Items = new List<Item>(); } public List<Item> Items { get; private set; } public void Add(Item item) { Items.Add(item); } } ...

How to automatically increment build versions in Visual Studio

Image
Some instructions on how to automatically increment the build number of your Visual Studio project. What was important to me was to automatically increment the build and version number of my executable files using Visual Studio. Some important StackOverflow links helped me to achieve this: https://stackoverflow.com/questions/356543/can-i-automatically-increment-the-file-build-version-when-using-visual-studio https://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio To demonstrate the instructions contained in the StackOverflow links, first create a new Visual Studio project. For simplicity, choose a .NET console application: Notice that a file called AssemblyInfo.cs is automatically created: Modify the AssemblyInfo.cs file, so that the AssemblyVersion attribute ends with an asterisk. Also comment out or remove the second of these lines, AssemblyFileVersion, so that we just have the following: AssemblyInfo.cs ...