Showing posts from May, 2020

Unit test c#: Create Fake Httpcontext to bypass Null exception for User object

Microsoft Visual studio Test Framework
Requirement: Nuget package Moq (or later)
Settings in visual studio: Menu->Tools->Options ->Debugging->General Tick "Use Managed Compatibility Mode"
Code: (copied from stackoverflow) Step 1: Create a new class FakeHttpContext and paste the below code. Change the Returns value to whatever user name you need.
public static class FakeHttpContext    {         public static void SetFakeContext(this Controller controller)         {
            var httpContext = MakeFakeContext();             ControllerContext context =             new ControllerContext(             new RequestContext(httpContext,             new RouteData()), controller);             controller.ControllerContext = context;         }

        private static HttpContextBase MakeFakeContext()         {             var context = new Mock<HttpContextBase>();             var request = new Mock<HttpRequestBase>();             var response = new Mock<HttpResponseBase&g…

Accessing SMB share from Raspberry pi (or linux)

Install smbclient :sudo apt update sudo apt install smbclientList the share items in the server:smbclient -L hostfor example: smbclient -L need to enter password.then you'll see the result like this:Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.9.5-Debian] Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers RaspberrypiShare Disk IPC$ IPC IPC Service (Samba 4.9.5-Debian) pi Disk Home Directories Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.9.5-Debian] Server Comment --------- ------- RASPBERRYPI Samba 4.9.5-Debian Workgroup Master --------- -------To browse Shared folder :smbclient \\\\\\RaspberrypiShare pa$$w0rd

Temperature/CPU/Memory info of Raspberry Pi in console

Open the console/terminal in the desktop or
Connect to the raspberry pi via ssh and type in the below command

For temperature:
/opt/vc/bin/vcgencmd measure_temp

For CPU info:
cat /proc/cpuinfo

For Memory info:
cat /proc/meminfo

Add Python(or Java or anything) to Environment variables

After installation of python in windows 10, python is not added to environment variable by default. If you want to use cmd for python, then python installed path must be configured in the environment variable.  When you type python in cmd, you'll see the below message:
Follow the below steps to add python to environment: 1) Open System in Control panel 2) Click Advanced system settings 3)Click Environment Variables 4) Select Path in User Variables and click edit 5) Either create new and type in the path of Python installed location or Browse the folder using browse button in the above screenshot.
6) Click OK and close the Environment variables settings window and all other opened windows.  7) Start a new command prompt and type python to test.  Done!