Wednesday, 14 January 2015

Regular Expression to change plain text to link

Here is small javascript code to change from plain text to html link which you can use while showing your posts.

<small style="color:blue; ">
var text = 'The CBOE Options Institute is offering a free webinar series: "New Tools for Trading Volatility" from CBOE, the Home of the CBOE Volatility Index (VIX®)" webinar series on December 10 - 12, 2013. Online access will be available by clicking HERE https://www.cboe.com/AboutCBOE/WebinarTools/ on December 10 - 12, 2013. If you need assistance, please call 1-877-THE-CBOE, press 2, and you will be connected with a staff member who can assist you. The Options Institute Staff 1-877-THE-CBOE https://www.cboe.com';

var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;</b>

 text.replace(exp,"<a href='$1'>$1</a>"); 
</small>

Tuesday, 22 April 2014

Compare two arrays in javascript.

Here is the small and beautiful function to compare two arrays in javascript

function arraysIdentical(a, b) { var i = a.length; while (i--) { if (a[i] !== b[i]) return false; } return true; }; 

arraysIdentical(["1","3","2","4"],["1","2","3"])


 If the arrays are not identical it will return false otherwise true. Use it enjoy it.

Friday, 25 October 2013

Custom ng-keypress, ng-keyup and ng-keydown directive in Angular js

In angular js sometimes we face an issue that is ng-keypress, ng-keyup and ng-keydown soetimes does  not work properly.
Here is the quick solution of this issue. You just have to write a small directive for this :


app.directive('zKeypress', function(){ 
 return {
     restrict: 'A',
     link: function(scope, elem, attr, ctrl) {
         elem.bind('keypress', function(){
             scope.$apply(function(s) {
                 s.$eval(attr.zKeyup);
             });
         });
     } }; 
});

Here is how you will apply this with tags:


<input type="text" z-keypress="foo()"/>  

You can change this keypress to keyup and keydown just to change one line :

  elem.bind('keypress', function(){

You can change this keypress with keyup and keydown

Friday, 20 September 2013

Remove last text from the string

Here is a simple and short method of resolving this issue:

var lastIndex = str.lastIndexOf(" ")

var str = str.substring(0, lastIndex);
 If you know the last text for example in my issue each string contains x in the last. I used str.lastIndexOf("x") for resolving my issue. You can customize it according to your requirement.
 

Thursday, 19 September 2013

Fun Game with Google Easter Eggs

Why get bored guys have a fun with Google. Most of you already knows abut this:



  1. My favorites was 'PAC-MAN'
  2. Type 'Zerg Rush' Into Google.



Enjoy it :-)

Use .htaccess file for remove .php extension

I have just got a requirement of remove the .php extension from a website, for make the URLs more SEO friendly (clean url).
Here I’ll show you how to do that easily, by editing the .htaccess file.
More information about .htaccess can be found here : http://en.wikipedia.org/wiki/Htaccess 

Removing .php Extensions

To remove the .php extension from a PHP file for example mysite.com/contact-us.php to mysite.com/contact-us you have to add the following code inside the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Friday, 30 August 2013

Make background-size work in IE

Background size does not work with less than IE9 browsers. Here is the solution
of this issue.
 
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo.gif',
sizingMethod='scale');

-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo
.gif',
sizingMethod='scale')";