git amend scenerios

Sometimes we need to change the commit message of already committed/committed-pushed files. See below some of the scenarios might arise..

Scenerio 1-> Committed but not pushed

$ git commit –amend

This will open an editor with the commit message. If you are using vi editor edit the commit message and save using !wq: Check with $git log if the message has been amended correctly.

Scenerio 2-> Already pushed + most recent commit

It might be the case that if a user has already pushed the changes to git central repository, in this type of scenario we need to first amend the most recent local commit and afterward apply –force push which will forcefully push the changes to the server. In this process, one thing to keep in mind is that if in between any other user who has already synced local copy with the central repository needs to re-pull.

$ git commit –amend
Edit the message in vi and save and exit
$ git push origin <branch_name> –force


Scenerio 3-> Not pushed + old commit

$ git rebase –i HEAD~X

where X is the number of commits to go back then move to the line of your commit, change pick and edit then change your commit message

$ git commit –amend

Finish the rebase with:

$ git rebase –continue

Rebase opened your history and let you pick what to change. With edit, you tell that you want to change the message. Git moves you to a new branch to let you –amend the message. git rebase — continue puts you back in your previous branch with the message changes.

alternatively, you can choose reword instead of edit when rebasing to change the commit directly. Then you can skip the amend and rebase continue. You may check this link from git book for more on this.

Scenerio 4-> Already pushed + old commit
Edit your message with the same 3 steps process as menined in scenerios 2 ( rebase –i, commit –amend, rebase –continue). Then force push the commit

$git push <branch_name> master –force

But! please remember re-pushing your commit after changing it will very likely to prevent others to sync with the repo, if they already pulled a copy. You should first check with them.


References:
https://gist.github.com/nepsilon/156387acf9e1e72d48fa35c4fabef0b4

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History


SpaceVim review

As a Vim user for nearly 2 decades, recently I got an opportunity to explore
SpaceVim a new Vim distribution. Some of the features worth highlighting are:

  • Nicely built edit mode.
  • Loved the idea of collecting related plugins together to provide features.
  • Instant search results using grep, ag, rgackpt and with a great UI.

Will exlore more features in coming days and shall update the post.

Gitbub:https://github.com/SpaceVim/SpaceVim

git quick tip – branching and merging

Sometimes you want to do experiment work or wants to patch the git master branch with some experimental code, in that case, it’s not the good idea to change the local master branch. Below are steps to do the changes in an experimental branch made with master and merge back to master and the pushback server.

Scenario:

    • Create a new branch locally with the existing branch
    • Make changes and commit these changes
    • Merge them with the local branch from where we have made the branch
    • push to the git server.

Example:
# Make a master_dev from master branch
$ git checkout -b master_dev master

# Do changes in master_dev branch
$ git commit -am "Commit message"

# Checkout master branch
$ git checkout master

# Merge the changes of master_dev to master
$ git merge --no-ff master_dev

# Push the changes of master to origin master
$ git push origin master

# Optionally one can push the master_dev branch to remote
# DO ONLY IF YOU WANT MASTER_DEV BRANCH ALSO ON SERVER
$ git push origin master_dev

 

Happy programming!

apache lucy search examples

Investigating search engines and this time apache Lucy 0.4.2. I am showing a basic indexer and a small search application. See below code for indexer (This will take documents one by one and then index them). Search module will take arugument as STDIN and then will show the search result.

This is pure command line utility just to show how basic indexing and searching works using apache lucy.

indexer.pl

#!/usr/local/bin/perl

use strict;
use warnings;
use Lucy::Simple;

#
# Ensure the index directory is both available and empty.
#
my $index = "/ppant/LucyTest/index";
system( "rm", "-rf", $index );
system( "mkdir", "-p", $index );
# Create the helper...a new Lucy::Simple object
my $lucy = Lucy::Simple new( path = $index, language = 'en', );

# Add the first "document". (We are mainly adding meta data of the document)
my %one = ( title ="This is a title of first article" , body ="some text inside the body we need to test the implementaion of lucy", id =1 );
$lucy-add_doc( \%one );

# Add the second "document".
my %two = ( title ="This is another article" , body ="I am putting some basic content, using some words which are also in first document like implementation", id =2 );
$lucy add_doc( \%two );

# Both the documents are now indexed in path

One indexing of the documents is done we'll make a small search script.

search.cgi

#!/usr/local/bin/perl

use strict;
use warnings;

use Lucy::Search::IndexSearcher;

my $term = shift || die "Usage: $0 search-term";

my $searcher = Lucy::Search::IndexSearcher new( index ='/ppant/LucyTest/index');
# A basic search command line which will look for indexed items based on STDIN and will show that in which document query string is found and no of hits
my $hits = $searcher hits( query =$term );
while ( my $hit = $hits next ) {
print "Title: $hit {title} - ID: $hit {id}\n";
}
# End of search.cgi


***********************************************************************

If you want to explore more check Full Code on GitHub

Out of memory Cent OS Linux: unicode_start hang issue: Solved

My Cent OS 5.6 RHEL based virtual machine has suddenly became very slow ..almost died 🙁 after few min I saw a message on console related to “Out of memory“, after doing a bit analysis and search I found that this is a known issue and also reported in redhat bug tracker (obviously got resolved in upstream versions).
Reason: Problem is that setting BASH_ENV=~/.bashrc runs /etc/profile, which sources /etc/profile.d/lang.sh. If TERM=linux, lang.sh runs /bin/unicode_start sending the whole process into an infinite loop.

I found two solutions (as of now)

1. Open vi /etc/sysconfig/i18n this file contains a reference to unicode (UTF-8). We have take out all the references to UTF-8)

Code before:

[code lang=”js”]
LANG="en_US.UTF-8"
SUPPORTED="en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
[/code]

Code after:

[code lang=”js”]
LANG="en_US"
SUPPORTED="en_US:en"
SYSFONT="latarcyrheb-sun16"
[/code]

2. Another solution is to change the shell from “bash” to “sh” in unicode_start script
We need to open the vi /bin/unicode_start and from first line change “#!/bin/bash” to “#!/bin/sh“.

References: https://bugzilla.redhat.com/show_bug.cgi?id=622981

Solving the authentication problem while opening Office documents hosted on Apache in IE8/IE9 on Windows 7

We were facing a problem in IE 8/9 on Windows 7 while accessing  Office 2007/ Office 2010 documents hosted on apache/Cent OS 4.6. After some analysis I found the reason and finally ended in a fix. See below my findings and solution. Hope this helps:

The main issue is with the Microsoft’s way of implementing Webdav protocol for accessing web content through Microsoft Web Client. When we click on a Office document then web client  sends HTTP /1.1 OPTIONS Request header to server to check the WebDav communication (My server doesn’t have WebDav). In response Apache return 200 OK Response header to Web Client which results in prompting the authentication screen by Windows 7.  Well you have option in IE to pass the authentication login automatically but that would be security breach as you will be exposing your machine authentication to internet so I would not prefer that. Best way is to configure Apache to reject these request. This is how i have solved. These changes needs to be done in httpd.conf file in /etc/httpd/conf folder (Cent OS 4.6)

# One way to doing it – Deny access based on request method

[code lang=”js”]
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(OPTIONS|PROPFIND)$ [NC]
RewriteRule ^.*$ – [F,L]
[/code]
# Another way to implementing – Deny acess based on user agent (Vista and Windows 7 used same user agent with different version so this Regx shall work for both
[code lang=”html”]
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Microsoft-WebDAV-MiniRedir
RewriteRule ^.*$ – [F,L]
[/code]
Explanation on Flags:

1. [F] flag causes the server to return a 403 Forbidden status code to the client.

2. Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn’t care whether letters appear as upper-case or lower-case in the matched URI.

3. The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. This corresponds to the last command in Perl.

 Some References:

Microsoft knowledge article on authentication requests from office documents 

Apache mod_rewrite rule documentaion

fiddler tool for debugging HTTP requests

Installing Microsoft TrueType fonts (TTF) on CentOS 4.6 and RHEL 4

Default Linux installation (Cent OS in this case) doesn’t contain true type fonts. The application like open office, PDF generators requires proper fonts to embed into if not it will use the free system fonts which can create a lot of issues like  pdf, not showing content properly etc. It’s always good idea to install ms core fonts Well you can buy more fonts as per your requirement if you want.
To install the ms core fonts follow the below steps (Login as a ROOT):
Install RPM: Change the directory to download folder and run the follwing command:
#rpm -ivh cabextract-0.6-1.i386.rpm

Create RPM: Change the directory to download folder and run the follwing command
#rpmbuild -bb msttcorefonts-1.3-4.spec

(This step will download Microsoft CAB files and extracts the fonts and builds an RPM.  This will use system utilities [wget, rpm-build, chkfontpath, fc-cache, ttmkfdir] and also check that http port 80 opened or not. This process will download the executable for all the font files.
This step will create RPM in /usr/src/redhat/RPMS/noarch/msttcorefonts-1.3-4.noarch.rpm
  • Installing RPM: Change the directory to /usr/src/redhat/RPMS/noarch/ and run the follwing command
# rpm -ivh msttcorefonts-1.3-4.noarch.rpm

  • Restart X server:
/sbin/service xfs restart

Now you can check the newly installed fonts on /usr/X11R6/lib/X11/fonts/TTF
Important Note:  Sometimes you might need to modify the msttcorefonts-1.3-4.spec file  for adding new address of mscorefonts location in sourceforge.net.  If you still face problems downloading font file then you can use my own font RPM [msttcorefonts-1.3-4.noarch.rpm].  You can download and install directly using # rpm -ivh msttcorefonts-1.3-4.noarch.rpm.
Good Luck!

Enjoy new fonts in your Linux machine.