Pages

Sunday, October 13, 2013

Display local date and time on the site using javascript

<div id="clock">&nbsp;</div>
<script type="text/javascript">

function init ( )
{
  timeDisplay = document.createTextNode ( "" );
  document.getElementById("clock").appendChild ( timeDisplay );
}

function updateClock ( )
{
  var currentTime = new Date ( );
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );
  var currentDay = currentTime.getDate ( );
 
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
 
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

var month_name=new Array(12);
month_name[0]="January"
month_name[1]="February"
month_name[2]="March"
month_name[3]="April"
month_name[4]="May"
month_name[5]="June"
month_name[6]="July"
month_name[7]="August"
month_name[8]="September"
month_name[9]="October"
month_name[10]="November"
month_name[11]="December"

  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay+"  "+  month_name[currentTime.getMonth()]+" "+currentDay+","+" " +currentTime.getFullYear();
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
//  document.getElementById("clock").style.fontWeight = 'bold';
}
</script>
<script>
updateClock( );
setInterval('updateClock()', 1000 );
</script>

Thursday, October 10, 2013

Steps to configure MongoDB

Steps to configure MongoDB

Download Mongo
UnZip mongodb-win32-x86_64-2.4.6.zip file in any folder (E:\MongoDB)
Create E:\MongoDB\data\db folder to store database
Open command prompt and run


E:\MongoDB\mongodb\bin\mongod.exe --dbpath E:\MongoDB\data\db\localDB   ==== to set database path

The above command prompt window should remain open so that you can work on database.
Now open another command prompt and run E:\MongoDB\mongodb\bin\mongo   ---- if successfull the below text will appear with a command prompt as ">" here you can execute commands
MongoDB shell version: 2.4.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
       
http://docs.mongodb.org/
Questions? Try the support group
       
http://groups.google.com/group/mongodb-user
>Execute your commands here

Download Mongo Interface (Robomongo) http://robomongo.org/ This is a UI tool to execute queries

Folder Structure
All local database localtion E:\MongoDB\data\db\localDB
Backup Folder
E:\MongoDB\dump\localDB\mydb
E:\MongoDB\dump\staging\mongodump-2013-10-10\dbName


BACKUP
mongodump -d <our database name> -o <directory_backup>


Take backup of local database without running the mongod instance
Run on command prompt
E:\MongoDB\mongodb\bin\mongodump --dbpath E:\MongoDB\data\db\localDB -o E:\MongoDB\dump\localDB


Take backup of remote database without running the mongod instance
E:\MongoDB\mongodb\bin\mongodump --host <servername> --port 27017 --username <username> --password <password> -db <dbname> --out E:\MongoDB\dump\staging\mongodump-2013-10-10

RESTORE - From local existing DB
mongorestore <directory_backup>

The mongorestore utility restores a binary backup created by mongodump. By default, mongorestore looks for a database backup in the dump/ directory

Connect to the the mongod instance for local restore
Local
E:\MongoDB\mongodb\bin\mongod.exe --dbpath E:\MongoDB\data\db\localDB   === Instance connection to the database

E:\MongoDB\mongodb\bin\mongorestore E:\MongoDB\dump\localDB  === Run this to restore from backup directory
--Staging
E:\MongoDB\mongodb\bin\mongod.exe --dbpath E:\MongoDB\data\db\localDB   === Instance connection to the database

E:\MongoDB\mongodb\bin\mongorestore E:\MongoDB\dump\staging\mongodump-2013-10-10\dbName === === Run this to restore from backup directory


 

Monday, October 7, 2013

Proper Case or Title case in c#

string[] values = { "a tale of two cities", "gROWL to the rescue",
                          "inside the US government", "sports and MLB baseball",
                          "The Return of Sherlock Holmes", "UNICEF and children"};

      TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
      foreach (var value in values)
         Console.WriteLine("{0} --> {1}", value, ti.ToTitleCase(value));


// The example displays the following output:
// a tale of two cities --> A Tale Of Two Cities
// gROWL to the rescue --> Growl To The Rescue
// inside the US government --> Inside The US Government
// sports and MLB baseball --> Sports And MLB Baseball
// The Return of Sherlock Holmes --> The Return Of Sherlock Holmes
// UNICEF and children --> UNICEF And Children