Why database should be taught before programming in universities

Learn Database before Coding

Often students from initial semester ask me how do we store our data in our programming project? When students join university to learn about computer science and technology they are usually taught programming first in courses like introduction to programming. As part of coursework students are required to work on a project. Majority of the projects, in fact almost all projects involve data handling and that data needs to be stored somewhere.

Problem students face

As a novice students don’t know how to store data. One option is to store data in plain text files if filing is taught to them but in that case their project becomes too complex for them. In my opinion, file formats is an advanced topic for students that have just started learning how to program. So, students get stuck where and how to store data. They create variables and arrays to store data in memory but that is not very useful until they have option to store their data somewhere permanently that they can retrieve later. Otherwise, every time they run their project they have to feed data from the beginning.

Teach Database before Programming

If universities modify their courses and add database in first semester and replace programming course with it then it would be easier for students to get started in computer science degree. Introduction to database is relatively easier course then programming and students will know what is database, how to store data in database, and how to retrieve it later using SQL. Then in next semester if they do a programming course then it will require only one lecture to teach them how to access database from your code and how to store and retrieve data. That will not only make their projects more valuable but will make more sense to them and they can take it to advance level in forthcoming courses.

Your Take?

What is your opinion? Please, let me know in the comments.

Creating Git branch in detached HEAD State

Recently, I came across a situation where I checked out a git branch and it showed me this message:

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

I guess this happened because the branch that I was checking out was rebased. Otherwise, it usually happens when you checkout a commit with its hash. But in my case, I was checking out a branch. Anyway, this is a special state called “detached HEAD”. While you can commit changes in this state, those commits don’t belong to any branch and will become inaccessible as soon as you check out another branch. But what if you do want to keep those commits?

The answer, unsurprisingly, is to use the “checkout” command again and you can use the same branch again:

git checkout <branch> #now you're in detached head state
# do some work and stage it
git add --all
git commit -m "add some work while in detached head state"
git branch <branch>
git checkout <branch>

Pretty easy, right?

Missing Hibernate option in Windows 10 Power Options?

Is Hibernate option missing from the Power Options in the Control Panel like in the screenshot below?

Here is a way to restore the missing Hibernate option back to the Power Options.

How to Fix?

Click the Cortana Search box on your taskbar, type cmd, right-click on the Command Prompt and select Run as administrator.

Once the Command Prompt is launched, type in the following command to enable the Hibernate feature.

powercfg /hibernate on

Next, run the following command to change the hibernation file type to full.

powercfg /h /type full

Reboot your computer. You should see the Hibernate option show up in the Power Options now.

Enjoy!

Mounting NFS Share on Windows 10 & 11 with Write Access

It is easy to mount a drive from Linux NFS share on Windows 10 & 11 machines. To do that make sure you have NFS Client (Services for NFS) is installed from Programs and Features. Following is the command to mount the NFS drive. Note that this command will run on cmd (Command Prompt) and not on PowerShell.

mount \<IP_ADDRESS>\<PATH_TO_DIR>\ drive:

For example, if the IP address of the NFS share is 10.235.0.10 and the directory you want to share is /var/www and you want to mount it to your Z drive, then you can run the following command.

mount \\10.235.0.10\var\www z:

But when you mount the drive you can browse the files using your Windows Explorer but you cannot create new files nor edit any files. To get write access on NFS share you have to make a small change in Windows registry before mounting the drive. Follow these steps.

  1. Open regedit by typing it in the search box end pressing Enter.
  2. Browse to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default.
  3. Create a new New DWORD (32-bit) Value inside the Default folder named AnonymousUid and assign the UID found on the Linux directory as shared by the NFS system. This is the UID of the user that has the write access to that directory on Linux system.
  4. Create a new New DWORD (32-bit) Value inside the Default folder named AnonymousGid and assign the GID found on the Linux directory as shared by the NFS system. This is the GID of the group that has the write access on the directory on Linux system.Windows 10: Regedit NFS AnonymousUid and AnonymousGid
  5. Restart the NFS client or reboot the machine to apply the changes.

Now run the mount command and you will get the write access.

Mark parent category menu active on single custom post view in WordPress

Recently I developed a theme for one of my client and I had to highlight the menu item of parent category in main menu when one of its associated single custom post is viewed. For that I had to add an action in my functions.php file for nav_menu_css_class. What is does is it returns the ‘active’ class which WordPress adds to the parent category menu item in the main menu. You can see the code at Gist here.

Why we moved from OpenShift to Google Cloud

The good old days

When OpenShift was in its version 1 it was great from customer’s point of view with low budget. OpenShift v1 had free offers to deploy app and add a custom domain to it. There was no SSL support but it could be handled via CloudFlare solution, making overall solution a great one.

Then there comes OpenShift v2

RedHat then launched OpenShift v2 and added a restriction that gears will be shutdown after certain period of inactivity and also removed the support for custom domain.

That was the time that we had to move to some other cloud platform that could support our apps with low resources and without investing anything.

Since all good things in life are free.

Google Cloud to the rescue

So we came across Google Cloud platform offering and we had $300 credit in free trial for next 6 months. That was more than enough for us to start with. And in fact they have micro virtual machine instances that are free for life with 30gb storage. That is more than enough for small apps to run for free that are under experiments or don’t have any monetization plans.

So, we migrated several of our apps from OpenShift to Google Cloud and started leveraging free credits provided by Google.

Just this week we consumed all our credit and our trial expired. Our virtual machine instances were shutdown, but it didn’t take long that we enabled billing on our project and downgraded our instances to micro ones which is free. That gave us such a relief that our apps are still running although with low resources but it is fine as that are not our revenue generating apps and are just experiments.

Codenvy and BitBucket Integration

OK, this post is a quick one. Let’s go.

In your Codenvy workspace goto Profile > Preferences > SSH > VCS and generate key and give it a name bitbucket.org. This will generate key for you. Copy this key by viewing it which we will use later on BitBucket.

Now go to BitBucket, select your repository, and then goto repository settings. Under Access Keys menu click Add Key button. Give a label as bitbucket.org and paste the key copied in previous step here and save.

Now on Codenvy project goto Git menu and add remote. You need to give SSH url to your BitBucket repo here. Add it and you can now pull the repo from BitBucket. Awesome!

Displaying Titles in Multiline in WordPress

When title is written it is usually displayed in single line on front-end until it is too long to display in one line. But if you want to write title in multiline and want to line break the title after a certain word how can you do that.

It is pretty simple. Since, we know the fact that when title is displayed it is a heading which is displayed using HTML tag off course. So, taking benefit of HTML we can just insert a HTML line break element <br/> just after the word in our title where we want the line break. Like this:

“This is my title <br/> with my own line break”

multilinetitleinwordpress.png

This will be displayed in two lines when you publish the post.

Different color for each menu item

In a recent project I got a requirement that each menu item should be highlighted in different color when visited. The menu items and their required active colors were:

  • Home – Green
  • Portfolio – Blue
  • Team – Yellow
  • Contact – Red

These colors were to be applied only when that page is being visited otherwise color of menu item should be default black color.

So, if user is visiting home page then menu item should something like this

home_menu.png

And if user is visiting Portfolio page then menu should be something like this

portoflio_menu.png

Considering that this was a WordPress theme project where we were using Understrap as a base theme which is based on Twitter Bootstrap. So, when user visits, for example a home page WordPress will attach a .active CSS class to it. Taking advantage of that we added different classes for each menu item and then used following rule to make menu item colors different:

.navbar-nav > .home.active > a {
    color: green!important;
}
.navbar-nav > .portfolio.active > a {
    color: blue!important;
}
.navbar-nav > .team.active > a {
    color: yellow!important;
}
.navbar-nav > .connect.active > a {
    color: red!important;
}

CSS Class Chaining

We utilized the class chaining method here. If you note that .home.active classes are chained together without space and which means it will select an element with both these classes.
That did the trick and all menu items were in different color.