Posts

javascript break in browser debugger

Image
While doing web (html+js) development, sometimes it's tedious to open your javascript code and put breakpoint in browser debugger to debug the code. This becomes even more difficult when you have to debug the code that gets executed on start up. here is an easy solution: put  debugger;  statement in your javascript code where you want to break. e.g. function doSomething(){    //some code here...    debugger;    //some more code here... } launch browser debugger (F12). navigate to your web application. debugger will automatically break at the debugger; statement.

Sleep or Wait in windows batch script

@ping 127.0.0.1 -n number_of_seconds + 1 >Nul for example, to sleep for 5 seconds @ping 127.0.0.1 -n  6 >Nul

Asp.Net concurrent requests from same session

You could run into a situation where you need to make multiple server requests from same browser page (or rather session). We would expect the requests to be served in parallel but they rather go sequential. Behavior of session-enabled requests handling by asp.net is important to be known to handle this case. Session State is read-write for pages by default. In this case, any request gets exclusive lock to the session object. So, the other requests from the same session (even if it requires only read access to the session) will have to wait until the lock is released either by completing the first request or timeout on the lock by first request.

xml dom - create element with namespace (cross browser)

var xmlDoc; ////some code to load and initialize xmlDoc.. //create an element 'book', with prefix 'px' and namespace 'http://bookshop.com/schema' var bookelement; if (xmlDoc.createElementNS) { //for other browsers than ie     bookelement = xmlDoc.createElementNS( 'px:book' , 'http://bookshop.com/schema' ); } else { //for ie     bookelement = xmlDoc.createNode(1, 'px:book' , 'http://bookshop.com/schema' ); } will create book element: < px:book xmlns:px ='http://bookshop.com/schema' />

cross-browser set innerText of an element

function setInnerText(elem, text) {    elem.innerHTML = "t" ; //dummy just to create a text node. ensures no other html exists inside but only text    elem.firstChild.nodeValue = text; }

FTP PASV (passive) mode

Ftp clients tell us to switch to PASV mode if you are behind firewall. Why so? The answer lies in the way FTP protocol works between client and server. There are 2 channels created between client and server: 1 for commands and 2nd for data. Let's take this example: You wanna receive a file from server. Client sends the command to server to receive a file through first channel. Now the 2nd channel has to be established to transfer the file from server to client. In normal mode, client starts listening on a port (act as server) and tells the server its ip and the port. Now server connects to client at the specified port and sends file. When there is firewall on client, it might block server to connect to client and that's the reason PASV (passive) mode is required. In passive mode , client tells the server to enter passive mode in response to that server listens on a port and sends the port number to client where client connects to the server at the specified port and receiv