Powershell: Count of lines, words, characters in files

July 18, 2013 Leave a comment

Example #1: count of lines in all files with extension .cs in current directory and under it
get-childitem . -include *.cs -recurse | get-content | measure-object -line -word -character

Lines Words Characters
----- ----- ----------
689 1721 23884

Example #2: count of lines in all files with extension .cs and *.js in current directory and under it
get-childitem . -include *.cs,*.js -recurse | get-content | measure-object -line -word -character

Lines Words Characters
----- ----- ----------
64994 284349 2605190

NOTE that the performance isn't good in very large projects

Categories: .net

Common CSS Reset and Basic Styles

July 16, 2013 Leave a comment

All the most common CSS Reset style in one place to copy/paste.


html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
 margin: 0;
 padding: 0;
 border: 0;
 font-size: 100%;
 font: inherit;
 vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
 display: block;
}
body {
 line-height: 1;
}
ol, ul {
 list-style: none;
}
blockquote, q {
 quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
 content: '';
 content: none;
}
table {
 border-collapse: collapse;
 border-spacing: 0;
}

.fl{float:left;} .fr{float:right;}
.italic{font-style:italic;}

/*Margins*/
.mar5{margin:5px;}
.mar10{margin:10px;}
.mar15{margin:15px;}
.mar20{margin:20px;}

.mart5{margin-top:5px;}
.mart10{margin-top:10px;}
.mart15{margin-top:15px;}
.mart20{margin-top:20px;}

.marr5{margin-right:5px;}
.marr10{margin-right:10px;}
.marr15{margin-right:15px;}
.marr20{margin-right:20px;}

.marb5{margin-bottom:5px;}
.marb10{margin-bottom:10px;}
.marb15{margin-bottom:15px;}
.marb20{margin-bottom:20px;}

.marl5{margin-left:5px;}
.marl10{margin-left:10px;}
.marl15{margin-left:15px;}
.marl20{margin-left:20px;}

/*Padding*/
.padt5 {padding-top:5px;}
.padt10 {padding-top:10px;}
.padt15 {padding-top:15px;}
.padt20 {padding-top:20px;}

.padr5 {padding-right:5px;}
.padr10 {padding-right:10px;}
.padr15 {padding-right:15px;}
.padr20 {padding-right:20px;}

.padb5 {padding-bottom:5px;}
.padb10 {padding-bottom:10px;}
.padb15 {padding-bottom:15px;}
.padb20 {padding-bottom:20px;}

.padl5 {padding-left:5px;}
.padl10 {padding-left:10px;}
.padl15 {padding-left:15px;}
.padl20 {padding-left:20px;}

/*Use this on conatiner div's which have floated div */
/*Clear fix*/
.clearfix:before,
.clearfix:after {
 content: " ";
 display: table;
}

.clearfix:after {
 clear: both;
}

/* IE6/7 support */
.clearfix {
 *zoom: 1;
}
.hide {display: none;}
.show {display: block;}

/* To Break long urls or words */
.break {-ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto;}

 

Categories: CSS, HTML Tags: ,

How to check jQuery version

July 9, 2013 1 comment

Some time we needed to check the version of jQuery used in the application. this can be done with the following code

 


// Returns string Ex: "1.5.1"
$().jquery;

// Also returns string Ex: "1.5.1"
jQuery.fn.jquery;

 

 

Categories: Javascript, jQuery

Clone Arrays with JavaScript

June 3, 2013 Leave a comment

1. Splice copy

To clone the contents of a given array, all you need to do is call slice, providing 0 as the first argument:
var clone = myArray.slice(0);

The code above creates clone of the original array; keep in mind that if objects exist in your array, the references are kept; i.e. the code above does not do a “deep” clone of the array contents. To add 
clone as a native method to arrays, you’d do something like this:

Array.prototype.clone = function() {
return this.slice(0);
};

2. loop fixed size

var copy = new Array(data.length);
for (var j = 0; j < data.length; j++) {
copy[j] = data[j];
}

3. loop copy
var copy = []
for (var j = 0; j < data.length; j++) {
copy.push(data[j]);
}

The winner is splice copy
http://jsperf.com/loop-vs-slice-copy/3 has the proof to the performance.

Categories: Javascript

Get thumbnail of YouTube video link using YouTube API

May 21, 2013 14 comments

YouTube video has 4 generated image.

http://img.youtube.com/vi/ID/0.jpg
http://img.youtube.com/vi/ID/1.jpg
http://img.youtube.com/vi/ID/2.jpg
http://img.youtube.com/vi/ID/3.jpg

eg.
Youtube ID: wstBewwipGI

http://img.youtube.com/vi/wstBewwipGI/0.jpg (480px x 360px)

http://img.youtube.com/vi/wstBewwipGI/1.jpg (120px x 90px)

http://img.youtube.com/vi/wstBewwipGI/2.jpg (120px x 90px)

http://img.youtube.com/vi/JwstBewwipGI/3.jpg (120px x 90px)

For the high quality version of the thumbnail use a url similar to this:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

There is also a medium quality version of the thumbnail, using a url similar to the HQ:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

For the maximum resolution version of the thumbnail use a url similar to this:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

Categories: General, HTML

“The Sales Girl in Chennai “Giri Store, Through the eyes of “Washington Post”

May 20, 2013 Leave a comment

"The Sales Girl in Chennai "Giri Store, Through the eyes of “Washington Post”

       After the Temple Darshan at the Kapaleeswarar Koil at Mylapore, we entered the "Giri Trading" stores and started searching for this Book on "Thatva Bodha".

       We found many people buying various Books and CDs and from their smart walks and accumulation of CDs from Abhang to Aruna Sairam and Bhajans to Bombay ishree, sent a nice feeling in us, that we have come to the right place indeed.

       I was looking for this Book while my wife started collecting Bharathiar's songs and MS's Music.  I searched everywhere for this Book.

       There was this Girl, standing next to the Cashier, sincerely watching all our movements - a dark complexioned Girl, should be from a nearby Village, might be 17 or 18, should not have crossed 8th Std., might be out of poverty she is here..  All my Journalist's brain unnecessarily calculated about this Gullible Girl..and tho' she was repeatedly watching me, I ignored her and started searching for "Thathva Bodha".

       I saw many books from "Sandhya Vandanam" to Swami VIvekananda's "Chicago Speech" but having spent a good 40 minutes.  I looked at her; she also looked at me curiously.

       I did not asked her, knowing fully well that such a girl cannot have any idea of anything, leave alone "Thathva Bodah".

        "Sir, may I help you*?*" (in Tamil)
       "Yes. I am looking for 'Thatva Bodha' "
       "Sanskrit Text or English/Sanskrit*?*"
       God..she knows.  "Sanskrit & English"
       "Do you like to have the Publication from Chinmaya Mission or Indu Publications or by Ramakrishna Mutt*?*"
       "I don't know..I just want to only Learn you see.. I don't really know indeed"
       "Do you read Tamil Sir*?*"
       "Yes I am a Tamilian " (thinking to myself how most of mylife time I like to act in most Other places that I am not)
       "Then Sir, you can take this"..she ran to the shelf where I had searched for 30 minutes, removed the books in the front and came out with a Book in Tamil.
       "This one in Tamil by N.Sivaraman by Indu Publications infact is simple and wonderfull.  You have the Sanskrit Text too inside."

       My God!  Why did I under estimate such a Genius.  Just because of my Arrogance that I am an NRI.  Or Just because I presumed such a Black, dark omplexioned, gullible girl, who would have come for this job out of absolute poverty, wouldn't have any idea of "Thatva Bodha".

       I decided to change my attitude and realized that I am absolutely an 'Idiot' at this moment in front of this wonderful girl and submitted myself in all humility.  "Madam, I really don't have any idea of even who wrote Thatva Bodha' till yesterday.  I just attended a lecture on this subject and was fascinated by the lecture and hence....."

       "Did you attend Goda Venkateswara Sastri's lecture in Bharathiya Vidya Bhavan*?*"
       "Oh God. How did you know*?*"
       "He regularly takes classes on such subjects.  In fact he is one of the best Sir, in the city on such subjects."
       "You are interested in such subjects*?*"
       "Yes Sir, I read a lot about Swami Vivekananda and Ramakrishna and Thathva Bodha incidentally is my favourite Subject"
       "Do you mean to say you have read Thatva Bodha*?*"
       "I have read this one by Sivaraman.  Once you read it you won't feel like keeping that book on the table at all."

       "Why what is so great about this Book*?*"
       "Sir,you must be joking that you don't know about 'Thatva Bodha'."
       "Really.  I accept my ignorance."

       My wife was watching from the corner, admiring all her CD collections.

       "Sir,according to me, if you read this it gives the entire Vedanthic Saramsam and to say it in-one-word you become a bit more humble in life, leaving ahamkaram once for all."

       "Is it a fact that reading this simple book one would get so humble*?*"
       "Of course one should be involved totally into the text.  Needs a lot of conviction and devotion."

       My wife joined the conversation and she felt this girl is indeed a very - very talented intelligent girl, so she told me, "Why don't you interview her for Washington Post*?* Why at all you should think of Paris Hilton*?*"

       I also felt that I owe something to her..  So, I asked her whether she can spare sometime for an interview.

       She politely refused saying "My boss is to give me permission. Besides, many people are looking for guidance or help, like you and hence I have to go."

       "What is your name*?*"
       "Kalaivani."

       My wife's admiration for her devotion to duty and her total involvement in her work, made her go direct to the Boss and said, "Sir,that girl Kalaivani."
       "Yes very hard working Girl."
       "This is my husband Viswanath."
       "Nice meeting you Sir"
       "He is the Senior Journalist in Washington Post."
       The Boss stood up." Washington Post*?*"
       "Yes Sir.  I would like to interview this girl. I am highly impressed with her ethics."

       The Boss called her.  Time was 5:45 Pm.  "Kalaivani, they have come all the way from USA., They would like to spend some time with you.  Can you*?*"

       "Sir, there are so many customers waiting for some guidance. as it is a rush time.  If they can come again tomorrow?".
       "OK. I can come again tomorrow."
       I came back next day morning leaving all my appointments with 'Times of India 'and “Madras Press Club “ just to see this girl.  It was no rush hour.

       My wife and myself found out.  Kalaivani is from a small village near Arcot.  She has 5 sisters, she being is the eldest.  Her father was a drunkard and he died a few years ago caring for none of them.  Her mother used to work as a helper in Masonry and passed away two years back, leaving all the 6 on the streets.

       This girl who had completed her 9th std decided to search for a job and 'Giri Trading' came forward to help her out.  She brought up all her 5 sisters with er and with her meager salary she is taking care of them.  All the 5 sisters are going to a nearby Chennai Corporation School.

       "Kalaivani. But when did you get this enthusiasm to learn about 'ThatvaBodha'*?*"

       "Sir after joining here, I decided that the best way to be of help to the customers is to know the Subject first. I took small Books on Ramana, Ramakrishna, swami Vivekananda and started reading.  I found the subject so fascinating..
I decided to read other books in Tamil like Bhagavad Gita, and Viveka Choodamani. Thats how...."

       "What is your salary*?*"
       "Rs 2,500/ a month, Sir."
       "Are you able to manage all your expenses with the 5 sisters*?*"
       "Not at all Sir, but the Boss helps me a lot."
       "What is your aim in Life *?*"
       "I want all my sisters to get education. Then they would easily get employment.  Is it not Sir*?*"
       "If I give you Rs 10,000 per month, for meeting all your expenses, would that suffice*?*"
       "It is indeed too much, but I would accept it only through my Boss."
       We took her to the Boss and told him that we would like to send Rs.10,000 every month so that all her sisters' education would be completed.

       The Boss said "She deserves it Sir.  You can trust me - I will hand over the amount to her every month or alternately you can open an account in her name and start transferring to the account."

       My friend John Paul, who is the Regional Manager of 'Times of India' had also come with me.  He said, "You have done a good thing." My wife said, "I pray that 'Karpagambal' helps Kalaivani to become an expert
in 'Vedantha' and start giving lectures in USA .  We can arrange for her lectures."

       We left wonder struck!  If we go into the interiors of India, how many more 'Jewels' like Kalaivani can be found!!

       I really became humbled!

—–

I am really impressed with this instant.. this has changed most of me…

Categories: inspiration

getter and setter properties in javascript

May 16, 2013 Leave a comment

In .net, C# we have a feature called Get Set.


Class Box{
    private int width =0;
    private int height = 0;

    public int Width
    {
      get { return this.width; }
      set { this.width = value; }
    }

    public int Height
    {
      get { return this.height; }
      set { this.height = value; }
    }
}

this is a cool feature. If we want this same in javascript, we can have it.
ECMAScript version 5 is the latest, official, approved standard version of the ECMAScript programming language.

Here is the sample


var box = Object.create({}, {
     _width: {
         value: null,
         enumerable: false,
         writable: true,
         configurable: false
      },
     _height: {
         value: null,
         enumerable: false,
         writable: true,
         configurable: false
      },
      Height: {
           get: function() {
              console.log("get is called");
              return this._height;
           },
           set: function(value) {
              console.log("set is called");
              this._height = value;
           },
           enumerable: true,
           configurable: false
      },
      Width: {
           get: function() {
              console.log("get is called");
              return this._width;
           },
           set: function(value) {
              console.log("set is called");
              this._width = value;
           },
           enumerable: true,
           configurable: false
      }
});
box.Width = 100; //set will be called
box.Height = 100; //set will be called
console.log(box.Width); //get will be called
console.log(box.Height); //get will be called

Categories: Javascript
Follow

Get every new post delivered to your Inbox.

Join 596 other followers