Monday, January 30, 2012

Adding Recent File List Plugin to VIM

From: http://stackoverflow.com/questions/3171284/recent-file-history-in-vim

MRU (Most Recently Used) Plugin
http://www.vim.org/scripts/script.php?script_id=521

How to add on unix:
On vim enter:
:help add-plugin


Steps:

mkdir ~/.vim
mkdir ~/.vim/plugin
cd 
~/.vim/plugin
wget -O mru.vim http://www.vim.org/scripts/download_script.php?src_id=11919


To Use:
While working on vim, enter the command:

1. :MRU
2. Select a file, press enter, thats it.

ProcessBuilder Runtime Redirecting Output and Exec uting

The following discuss details of the problem:


ProcessBuilder redirecting output


http://stackoverflow.com/questions/5986324/processbuilder-redirecting-output

Shell redirection operators are unknown to ProcessBuilder. Put your command in a shell script and execute it, as shown here. Alternatively, use bash -c, as shown here.



Or prepending "bash -c" to the exec


http://stackoverflow.com/questions/5740390/printing-my-macs-serial-number-in-java-using-unix-commands/5740673#5740673


How to use OutputStream for output redirection


http://stackoverflow.com/questions/3777654/problem-with-runtime


Split a string containing command-line parameters into a String[] in Java


http://stackoverflow.com/questions/3259143/split-a-string-containing-command-line-parameters-into-a-string-in-java
Wonderful answer here:


Here is a pretty easy alternative for splitting a text line from a file into an argument vector so that you can feed it into your options parser:
This is the solution:
public static void main(String[] args) {
    String myArgs = Commandline.translateCommandline("-a hello -b world -c \"Hello world\"");
    for (String arg:myArgs)
        System.out.println(arg);
}

Git User Manual, Looks Very Good

Git, how to diff a file with its previous commits

git diff HEAD 0d82 -- myfile.java

Git, How to revert to a previous commit?

Best on this is:http://stackoverflow.com/questions/4114095/git-revert-to-previous-commit-how

I like this way:

git checkout 0d1d7fc32 .
git commit
Also you can do the following if you have some local modifications:
git stash
git checkout 0d1d7fc32
git stash pop
git commit


Friday, January 27, 2012

Saturday, January 14, 2012

Display files modified in the last 10 minutes on linux

find /var/log -type f -mmin -10

Wonderful command.

Monday, December 12, 2011

How to comment code in VI or VIM


Mark the area which is to be commented using the *blockwise* visual mode (CTRL-V, in Windows this is CTRL-Q).

Press I (capital i) and write the text you want to prepend to each line of the selected block, e.g. #####.

Then press ESC and the text will be inserted to the left of each line of the selected block.

getResouce and Files in java. I just hate having to search for this every time.

To get a file inside a jar, you have to do the following:

URI resourceURI = this.class.getResource("/path/to/file/in/jar/config.txt").toURI();

To open the file using a file you can do:

File theFile = new File(resourceURI);

To read the contents of the file:

List<String> lines = Files.readLines(theFile, Charsets.UTF_8);


To read the files in a directory:



// Load the directory as a resource
URL dir_url = ClassLoader.getSystemResource(dir_path);
// Turn the resource into a File object
File dir = new File(dir_url.toURI());
// List the directory
String files = dir.list()

Monday, October 31, 2011

"Run On Server" not showing up in Eclipse with m2eclipse?

Okay, I went through this problem in Eclipse Indigo for J2EE Developers release that m2eclipse wont show me the Run On Server selection in the Run menu when I import a maven project with war packaging (ie. the maven-archetype-webapp).

Here is how to fix it:
1. Uninstall the current m2eclipse plugin you have in eclipse:
  (a) Go to "Help > Install New Software"
  (b) Click on the "What is already installed?" link
  (c) Select "m2e - Maven Eclipse Integration" and click on the "Uninstall" button
  (d) Restart eclipse when prompted

2. Next, you have to install the m2eclipse:
  (a) Go to "Help > Eclipse Market Place"
  (b) Search for the word m2eclipse
  (c) Select "Maven integration for eclipse"
  (d) Click the "Install" button

3. Install the "Maven Integration for Eclipse WTP"

  (a) Go to "Help > Eclipse Market Place"
  (b) Search for the word m2eclipse
  (c) Select "Maven integration for eclipse WTP
  (d) Click the "Install" button

Restart when prompted.

Now, importing a maven project with war packaging will work out of the box. Enjoy.

Sunday, October 23, 2011

Configuring Eclipse to run with a specific JDK or JRE


1. Open the file eclipse.ini for editing

2. Add the two lines to specify the virtual machine to use (the bolded lines):

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar

-vm 
C:\Program Files\Java\jdk1.6.0_29\bin\javaw.exe

--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502

3. Now start eclipse.

Wednesday, October 19, 2011

Wonderful Iphone Icon Generator Online

Give your divs a simplistic nice shadow with css

I loved the middle box shadow in the shopify.com website, and therefore decided to dig it up. The CSS used for it is:

-moz-box-shadow: 0px 0px 15px rgba(0,0,0,0.1);
-webkit-box-shadow: 0px 0px 15px rgba(0,0,0,0.1);
box-shadow: 0px 0px 15px rgba(0,0,0,0.5);

Monday, October 17, 2011

Using mod_jk with Apache 2.2 How to setup a reverse proxy



Advice on mod_jk versus mod_proxy and mod_proxy_ajp
Do not use mod_proxy and mod_proxy_ajp on Apache 2.2 since they are not stable and have caused me some problems. Use mod_jk instead.

Prerequisites & Assumptions Before you continue
I assume you have:
- You already have Apache Webserver 2.2 installed
- You already have Tomcat installed
- You already have a web application on Tomcat with context "jobsapp"
- You are using Redhat Enterprise or CentOS and therefore have yum on your system.

How to get the mod_jk binary for Apache 2.2 on Linux
You wont find it anywhere, you have to compile it, now stop being lazy and start working.

The following steps detail the process:

// Create a temporary source directory, I use /opt/src
mkdir /opt/src
cd /opt/src 


// Get the source package
wget http://mirrors.isu.net.sa/pub/apache//tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.32-src.tar.gz


// Install packages needed to compile the binary
yum install httpd-devel
yum install gcc-c++


// Extract the tar.gz file
tar -zxvf /opt/src/tomcat-connectors-1.2.32-src.tar.gz


// Configure, make, make install
./configure --with-apxs=/usr/sbin/apxs
make
su -c 'make install'

How to configure Apache Webserver with Mod JK

1. Edit the file httpd.conf
vim /etc/httpd/conf/

2. Add this line to load the module:
...
LoadModule jk_module modules/mod_jk.so
...

3. Add also the following lines:

JkWorkersFile   conf/worker.properties
JkLogFile       /var/log/httpd/mod_jk.log
JkLogLevel      debug
JkRequestLogFormat      "%w %U %T"
JkOptions +ForwardURIEscaped +ForwardURICompatUnparsed

After finishing, change JkLogLevel from debug to "error" or "info" so that the log file doesn't grow too much in size.

4. Now create a file names worker.properties inside /etc/httpd/conf/ and add the following lines to it:
vim /etc/httpd/conf/worker.properties

# Worker Properties file for mod_jk
worker.list=tomcat
worker.tomcat.host=localhost
worker.tomcat.port=8009
worker.tomcat.type=ajp13
worker.tomcat.connection_pool_timeout=300




4.5. Make sure to read the mod_jk attributes in this link:
http://tomcat.apache.org/connectors-doc/reference/workers.html

5. Now open the httpd.conf or your virtual host configuration file and add the following lines:

JkMount     /jobsapp tomcat
JkMount     /jobsapp/* tomcat

6. Also open the ssl httpd conf file which has the following line at the top,
and add the same two lines inside them:

<VirtualHost _default_:443>
...
JkMount     /jobsapp tomcat
JkMount     /jobsapp/* tomcat
...
</VirtualHost>


7. Now restart apache

/etc/init.d/httpd restart

Tuesday, October 11, 2011

Adding deleted files in git

When you type:

git commit -a

Git will add the new, modified and deleted files automatically and commit them

However, there are cases when you want to 'git add' deleted files (that got deleted in your working directory).

I tried:

git add *

But this didn't workout. It only added the modified and created files.

I wanted a way to add the deleted files, I thought of issuing a 'git rm' command:

git rm *

BUT WAIT. THIS WILL DELETE EVERYTHING.

So, what is the solution.

The solution is to use:

git add -u

The -u (show for --update) tells git to compare to the tracked files in git rather than the working directory.

According to the GIT manual:
'git add' man page says about the -u option...
-u
--update
Only match <filepattern> against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.
If no <filepattern> is given, default to "."; in other words, update all tracked files in the current directory and its subdirectories.