Error: socket hang up

While working with Node.js microservice that had some long-running request/queries, I needed a way to increase the request timeout for the Express application.

It is not clearly defined in documentation and not at all, in the Express documentation so here’s how you do it.

Simply put, you need to configure the timeout value on the HTTP Server that express generates when you call the listen method.

Continue reading “Error: socket hang up”

Angular Js: ng serve doesn’t listen remote machine

If you are working on Angular Js and trying to run it form remote machine, you will face this issue of site not opening.

ng serve

above command binds to 127.0.0.1 with port 4200 by default.

In order to open this up for all IP address you can use below command while running ng serve.

uncaught exception: [Exception… “Not enough arguments” (NS_ERROR_XPC_NOT_ENOUGH_ARGS)

I was testing my web application on FireFox5 , I faced “not enough arguments” issue. During investigation what I found is while opening the page we are hitting actual issues inside ‘addEventListener’ function. I searched web around behavior of ‘addEventListener’ in firefox and found that it expect third argument as well so I replaced below code locally and it worked for me =)

addEventListener(“load”, function(event) {
      _init();
);

with Continue reading “uncaught exception: [Exception… “Not enough arguments” (NS_ERROR_XPC_NOT_ENOUGH_ARGS)”

Javascript: Make independent copy of array using slice() method

Sometime it happens that we need to make copy of an array but in javascript when we assign an array to new it assign it with reference means if you delete anything from new array it will delete it from the main array as well 🙁

To create a copy of an array that is independent of another array:
Use the Array object’s slice() method.

For example, the following statements create an array and then use slice() to make an independent copy of the array.

 // JavaScript syntax

var oldArray = ["1", "b", "3"];

var newArray = oldArray.slice();

Remove element from Array

What if you want to delete an element from Array ??

Mostly people use delete command  but it leaves undefined behind it

>>> var list = [1,2,3];

>>> delete list[1];

>>> list

[1, undefined, 3]

Now try splice instead of delete

>>> var list = [1,2,3];
>>> list.splice(1, 1); // Remove one element, returns the removed ones.
[5]
>>> list[4, 6]
And it's done... 

Javascript – Add Float numbers upto 2 Decimal

Hi,

Today I was creating a page that is basically a calculator page have many text fields. All of them can accept number upto 2 decimal and onBlur() I have to total that numbers and display on the page

 <script language="JavaScript" type="text/javascript">

function something()
{
    var val = parseFloat('2.22') + parseFloat('3.33');
    val = parseInt( val * 100 ) / 100;
    alert(val)

}

</script>

it results 5.5500000000000001 but my expected result was 5.55

Continue reading “Javascript – Add Float numbers upto 2 Decimal”

“Learning jQuery” Book review

Book review by Techcrony.info | Publisher: Packt. Author(s): Jonathan Chaffer and Karl Swedberg | Reviewed on: April 8th, 2008'


jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

jQuery is one of at least a dozen JavaScript frameworks that have exploded onto the scene during the last few years, and for good reason. The Web 2.0 era has called upon JavaScript in a big way, turning to it as the driving force behind all the gliz and glamour that defines any Web 2.0 site. This huge increase in workload for JavaScript has called out for JavaScript frameworks that do the heavy lifting of common Web 2.0 tasks for us, from common visual effects such as fading, DOM traversal/ manipulation, to of course, Ajax interaction. jQuery has risen to become one of the most popular JavaScript framework due to its small footprint and focus on just the core tasks shared by almost any Web 2.0 project. A few books have sprung up to go beyond the jQuery documentation in explaining all that this framework has to offer, one of them being "Learning jQuery" (Packt Publishing).

"Learning jQuery" compliments the official jQuery documentation nicely, as its focus is on how to harness the power of jQuery to replace things you're used to do using raw JavaScript. The book is structured so that each chapter acts as a building block to the next, and requires no previous knowledge of jQuery to begin. The book's TOC is as follows:

Chapter 1: Getting Started
Chapter 2: Selectors–How to Get Anything You Want
Chapter 3: Events–How to Pull the Trigger
Chapter 4: Effects–How to Add Flair to Your Actions
Chapter 5: DOM Manipulation–How to Change Your Page on Command
Chapter 6: AJAX–How to Make Your Site Buzzword-Compliant
Chapter 7: Table Manipulation
Chapter 8: Forms with Function
Chapter 9: Shufflers and Rotators
Chapter 10: Plug-ins
Appendix A: Online Resources
Appendix B: Development Tools
Appendix C: JavaScript Closures

Chapter one quickly prepares you for the syntax conventions used by jQuery before opening the flood gates. Each chapter thereon examines a different area handled by "normal" JavaScript, and how that process can be simplified greatly using jQuery. One of the greatest strengths of jQuery lies in its DOM and elements traversal abilities, and in Chapter 2, the reader is shown how to turn their understanding of CSS and XPath Selectors as basis for actually accessing those elements, using jQuery. It also explains the concept of "chaining" in jQuery, or the ability to perform multiple actions on multiple elements all in one scoop. The sharp turn from introduction to getting straight to the heart of jQuery does mean you better have a firm grasp on JavaScript and CSS already before picking up this book, or you'll get lost very quickly. This is more of a praise than a criticism however- jQuery is what you're going to get with this book, nothing more (or less depending on how you see it).

In Chapter 3, the reader is shown how to attach and remove events to elements using jQuery, and how jQuery expedites things in terms of cross browser compatibility and more subtle issues like taking care of potential memory leaks in IE. Essential event related tasks like preventing event bubbling, event propagation, and cancelling default actions are also discussed within the context of using jQuery.

Chapter 4 looks at jQuery's built in abilities for rendering effects like element fading, sliding in/out, movement across the page etc. jQuery isn't exactly an effects centric library like MooTools, but there are still areas it covers that the jQuery documentation itself does a poor job of, such as the animate() method and how to queue effects.

Chapter 5 breaks down DOM and HTML manipulation using jQuery, a task that is currently quite tedious for the purists that go through the standard DOM methods on their own to accomplish. You'll learn things like using jQuery to insert new elements, move elements, copying and appending elements to the document
on demand.

In Chapter 6, "Learning jQuery" woes the Web 2.0 crowd by going into detail jQuery's Ajax abilities, and how it makes light work of common tasks such as performing GET/POST requests, fetching data as either JSON or XML and parsing it using jQuery. There are quite a few Ajax related methods in jQuery, some redundant IMO, and this chapter does start to lose focus by trying to cover too many of them, instead of limiting itself to just methods that do not overlap in function. Nonetheless, it's still better than the jQuery documentation, that's for sure.

Up until this point, all the chapters have been "building blocks" in nature, one paving the way to the next. However, starting in Chapter 7,  "Table Manipulation", breaks away from this roadmap and looks at common tasks of the day that can be simplified and enhanced using jQuery. There are additional jQuery tips you pick up as you read these chapters, though the focus now is more on the application rather than new techniques. Chapter 8 "Forms with Function" arguably has the most mass appeal, containing numerous examples that are manageable in size and somewhat self contained, from the obligatory required fields validation, checking for specific data types like numbers, currency etc, to Ajax infused forms.

The concept of "closures" in JavaScript is interwoven into every aspect of jQuery when it comes to its deployment, and to that end, the final section of this book, "Appendix C" provides a good tutorial on JavaScript closures. It's a fitting and nice conclusion to a great book.

There currently aren't many other jQuery books to compare "Learning jQuery" to, but it really doesn't matter. If you're new to jQuery or JavaScript frameworks in general yet aren't new to JavaScript itself, it's hard to go wrong with picking up "Learning jQuery" to learn jQuery.

Reference:

1) Learning jQuery by Packt Publishing

2) Learning jQuery Blog