Monday, 26 June 2017

Including jQuery in node.js

I just started working on Node.js and the first issue I encountered was integrating jQuery into the application. I tried the npm listed option but that didn't work. After googling, I found the below code that helped me include and use jQuery in node.


const jsdom = require('jsdom');
const {
    JSDOM
} = jsdom;
const {
    window
} = new JSDOM('<!DOCTYPE html>');
const $ = require('jQuery')(window);

After analyzing the code, I realized that a window with a document is required for jQuery to work in Node and node doesn't provide any such default window. So we use jsdom to mock it.

Thursday, 11 June 2015

How to configure TortoiseSVN repository with Apache and Subversion?


 Configuring SVN repository


        Most of us know how to install and use SVN Client. But we never get a chance to configure a repository and provide a http url for version control. This blog is about creating one such repo and make it available over http. Installing SVN and making a folder as a repository will only make it available locally but to access it over http from other systems, we need servers like svnserve or apache etc. We will learn about configuring svn with apache in this blog! :)
1.      Download and install TortoiseSVN 1.8.11, in the server, from “http://tortoisesvn.net/downloads.html”.

2.      Create a folder in D:\ drive with the name “SVNRoot”.

3.      Create a new folder under any drive, say E:\SVNRoot.

4.      Right click on the newly created folder and select “Create repository here” option under TortoiseSVN. Thus a repository is created locally. To make it available over http, we will configure it using Apache and subversion as mentioned below.




Fig. Creating SVN repository

 5.      Download Apache server binary version “Apache 2.4.12 x64” from “https://www.apachehaus.com/cgi-bin/download.plx”.


6.      Download Subversion modules for Apache – “Mod Subversion 1.8.11 for Apache 2.4.x x64” from “https://www.apachehaus.com/cgi-bin/download.plx”.

 

                                    Fig. Downloaded Apache Server and Subversion Modules

 7.      Copy the following subversion modules into Apache modules:

a.       mod_dav_svn.so

b.      mod_authz_svn.so

Subversion modules source path: “mod_svn-1.8.11-ap24-vc9-x64\modules”

Apache modules destination path: “httpd-2.4.12-x64-r2\Apache24\modules

8.      Copy all the dll files from “mod_svn-1.8.11-ap24-vc9-x64\bin  to “httpd-2.4.12-x64-r2\Apache24\bin

 

                                          Fig. dll files to be copied

9.      Open the “httpd.conf” file from the Apache server folder - “httpd-2.4.12-x64-r2\Apache24\conf” in notepad and make the following changes:

 
a.       Update “Listen 80” to “Listen 8078” or any other port number.

b.      Update “Define SRVROOT path to “Define SRVROOT "E:/final/httpd-2.4.12-x64-r2/Apache24"”

c.       Update ServerName to “ServerName localhost:8078”.

d.      Add the following code at the end of the file:

 
LoadModule dav_module modules/mod_dav.so

LoadModule dav_svn_module modules/mod_dav_svn.so

LoadModule authz_svn_module modules/mod_authz_svn.so

 

<Location /repos>

  DAV svn

  SVNListParentPath on

  SVNParentPath D:/SVNroot

</Location>

SVNParentPath path should point to the root directory of the repositories.
We can also add authentication details in the <Location></Location> section.

10.  Save the httpd.conf file and open the cmd prompt as administrator.

11.  Navigate to the Apache bin folder(httpd-2.4.12-x64-r2\Apache24\bin) in the cmd prompt and execute the following command:

 
httpd.exe –k install

 
12.  Now the repository will be available over http and we can check-in and checkout the code using the TortoiseSVN client in our local systems. :)

 

Monday, 27 April 2015

Ajax data not getting updated in IE

Again an issue with Ajax and JSON in IE. I was working on an application that needs the updated data to be rendered once every minute. Everything works good in Firefox and Chrome. But again IE, only the first result set was getting rendered and the subsequent ajax calls data wasn't fetching the updated one. When explored on this issue, we found it was a caching problem. I did try adding a timer to the ajax call URL so that every call is unique but that did not work either. Then tried the attribute - {cache: "false"}and it started working :) There are scenarios where changing the url by just appending some additional unique parameter to the url everytime worked in IE but there could be an issue with cache and setting the cache attribute to false helps!! :)

JSON.stringify and JSON.parse not working in IE

While working with JSON data in  an ajax call, I was using the JSON.stringify and JSON.parse methods. Everything was working good in Chrome and Firefox but, as usual, it wasn't in IE. :( Then found this json2.js file that allows JSON.parse and JSON.stringify to work in any browser i.e. it has a global JSON object that has these two methods - stringify and prase implemented :) All, I had to do was just include this js file and that is it. It started working :) 

Friday, 31 October 2014

How to redirect requests (in IIS), to a particular ColdFusion server when multiple versions (CF 9,10,11 etc.) are installed?


How to redirect requests (in IIS), to a particular ColdFusion server when multiple versions (CF 9,10,11 etc.) are installed?

Introduction:
                We often install multiple versions of ColdFusion in our system and may need to redirect the requests, amongst these versions, based on the need.
Solution:
Open IIS and single click on the WebServer


In the “Features View” – in the centre of the IIS Screen, we will have an option – “Handler Mappings”.
 Handler Mappings is responsible for redirecting the requests to particular servers.
On double clicking Handler Mappings, we will find a lot of mappings. Amongst them, we will have to modify –
1.       cfmHandler
2.       cfcHandler
3.       cfmlHandler
4.       cfrHandler
5.       cfswfHandler



Right Click on cfcHandler and select “Edit”.

 
We will find the “Executable” path pointing to the “isapi_redirect.dll” file present in the coldfusion server. We will have to change this pointer to point to the dll file present in the coldfusion server (C:\ColdFusion10\config\wsconfig\1) to which we wish to redirect the requests.
We will do the same and change the Executable pointers of others (cfmHandler,cfmlHandler,cfrHandler,cfswfHandler) to the required coldfusion server.


That’s it!! Its done. J



Thursday, 22 May 2014

An error occurred while reading the Excel: org.apache.poi.hssf.record.RecordFormatException: Duplicate PageSettingsBlock record (sid=0x89c).

ISSUE IF POI JAR FILES ARE NOT UPGRADED
Exception: ‘An error occurred while reading the Excel: org.apache.poi.hssf.record.RecordFormatException: Duplicate PageSettingsBlock record (sid=0x89c).’
Exception Cause: Using older version of POI jar files.
Description:
At times, while reading few .xls files, using cfspreadsheet, we face the following issue:
‘An error occurred while reading the Excel: org.apache.poi.hssf.record.RecordFormatException: Duplicate PageSettingsBlock record (sid=0x89c).’



This is because the default poi jar files-we get with CF installation, do not process all excel files. CF10 gives us version 3.6 beta jar files by default and these do not process all the excel files. So we have to upgrade these jar files for better Excel support in ColdFusion.

  
Solution:
1.       Download the latest stable “Binary Distribution” version jar files from “http://poi.apache.org/download.html”. I have downloaded version 3.10 from ”http://mirror.nexcess.net/apache/poi/release/bin/poi-bin-3.10-FINAL-20140208.tar.gz


2.       Extract the files to a temporary folder.
3.       Navigate to the ColdFusion’s lib folder - “C:\ColdFusion10\cfusion\lib”.
4.       Take a backup of all the jar files starting with “poi-“.


5.       Stop the ColdFusion Service. (Services.msc  -> ColdFusionMX Application Server).

6.       Delete the existing poi jar files (jar files starting with poi -) from the “lib” folder (C:\ColdFusion10\cfusion\lib).
7.       Copy the latest jar files, which were extracted to a temporary folder earlier, into the “lib” folder.
8.       Now start the ColdFusion Service.
9.       Execute the file processing the .xls file. It should now be able to read the excel file.

J

Windows could not start the ColdFusion 10 Application Server on Local Computer. For more information review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 0.


                                MAXIMUM JVM HEAP SIZE ALLOWED IN A 32-BIT OPERATING SYSTEM.
Error Message: “Windows could not start the ColdFusion 10 Application Server on Local Computer. For more information review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 0. “
Error Cause:  Allocating 1844 MB or more for ‘Maximum JVM Heap Size (in MB)’ in ‘Java and JVM‘ Settings of CF Admin on a 32-bit processing system.
Note:
Any value, greater than 1844, in a 32-bit OS, for Max JVM Heap Size would cause the issue mentioned.
Description:
At times, we get errors specifying that the process is running short of JVM Heap memory. So we increase the Max JVM Heap size through CF Administrator. But increasing the Max size, without knowing its boundary value, would land up in getting the issue mentioned below:
1.       Try changing the ‘Maximum JVM Heap Size (in MB)’ value in ‘Java and JVM’ settings of CF Admin to any value higher than 1844 on a 32bit operating system, as shown in the below screen shot.

  
2.       Then click on Submit. An alert appears, as shown below, which asks for a ColdFusion Service restart.



3.       Open Services.msc and try restarting the ColdFusion service.

4.       It throws an error as shown in the below screenshot:


 5.       The only way, this issue can be fixed, is by changing the jvm.config file.
a.       Go to CF Installation directory like “C:\ColdFusion10\cfusion\bin\” and there you will find a file jvm.config.
b.      If the file is not found, search for jvm.config file in the installation directory.
c.       Open this file in Notepad and search for “Arguments to VM”.
d.      Change the value after –Xmx to a value less than 1844.
e.      Save the file and then restart the ColdFusion Service.



Issue fixed J



Reverting accidental delete/update without recent backup


Issue:  At times, we may run/execute an update/delete script accidentally and then start googling to find if there is a way to revert it.
Requirement to fix the issue: Old Backup of the same Database.
Solution:
The solution given below is helpful if you have some old Database backup.
Steps:
1.      Note the approximate time at which you executed the update/delete script. Restoring the DB to a minute earlier to that time would make sure that we haven’t lost any updates on the DB.
2.      Take a ‘Transaction Log’ backup of the Database to be restored by selecting the ‘Transaction Log’ from the ‘Backup Type’ dropdown. To get the "Transaction Log" in the dropdown, make sure the DB Recover Model is "FULL". 
      To make a DB recover model as "Full":
            1.      After connecting to the appropriate instance of the SQL Server Database Engine, in Object       Explorer, click the server name to expand the server tree.
2.      Expand Databases, and, depending on the database, either select a user database or expand System Databases and select a system database.
3.      Right-click the database, and then click Properties, which opens the Database Properties dialog box.
4.      In the Select a page pane, click Options.
5.      The current recovery model is displayed in the Recovery model list box.
6.      Optionally, to change the recovery model select a different model list. The choices are Full, Bulk-logged, or Simple.
7.      Click OK.






         
3.      Now ‘Restore’ the old backup of the database you have. Make sure that select the ‘RESTORE WITH NORECOVERY’ option in the ‘Recovery State’ dropdown in Restore options.




4.      Once the Old backup is restored, now restore the Transaction Log Backup specifying the timeline which is BEFORE the update/delete script execution.Also make sure to select the ‘RESTORE WITH RECOVERY’ option in Restore Options.





5.      Now run a SELECT script and check the records. They would contain the values before the Update/Delete script execution. J