There are situations where you just committed a change in git and just after that realized you made a mistake in the last commit. If you haven’t pushed that code then the last local changes can be undone with the following command.
git reset --soft HEAD~1
What this does is that it uncommits the last change and puts that back in a staged state. That means if you run the git status command then you will see those changes in your working directory. Now you can make further changes to that revision and then commit again.
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.
What is your opinion? Please, let me know in the comments.
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>
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.
Open regedit by typing it in the search box end pressing Enter.
Browse to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default.
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.
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.
Restart the NFS client or reboot the machine to apply the changes.
Now run the mount command and you will get the write access.
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.
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.
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!
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”
This will be displayed in two lines when you publish the post.