Tuesday, November 25, 2014

Javascript: Cloning an object...

In Case, you need to do a complete clone of an object in Javascript and you want the original to remain unaffected, then you probably can give this method a go. :)


* Click here to access the demo that I have created on 'JSFiddle'.
^ Click here to test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code
  editor.

Sunday, November 16, 2014

Towards the end of 2014...

Less than 8 more weeks to the end of 2014. And it's time to start the countdown for the last IT Show for the year 2014...

Image taken from 'SITEX 2014' website.

The venue for the upcoming event is pretty far, but it's
worth travelling all the way down. As compared to the
venue at 'Suntec Convention & Exhibition Centre', I prefer
the huge spacious space at Singapore Expo. Most importantly,
I can roam around the place freely and quickly, whhich is a
very big (+). :)
Venue:
  • Date: 27 - 30 November 2014
  • Opening Hours: 11am to 9pm
  • Venue: Singapore Expo Convention & Exhibition Centre
                 Halls 5 & 6

* Click here to find out more about 'SITEX 2014'.
^ Click here for the Facebook page of 'SITEX 2014' site.
~ Click here for the unofficial 'SITEX 2014' site.
  (You can gain access to all the pricelist of all the Exhibitor @ 'SITEX 2014'.
  Although it isn't available yet but it will be populated with lots of price lists and
  brochure as the 'show' approaches.)

Sunday, November 9, 2014

Javascript: Some useful sites that helps.

Frankly speaking, I don't have a fantastic memory and in case, you don't have a fantastic memory, you probably can use the following sites to search for useful examples and references. Even though these sites doesn't provide an example for all everything, but it's a great place to start searching.

W3Schools
This has been around for quite some time.
Not only it covers 'Javascript', it also covers coding environment
like 'PHP', 'SQL', 'ASP.NET', etc... Though most of the time it
covers only the basic stuff, but it's a great place to get you
started.

JavaScripture
This covers JavaScript only. But with the number of examples that
was provided on the site itself to demonstrate the usage of the
different types of JavaScript syntax, makes this a pretty good
place to start searching.

Sunday, October 26, 2014

Apache Ant: Pushing your Ant script to a whole new level...

If you have been using Apache Ant quite a bit, you will soon realize that it can be pretty annoying at times. You couldn't open up and read a file, you couldn't create Arrays, etc... Therefore there's actually a way to work around it. You can actually use Javascript + Java inside the Ant script environment. And on top of that you can actually manipulate simple basic Ant variables in the Javascript + Java environment.

 <macrodef name="getIndexHtmlContents">
  <sequential>      
   <script language="javascript">
    <![CDATA[
     //Import the necessary Java classes
     importClass(java.io.File);
     importClass(java.io.FileReader);
     importClass(java.io.BufferedReader);

     //We will be reading the value from the Ant Project Property 'filenameProp'
     var filenameProp = GWR.getProperty("filenameProp");

     //Then we will be using BufferedReader and FileReader to read the contents of the file
     var reader = new BufferedReader(new FileReader(new File(filenameProp)));

     //Next we will loop through all the contents of the file and store it in a temporary variable
     var sCurrentLine;
     var strEverything = "";
     while ((sCurrentLine = reader.readLine()) != null) {
      strEverything += sCurrentLine;
     }

     //We will printout the contents of the file/temporary variable on the ant console output
     println(strEverything);

     //Writing the value of the temporary variable and saing it in the Ant Project Property 'fileContents'
     GWR.setProperty("fileContents", strEverything);
    ]]>
   </script>
  </sequential>
 </macrodef>
Though you have specified that you will be writing some script in 'Javascript' syntax, it actually allows Java codes to be written inside that <script> block too.

* Click here to find out more about 'Apache Ant'.

Friday, October 17, 2014

Linux: Mass find and replace a folder of files

In the Linux environment, it is pretty easy to loop through a particular type of files to find and replace a particular string using shell script. I hope this helps.

The following will give you an idea how to get it done.
You need to replace all the {value} with the corresponding values.
#!/bin/bash

varReplace={string_to_replace}
find ./{the_folder}/ -name \*.{file_extension} -type f -print0 | while read -d $'\0' file; do
    echo "Processing $file"
    sed -i 's/{string_to_look_for}/'$varReplace'/g' $file
done
The following example will go through all the files with extension (.js)
in the folder 'output', find the string '{my_version}' and replace it with
the string 'v1.0.122'.
#!/bin/bash

varReplace=v1.0.122
find ./output/ -name \*.js -type f -print0 | while read -d $'\0' file; do
    echo "Processing $file"
    sed -i 's/{my_version}/'$varReplace'/g' $file
done

Friday, October 10, 2014

Simple Javascript Timer Implementation

Well basically this is a post meant for myself. I keep forgetting how to get this done. Basically this is a simple implementation of a Timer in Javascript.


* Click here to access the demo that I have created on 'JSFiddle'.
^ Click here to test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code
  editor.

Friday, October 3, 2014

AngularJS: Input type number and maxlength fix

Well, there might be situations that you need to limit the number of characters that you are allowing the user to enter in a numerical text field. Therefore, here's a fix for angularJS.


* Click here to access the demo that I have created on 'JSFiddle'.
^ Click here to test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code
  editor.