Sakibul Hasan

Dont be a Pithagorian, be for others

Free tomcat 8080 port in windows 8

  1. Open command prompt in admin mode
  2. netstat -ano | findstr 8080. Rightmost column is PID.
  3. From Task Manager tab find the process with that PID, right click and end task.

MongoDB Handy Queries

  1. Create a new collection from Distinct values
    DBQuery.shellBatchSize = 5000
    db.cities.aggregate(
     [
     {
     $group : {
     _id : { city: "$city", province: "$province" },
     id : {$first: "$id"},
     city : {$first: "$city"},
     province : {$first: "$province"}
     }
     },
     { 
     $project : {
     _id : 0 ,
     id : 1,
     city : 1 ,
     province : 1
     }
     }
     ]
    ).forEach(function(doc){
     db.cities_new.insert(doc);
    });
  2. Delete field from collection
    db.cities.update({}, {$unset: {postal_code:1}}, false, true);
  3. Rename Field

    db.cities.updateMany( {}, { $rename: { “province”: “stateCode” } } )

 

Run Jboss 7.1.1 on background on Ubuntu 12.04

Lately I install jboss 7.1.1 on my VPS server (Digital Ocean) in a Ubuntu 12.04 box. Initially I tried to run the following command to run the server on background.

./standalone.sh -b 0.0.0.0 &

But when I close my remote connection, it happened to stop my server. Thats why I came up with the following script to run my Jboss 7.1.1 server on background

#!/bin/sh
# # Shell script to start and stop integrated JBoss/Jett
# change this according to your own situation

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
export JBOSS_HOME=/root/jboss-as-7.1.1.Final

if [ “$1” = “start” ] ; then
export LAUNCH_JBOSS_IN_BACKGROUND=1
$JBOSS_HOME/bin/standalone.sh -b 0.0.0.0 &
echo $! > $JBOSS_HOME/bin/jboss.pid
elif [ “$1” = “stop” ] ; then
# This will kill the standalone.sh process AND the JBoss AS java process.
kill `cat $JBOSS_HOME/bin/jboss.pid`
rm $JBOSS_HOME/bin/jboss.pid -f
else
echo “Usage:”
echo “jboss (start|stop)”
echo ” start – start jboss in the background”
echo ” stop – stop jboss”
exit 0
fi

jboss 7.1.1 deploy appliction as domain mode

Edit your file jboss-as-7.1.1.Final/standalone/configuration/standalone.xml

change this value

from

<virtual-server name=”default-host” enable-welcome-root=”true”>

to

 <virtual-server name=”default-host” enable-welcome-root=”false” default-web-module=”your-web-app”>

Always run tomcat in debug mode

open startup.sh file in bin folder

1. add following lines at the beginning of other uncommented line

export JPDA_ADDRESS=8000

export JPDA_TRANSPORT=dt_socket

2. add jpda in exec line

exec “$PRGDIR”/”$EXECUTABLE” jpda start “$@”

3. from command line run ./startup.sh

CSS for Pretty HTML form

The default look and feel of HTML form is not that great. Thats why I applied some CSS to prettify the look and feel of HTML forms. Here is the css code:

input[type=”text”], textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
resize: none;
margin-bottom: 10px;

padding: 5px;
border: 1px solid #CDCDCD;

-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;

-webkit-box-shadow: inset 0 0 5px #CDCDCD;
-moz-box-shadow: inset 0 0 5px #CDCDCD;
-ms-box-shadow: inset 0 0 5px #CDCDCD;
box-shadow: inset 0 0 5px #CDCDCD;
}

input[type=”text”] {
width: 400px;
}

textarea {
width: 500px;
height: 100px;
}

input[type=”submit”] {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=’#ededed’, endColorstr=’#dfdfdf’);
background-color:#ededed;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:arial;
font-size:12px;
font-weight:bold;
padding:5px 10px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
}
input[type=”submit”]:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=’#dfdfdf’, endColorstr=’#ededed’);
background-color:#dfdfdf;
}
input[type=”submit”]:active {
position:relative;
top:1px;
}
.activeField {
background-image: none;
background-color: #ffffff;
border: solid 1px #33677F;
}

.idle {
border: solid 1px #85b1de;
background-position: top;
}

Colorful Git

After installing Git on you machine just type the following command to get colorful Git output

git config –global color.ui true

Microsoft SQL Server handy commands

  1. Delete all the tables of a database
  • Open a query window under the database whose tables you wanna delete
  • Run:  EXEC sp_MSforeachtable @command1 = “DROP TABLE ?”
  • All the tables may not the deleted because of some foreign key constraints, thats why you need to run it several times to delete all of them.

Setup Tapestry 5 in Mac OS X

1. Install Java JDK (in OSX Lion you have to install Java), Maven (it should installed by default) and Eclipse (I use MyEclipse)

2. Create tapestry skeleton:

  • mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org
  • decide the following things:

3. For testing whether the skeleton works or not, go the the root directory and do followings:

  • run “mvn jetty:run”
  • check http://localhost:8080/%5Bartifact id]
    1. Choose archetype: 1 (Tapestry 5 Quickstart Project)
    2. Choose version: 5.2.6 (this was the stable version while writing this article)
    3. Define value for property ‘groupId’: com.tapestry.security (define as your wish)
    4. Define value for property ‘artifactId’: tapestry-security (define as your wish)
    5. Define value for property ‘version’: 0.0.1-SNAPSHOT (define as your wish)
    6. Define value for property ‘package’: com.tapestry.security

4. Load project into eclipse:

  • run “mvn eclipse:eclipse” in terminal from the root position of the newly created project (If you are using MyEclipse then mvn eclipse:myeclipse)
  • Open Eclipse and create new Java Project (File > New > Java Project)
  • Choose project name as the same of the artifactId (for my case it was “tapestry-security”)
  • Right click on project and MyEclipse Maven > Enable Dependency Management (This option is specific to MyEclipse, you should install m2Eclipse plugin to get the option in your Eclipse IDE)
  • Maven / Maven4MyEclipse > Update Project Configuration

5. Add Jetty:run in run configuration

  • open run configuration
  • add new Maven build
  • Name: as-your-wish
  • Base directory: ${workspace_loc:/artifact id}
  • Goal: jetty:run
  • run it to test

Install network printer (windows printer via samba) in Mac

If you want to install windows printers via samba which are in network in your macbook, then follow the instructions:

  • Go to this link http://127.0.0.1:631
  • Click add printer.
  • You will be prompted to put username and password. Put your Mac’s username and pasword.
  • Then on next page you will get a list of options, from where choose “Windows printer via Samba”.
  • write your samba url (i.e. smb://[workgroup/]server[:port]/printer).
  • Make sure to select the correct printer and model from the next appeared list.