05 January 2018

Recursively delete files in Windows



Recursively delete files in a folder with long file names:

robocopy /MIR D:\temp\empty D:\folder\with\long\names

robocopy will recursively copy files. But with /MIR switch, there is an attempt to mirror source folder to destination folder.

If destination folder is having files with long file names and is getting difficult to delete, you can force it to mirror an empty folder which will recursively delete it in an attempt to mirror an empty folder.

Neat trick.

Source : http://clintboessen.blogspot.com.au/2014/05/how-to-delete-files-which-exceed-255.html 

20 May 2016

Example apps for Tomcat and JBoss


I would personally encourage you to try tomEE+ and they have examples for you to try out as well. 

You can also see tomcat supported versions and tomEE supported versions for the JEE environment.

If you are thinking JBoss Wildfly, take a look at the Ticket Monster example app by JBoss.

08 February 2016

Git Branching and Merging

New Branch
-----------
To create a new branch
$ git checkout -b BRANCH-NAME

This is same as
$ git branch BRANCH-NAME
$ git checkout BRANCH-NAME


 

New Tag
-------
Create a new tag. This will create one locally
$ git tag -a TAG-NAME -m "commit message"

Push the new created tag to remote
$ git push --follow-tags

To view git tag message
$ git tag --list


Merge Branches

-------------- 
Note: When merging, it's the local copies that get merged. So make sure you have the latest copies locally for both branches.
To merge your branch to master
Switched to branch 'master'
$ git checkout master

$ git pull

Assuming you have the latest in your branch.
$ git merge BRANCH-NAME



If there are any merge conflicts, then you have to resolve them first before you push the merge. So after resolving any conflicts, just push the merge

$ git commit origin master
$ git push origin master

14 August 2014

Working with multiple jdk's on your local

I installed multiple jdk's on my local today. Played around a bit and figured out this is how I can easily switch between them!

> java -version:1.7 -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b19)

Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)


> java -version:1.8 -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)


If I want to use specific java version to run my eclipse, I will have to set the "-vm" variable in the eclipse.ini file like so:


-vm
C:\Program Files\Java\jdk1.8.0_11\bin\javaw.exe

Reference: 
1. multipe java on stackoverflow 
2. Eclipse - Specifying the JVM

03 July 2014

Eclipse keyboard shortcuts

Introduction to the dark art of Eclipse magic.

Ctr+Shift+L = Display all keyboard shortcuts

Ctr+M = maximises the current view
F4 = display type hierarchy

Ctr+Q = Take you back to your last edit
Alt+LEFT, Alt+RIGHT = navigate backwards and forwards on your last file views.
F3 or Ctr+CLICK = Take me to it's definition
Ctr+L = Jump to a specified line number
Ctr+E = Browse through a list of all the files that is opened in editor.

Ctr+F = Find/Search
Ctr+J = find as you type - incremental search
Ctr+Shift+R = Open a resource

Ctr+I = Indent code
Ctr+D = delete current line

Ctr+Shift+O = Organize imports
Alt+Shift+R = refactor - rename variable/method name.
Alt+Shift+S+R = refactor - generate getters and setters
Alt+Shift+M = refactor out a method

Play with these shortcuts. As you work on your IDE, there are frequent things you keep doing. Look for a keyboard shortcut for it. If you can't find it, then you search for it and create your own in the Preferences window. 
You can open it by Ctr+Shift+L and again Ctr+Shift+L. 

Something I made up
Ctr+Shift+F = File search

Happy typing.

Reference - http://web.stanford.edu/class/cs108/handouts132/10EclipseGuide.pdf

05 February 2014

Git




Git is very different compared to other SCMs. When ever you commit, git creates another image of your project and saves the difference. So when you switch between two different branches, you are switching between two images of your project folder.

If you are on Windows, use Git Bash. Tortoise Git is usually not recommended.

To start, select the folder where you want to manage your code.

Then initialise the folder like so:
$ git init

Check with help to see the available options for git-add
$ git add --help

You can do a trial run to see what will get added before you actually execute it
$ git add -na   #This shows what happens if you do - git add -a

Adding specific file/files
$ git add */foo-bar.txt

Adding all files in a specific folder
$ git add */foo/*

Adding modified or deleted tracked files. New files not included.
$ git add -u

Add everything. Add files that are modified, add new files, remove deleted files
$ git add -A

Remove any file

$ git rm file.java

 Lets say you added some code, and you want to start committing code.
$ git add *
$ git commit -m 'comments to your commit'




You want to push these to a remote server and start collaborating
$ git remote add origin https://server.com/foo-bar/project-name.git 

# Creates a remote named "origin" pointing at your remote repository
$ git push origin master 

# Pushes code to HEAD or master or trunk or main 'thing'


You want to get an existing project from the remote server
$ git clone https://server.com/foo-bar/project-name.git

To get the latest code
$ git pull
You changed something and now you want to discard your changes without committing.
$ git checkout -- finename



Instead of totally discarding your changes, you want to save/stash them, for just in case moments
$ git stash save --keep-index



Show me all the branches
$ git fetch
#this updates branch information from remote server

$ git branch --all
#this shows all the branches


You want to know what's up with your project folder
$ git status


You want to change to another branch, commit all local changes and do this:
$ git checkout --track origin/branch_name


If you want some graphical output of the git tree
$ git log --graph --oneline

Display list of files in the commit
$ git log --name-only


To create a new branch
$ git checkout -b new-branch-name

This is same as
$ git branch new-branch-name
$ git checkout new-branch-name

Create a new tag. This will create one locally
$ git tag -a v8.0 -m "commit message"

Push the new created tag to remote
$ git push --follow-tags

  This should get you started.

Happy gitting!

26 September 2013

Bash in 5 minutes


Every time you login, /etc/profile script is run first to initialize.
Then these files are run
    .profile
    .bash_login
    .bash_profile
these files are best to configure PATH variables.

when you logout, .bash_logout script is run.

#refers to home - /home/indu/
~/

#refers to current folder
./

#command to check the PATH variables
echo $PATH

#changing permissions

#chmod refer - http://ss64.com/bash/chmod.html
 
# change to rwxr-xr-x
chmod 755 file-or-folder

# all(a) get added(+) permissions rw to file
chmod a+rw file-or-folder

# others(o) get removed(-) permissions rw to file
chmod o-rw file-or-folder

# owner(u) get added(+) permissions x to file
chmod u+x file-or-folder

# change ownership
sudo chown username:group file-or-folder

#! - specifies a shell
#!/bin/bash

# Ubuntu version
lsb_release -r

--------------------------------------------------------
bash commands
--------------------------------------------------------
ps            //lists what shell prompt you are using
cd           //goes to home
cd ~/folder-at-home       //this ~/ refers to home location

pwd        //shows which directory you are working in

mv f1 f2        //moves file f1 to file f2 - can be used to rename file
cp f1 f2        //copies file f1 to file f2.  If f2 exists, then it is overwritten without warning
cp -i f1 f2        //asks before copying and overwriting f2

ls            //lists files in a directory

ls -lt        // order the list by creation date
ls -ltr       // order the list by creation date in reverse order
ls -l            //lists files in more detail
ls -a            //lists hidden files that start with '.'
ls -F        //lets you identify directories with a slash

cat text-file-name    //outputs contents of the file to the terminal
cat file1 file2     //outputs contents of file1 and then prints out file2

tail -f file-name   //outputs the logs that are getting generated, live

less text-file-name    //outputs contents page wise - use :q to quit to terminal
more text-file-name    //outputs contents page wise and quits to terminal just like cat

rm            //removes file
rm -r            //removes a directory along with the files in it
rm -i            //asks before deleting a file
hostname        //displays the name of the system you are working on



//searches recursively in /directory/ for 
//file or folder named item
$find /directory/ -name item -print 
 

//searches and prints all lines that contain string in filename
grep 'string' filename   
 

// searches for specified text in 
// all files in the current directory
grep -lir "some text" *
grep -lir "some text" /this/folder/location  // searches for specified text in the specified directory location
    -l - files that match
    -i - ignore case
    -r - read all files under each directory recursively
head filename        //displays first 10 lines of text in file
head -3 filename    //displays first 3 lines of text in file
tail filename        //displays last 10 lines of text in file
tail -6 filename    //displays last 6 lines of text in file
sort            //displays contents of file with lines sorted according to alphabetical order

:q            //quits the man page and goes to terminal

 |            //pipe - output of one process will become the input to another process
echo            //send messages from scipts to screen, and more
whereis    java        //lets you know where all java executable is installed
which java        //locates utility copy that you are going to use

bzip2 file.txt        //binary-sorting file compressor
bunzup2 file.txt.bz2    //uncompress

gzip file.txt        //GNU zip compressor
gunzip file.txt.gz    //GNU uncompressor

#tar             //tape archive
tar -czvf allmyfiles.tar.gz *    //gunzips all the files in the current folder

tar -czvf folder.tar.gz foldername/      //gunzips a folder
tar -zxvf allmyfiles.tar.gz    //this will extract the zip file in the current folder
tar -ztvf file.tar.gz         //list files that is zipped in this tar file

clear            //clears the screen
fg            //brings the background process to foreground


#redirecting standard output
command options > destination_file    //output of command will be put in destination_file, by erasing the previous contents.
command options >> destination_file    //output of command added to the end of destination_file.

#redirecting standard input
command options < filename    //command's input to come from file with the provided options

#pipes
command options | command options     // output of one command is input to another command
#same as
command options > tempfile
command options < tempfile

jobs            //lists the current running jobs with process ids
kill %process_id    //kills the process with the process

diff --brief --recursive folder1 folder2 > difference.txt  // gets the difference between two folders

--------------------------------------------------------
chmod - chaning file permissions
--------------------------------------------------------
File permissions read(r), write(w) and execute(x) have numbers.
r = 4
w = 2
x = 1

0 - ---
1 - --x
2 - -w-
3 - -wx
4 - r--
5 - r-x
6 - rw-
7 - rwx

chmod 644 filename // user = -rw-, usergroup = -r--, all = -r--
chmod 777 filename // user = -rwx, usergroup = -rwx, all = -rwx

--------------------------------------------------------
short-cut keys
--------------------------------------------------------
ctrl+U        //clears your typed matter at the terminal
ctrl+Z        //kills the current running program
\q        //escapes current view
Ctrl+D        //quit or exit
 

31 August 2010

Logo design at Logosnap

I recently came across this amazingly simple and yet powerful site to design your own logos.  Its called Logosnap.com and is owned by logodesignguru.com.  I know how cash strapped we are when we are a recent start up.  This site is ideal to come up with your own design.  You also get to credit yourself to all your friends and family and share that you did it yourself.  Its a feeling unmatched.  Do visit them and give it a try.  You may begin to love your own work, thanks to Logosnap.com

27 August 2010

Setting and Reading Cookies in python Django

I recently tried to figure out how to set and get cookie values.  I knew how to do sessions, but I wanted to have my own custom cookie.  I was looking for a key-value pairs I could let it be stored on user's browser instead of on the database which is the case with sessions.

Here's how to set a cookie.

response.set_cookie(key="mykey", value="myvalue")

Here's how to read the cookie.


if "mykey" in request.COOKIES:
     read_value = request.COOKIES["mykey"]


That's it.  Have fun with cookies.

Reference : http://docs.djangoproject.com/en/dev/ref/request-response/

03 June 2010

Python Best Practices

Here are two interesting articles that will shed some light on the Python Best Practices

http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

http://blog.apps.chicagotribune.com/2010/02/26/best-practices/

http://www.python.org/dev/peps/pep-0008/

Let me see if I can summarize it in the future post.

.

07 July 2009

Django using Eclipse with pydev extension

This article helps you configure eclipse so that you do web app development using django framework. Eclipse can be used for python programming using pydev plugin. The same plugin will be used for working with django framework also.

I assume you already have pydev plug-in for your eclipse. If not you can download it here. I assume that you have already installed django. If not you can download it here. Django installation instructions are here.
  1. Create your django project folder using the command line method as illustrated in the django tutorial. I assume you have used the project name as "mysite". For reference, I will consider it as located at "documents/mysite".
  2. In eclipse go to windows>preferences and then select Pydev>Interpreter-Python. Select the python interpreter (python dot exe). In the System PYTHONPATH section, please select the django folder you installed. Click Apply. Then click OK.
  3. Create a pydev project called "mysite" with src folder. For reference I will assume the project folder will be at "eclipse_workspace/mysite".
  4. Copy the entire "mysite" folder from "documents/mysite" and paste it into "eclipse_workspace/mysite/src" folder. Refresh your view in eclipse. You should now be able to see mysite package and polls package in the eclipse package explorer.
  5. Lets set up some run configurations. Go to Run>Run Configurations... In the Run Configuration window, select Python Run on the left. Right click and select New. Name it as "manage_config". Select the project as "mysite" and Main Module as "manage.py". In "arguments" tab, add "runserver --noreload" in Program Arguments section. In "environments" tab, add variable DJANGO_SETTINGS_MODULE with value mysite.settings. You can add new variables by clicking on "New..." button. Now you can run the manage.py module, and this will start the django inbuilt development server. If you want to debug the app, run the manage.py module in debug mode. Just right click on manage.py and then select debug>debug configurations and select manage_config. Click on debug. Or right click on manage.py select debug as> python run, if you have only one run configuration defined for manage.py

  6. Create a package called "test" and a module called "test". Use this module to play with your Django API. Lets set up some run configurations for test module. Go to Run>Run Configurations... In the Run Configuration window, select Python Run on the left. Right click and select New. Name it as "test_config". Select the project as "mysite" and Main Module as "test.py".

    In "environments" tab, add variable DJANGO_SETTINGS_MODULE with value mysite.settings. You can add new variables by clicking on "New..." button. Now you can run the manage.py module, and this will start the django inbuild dev .

    Now you can run or debug the test.py module and play with the Django API to your hearts fill.

    Please feel free to test drive and let me know if you run into issues. This set up is pretty much independent of version numbers. If you have any specific problem with any specific version combination, please leave a comment.

23 June 2009

Unable to update Avira Antivir

Since couple of days, I found my Avira Antivir Personal edition (free) not updating properly, or taking for ever to do an update. I thought something might be wrong with my program or worse, my computer might be affected. After searching the web, I found that sometimes when the update files are big and if the update server get over burdened, you will not be able to automatically update.

Solution: Do a manual update. To do that, download the latest virus definition file (VDF) from Avira VDF update. After the file is downloaded, use your Avira Antivir program to do a manual update by clicking "Update" > "Manual Update".

Let me know if this works for you.

16 June 2009

Paul Graham - Great Hack

Here is an article from Paul Graham. This is a gem of an article. Great Hackers by Paul Graham.

29 May 2009

Python is faster than Java!

I wanted to pitch Java and Python against each other and see how they perform. So I put in a simple program that puts some stress on the system. Data Structures would also be used. Both the programs should be run on same machine. There shouldn't be any other Java or Python process running in background. I wrote a simple program in both Java and Python and ran them.

Java Program (JVM version - 1.6.0_11-b03)

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;


public class PerformanceTester {

private final static int SIZE = 500000;

public static void main(String[] args) {

long start_time = System.currentTimeMillis();

Hashtable build_hash = new Hashtable();
for(int i=0; i build_array = new ArrayList();
for(Iterator it = build_hash.keySet().iterator(); it.hasNext();){
Integer value = build_hash.get(it.next());
it.remove();
String strValue = (value.intValue()+8)+"add more";
build_array.add(strValue);
}

long stop_time = System.currentTimeMillis();
System.out.println("Total Time = "+((stop_time - start_time)/1000.0000));

}

}


Multiple Run Result
Total time = 1.391
Total time = 1.375
Total time = 1.344
Total time = 1.422
Total time = 1.484


Python Program (CPython version 2.6.1)

import time

start_time = time.clock()
SIZE = 500000

build_hash = {}

for a in range(1,SIZE):
build_hash[str(a)] = a

build_array = []

for key in build_hash:
build_array.append(str(build_hash[key]+8) + "add more")
build_hash[key] = None

stop_time = time.clock()
print "total time = ", (stop_time - start_time)


Multiple Run Result

Total time = 0.888883333612
Total time = 0.878249380963
Total time = 0.991458537034
Total time = 0.850523498354
Total time = 0.860505161151

I see Python showing a huge advantage when it comes to speed of execution. Java is slow! Thats bad news for Java. I would like you to try same or similar program and let me know how it performs. If you run the same above programs, try increasing the hash size for both the programs. You will be surprised with what you see! I can't believe Java is not only slow, but also uses more memory. Python is not only simpler, but faster, more powerful and uses lesser memory than Java.

28 May 2009

Java is loosing the grip while Python and Ruby gaining ground


We have come accross many instances that Java/J2EE is trying to get rid of its complexities, yet not very successful at it. First the misfortunes EJB 2, and then the obliteration of XML files in a large application. Finally the tedious and daunting task of putting all the types of frameworks and to make them work together for every new application. There has been a huge improvement in EJB 3, but
architects and managers still dread the name EJB.

The management hates it when we tell them that we are throwing away code. They panic, as if we are throwing away used furniture. Why throw it, can't we re-use them somewhere! This statement looks very logical from the management perspective, but when it comes to we super technologists, it sounds ridiculous. For us, old code is like old milk. You refactor it and continually improve it or just throw the freaking thing away. Old code has a shelf life, just like milk. We are involved in developing and maintaining code, we know how bad it stinks. The smell is a good indicator that the application is deteriorating in quality and increasing in quantity.

If you are worried about your job prospects, Java/JEE is still a hot bed as of May 2009. The ecosystem is complex enough that you need people who are bright enough to make sense from it. Many companies still stick to Java as their primary web technology, but things might be changing soon.


Sun is now acquired by Oracle and I do not know what future holds for new Java apps. Oracle is big and they will push the Java technology to upper management in many large corporations. These companies have lot of money to invest and they are always more comfortable when they know that they are in company with large corporation such as Oracle. If you are very enthusiastic about web application development, and are willing to take some risks in the job market, you should try Rails or Django. Job prospects are improving for both, so you might not be in loss. But you will enjoy your work much better because I see either Ruby or Python to be much better programming languages than what Java is or going to become. After being with Java for this long, I see that Java has this inferiority complex with C# and does a catch up. I am in big favor of open source and you might know how I might feel about C#.

Ruby on Rails or Python with Django provide very powerful combination for web development. Job demands will come, but will come as the industry adoption grows. Both Python and Ruby are mature and have good community of users. The new features in the languages come from key persons. Just like Linus Torvalds drives Linux kernel development, Yukihiro Matsumoto will drive Ruby language development and Guido van Rossum will drive Python language development. I feel this is much better than a language being driven through a community similar to JCP.

21 March 2009

Ruby on Rails IDE for beginners

I have been a Java programmer for a long time and a big fan of eclipse. Lately I have been very interested to try out Ruby on Rails and Python with Django. I am not the guy who wants to program using text editors. I found that we have these following choices. I have listed here some IDEs and simple test editors which can turn into powerful programming environments for you as a new RoR explorer.

Programming environments listed in Alphabetical order
Note: If you are already using a tool for Ruby on Rails development, please leave a comment and let us know about it.

Eclipse based RadRails - If you are coming from Java shop and are already heavily into eclipse as your IDE, then you might want to check this out. It installs on Linux, Mac OSX and Windows. Because eclipse is java based, you will need jvm installed before you install RadRails with eclipse. RadRails can also be installed with Aptana Studio, an IDE bundle by RadRails creators.

JEdit - JEdit is a powerful programming tool for those who are good with using just a text editor for their coding requirements. Here are couple of good guidlines from Eric and Eadz for working with JEdit for RoR.

Komodo - This is an excellent IDE from ActiveState developers for scripting languages. You can program in Python, Perl, PHP, Ruby, and even HTML, CSS and javascript using Komodo. If you are also programming in other mentioned languages, then this IDE would be worth a look.

NetBeans- This is a java based IDE which has a good support for RoR. Comes bundled with Glassfish V3 Prelude. They provide RoR learning trails that can help you if you are a beginner.

TextMate - For all Mac enthusiasts, this is the editor of choice for RoR. This is pretty powerful and highly customizable. You defenitely want to check this out if you are on a Mac. If you use windows, there is a similar editor called eTextEditor, which is equally powerful.

20 March 2009

Ruby, JRuby, Rails, Python, Django, J2EE

As an experienced Java/J2EE developer for more than 4 years, and after successfully leading Java projects, we are missing something. It takes too much time to even just set up a rough draft of what we want. Even to provide a small demo for the client, we had to set up the whole mixture of frameworks, make sure the jar files don't conflict with new versions, and tedious manipulations trying to figure out how each framework will talk to each other... and so on. What a pain. Programming should be better than this. Web programming has so much capabilities and yet getting simple things in and out shouldn't be such a trouble. Python with Django and Ruby with Rails are beginning to solve most of these problems.

There are talks for Sun being acquired by IBM. Bad news for Java. I don't see much innovation happening due to Java Community Process. The web and open source shall remain the first and last place for free spirited innovation. If you are someone like me who wants to explore and find solutions where Java is failing, then you should definitely give Python or Ruby a try. There is no harm in learning a new language. Infact it will flex your cranium further, and you will be a better programmer, whether you program in Python, Ruby or Java.

30 July 2008

Favorite Proverbs and Quotations

These are the ones I like the most.
  • Action speaks louder than words. - Proverb
  • Patience, humility and caution builds great characters.
  • Excellence is an art won by training and habituation. We do not act rightly because we have virtue or excellence, but we rather have those because we have acted rightly. We are what we repeatedly do. Excellence, then, is not an act but a habit. - Aristotle
  • Silence is a fence around wisdom. - Hebrew Proverb
  • Silence is the best way to answer stupidity. Only a fool has his answer at the tip of his tongue. - Arabic Proverb
  • Empty vessels make more noise. - English Proverb
  • Above all, try something - FDR

18 April 2008

Python and Django

Python and Django, a similar combination to Ruby on Rails, is another scripting combination for the web for speedier delivery schedules. Adrian's Django presentation gives more information on the history and the present trends with Django. There has been a lot of hype surrounding Ruby on Rails. But that will involve learning a whole new language, Ruby. When it comes to Python, you can safely bet on Django. Generating PDF's were my biggest concern in my previous project. I was overwhelmed to see that there is ample support for outputting PDF's. Here's the documentation for this! :)