Tech Junkie Blog

Latest Posts

Tuesday, August 14, 2018

In this post we are going to install MongoDB on a Linux operating system.

Here are the steps:

1.  Download the community edition of MongoDB from the page click on the "Linux" tab is selected and select the Linux version that you want

2. After you download the file extract the file with the tar command

tar -zxvf mongodb-linux-x86_64-rhel70-4.0.1.tgz

3. Create a new folder in the /opt/ directory call mongodb with the command mkdir /opt/mongodb
4. Copy the extracted files to the newly created folder with the command

cp -R -n mongodb-linux-x86_64-rhel70-4.0.1/ /opt/mongodb

5. Type mongod to verify that MongoDB has been installed

You will noticed that MongoDB tries to start itself but shut itself down because there's no data 
folder that it expects.  That's easy enough to fix.  All you have to do is type in the following
command in the terminal

mkdir /data
mkdir /data/db/

Now you can type mongod to start MongoDB.

Monday, August 13, 2018

JavaScript does not have a built-in feature to define a namespace.  A namespace is basically a container of your code that it does not pollute the other codes that's on page.  Namespace allows you to play nice with people's code and other JavaScript libraries.

Fortunately, JavaScript functions have their own contexts and scope.  Therefore, we can use functions as a namespace so that it does not pollute the global scope.

The easiest way to create a namespace on a page is to encapsulate everything in an anonymous function like the code below.

        (function () {
            // put your code here


Another way of using namespace is to assign the anonymous function to a variable

       var myNameSpace = (function () {
            // put your code here


Friday, August 10, 2018

Linux installation comes with OpenJDK, but you want to use the official JDK from Oracle instead to run most of the software.  This post will show you the steps to install the Oracle JDK

First let's check to see what version of JDK we have installed by running the command

java -version

As you can see Fedora installs the OpenJDK library by default.  What we want to do is replace it with the Oracle version instead.

Type the address
into Firefox in the Fedora VM and click on the "JDK" download button

Thursday, August 9, 2018

One of the most useful feature in Azure is the ability to reset your virtual machine's password.  There will be times when you create a virtual machine that you put aside for a long time and you forgot the password for the machine.

To reset your password do the following:

1.  Log into Azure by typing the URL
2. Click on the "Virtual Machines" link

3. Select the virtual machine you want to reset your password on

4. Click "Start" to start the machine, your machine must be running before you can reset your password

5. Under "SUPPORT + TROUBLESHOOTING" select "Reset Password"

6.  Select the "Reset Password" radio button, enter the username and password you want to reset to.  Then click "Update" when you are finish

Surprisingly the reset password function takes a long time to apply. So you have to wait for a while before you can use your virtual machine again.

Wednesday, August 8, 2018

An ASP.NET MVC can get big, and it could be overwhelming.  Areas are a way to break up the application into smaller segments,  A perfect candidate for an Area is the Administrative features of the site because it has multiple pages, and functionalities.  So it is a good idea to segment off the Administration area to its own area (no pun intended).

To add an Area to your MVC application right-click on the project and click "Add", then select "Area..."

Type in the word "Admin" in the "Add Area" dialog

Make sure AreaRegistration,RegisterAllAreas method is called in the Global.asax.cs file so that your "Admin" area is registered

The Areas folder structure should look like this.

Now we want to create a controller for the Admin Area, right-click "Controllers" folder under "Admin" and click "Add", then select "Controller"

Select and empty controller

Call the controller "HomeController", then click "Add"

Open the HomeController.cs file under the "Contollers" folder in the "Admin" folder, right-click on the "Index" method, then click "Add View"

Except the default options for the view and select "Add"

Open the Index.cshtml and type in the following code

    ViewBag.Title = "Index";


<h1>This is from the Admin Area</h1>

Now if you type in the route /Admin/Home/Index you see the message "This is from the Admin Area"

Now comes the annoying part about Areas, when you type in the route /Home/Index you will get an error that the Home controller is not unique.  That is because the MVC framework puts all controllers in finds in the application into a flat list regardless of namespace.

In order for us to fix this issue we need to specify the namespace in both the "AdminAreaRegistration.cs" file and RouteConfig.cs file

First let's fix the AdminAreaRegistration.cs file, open the file and type in the following code in the RegisterArea method

        public override void RegisterArea(AreaRegistrationContext context) 

                new { action = "Index", id = UrlParameter.Optional },
                new string[] { typeof(NorthwindCafe.Areas.Admin.Controllers.HomeController).Namespace }

Notice in the last line new string[] { "NorthwindCafe.Areas.Admin.Controllers" } we set the namespace for the Admin Area controls so that MVC looks for the controllers that are only in that namespace

Now let's do the same thing for the RouteConfig.cs file. Open the RouteConfig.cs file and change the routes.MapRoute method to the following

                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new string[] {typeof(NorthwindCafe.Controllers.HomeController).Namespace}

Now when you type in the route /Admin/Home/Index you see the Admin Index.cshtml page

And when you type in the /Home/Index route you see the application home page

Tuesday, August 7, 2018