Remember the callback daze

Javascript is everywhere.. it took off to be the most predominant language that applications are developed on both server (node.js)  &  client side (web, mobile, desktop) with plethora of technologies & frameworks.  While coding/debugging nodejs modules, I understand the asynchronous pattern of callbacks functions and how they fit into the event-based execution model of Javascript. But sometimes, the callbackhell is quite overwhelming and I get lost in the daze of callback functions, which ends up in myself strolling through the blogs for a better, clear understanding of the concept. This post is a synthesis of one such instance.

Coming from a Java/C# Eco system, where traditionally functions are defined as per contract/definition and executed sequentially (well…most of the time, other than EventHandlers, callback interfaces, etc.) & every function/method has an object input, output & possible exception handling. Functions in javascript are different as they can be defined traditionally with input arguments & output/return values. They can also be expressed, manipulated passed around like objects. Functions can be also be returned as local variables (closures) and in strict mode, they bleed ‘undefined’ profusely. All good, then what exactly is an callback ?

Callbacks are functions that are executed asynchronously, or at a later time. Instead of the code reading top to bottom procedurally, async programs may execute different functions at different times based on the order and speed that earlier functions like http requests or file system reads happen. (ref:art-of-node#callbacks)

Best explanation I found:
Mike Vollmer did an fantastic job in explaining what are callbacks & how callbacks are used to do things asynchronously in javascript vs. traditional programming languages.

In addition,The Difference Between Call() and Apply() in Javascript would further clarify operations on callback. (ex: callback-apply.js). Another simple explanation: .

Key points noted are:

  • explicitly making sure callback is a function before use.  (typeof(callback) === ‘function’)
  • callback executes after the asynchronous action begins, but NOT before it completes (Not always) (ex: callback-timing.js).

For well versed javascript coders, it must be pretty basic stuff, but this has been an shift in programming paradigm for me. I do use callbacks and anti-pattern libraries like async.js for node modules & yet sometimes I cannot wrap my head around these callbacks. Modularising code and getting more familiar with asynchronous programming and node.js patterns seems to be solution for the confusion… till then…I need to remember the callback daze..


Tagged with: ,
Posted in JavaScript, Node.JS

Blogging: Re-Resurrection

I am not a good blogger, (admitted). but I wanted to stick to the habit of writing/blogging regularly for several reasons, one of the primary being that “Writing makes you smarter“. Nathanmarz nailed it in his blog “You should blog even if you have no readers” . Expressing my ideas and experiences in an coherent way has been an challenge for me and I hope that by blogging regularly would provide me an opportunity to be better at it.

Inspired by some of my peer’s blogs, I started blogging early 2011 and was experimenting it. I could never make it a habit with endless excuses and this blog became dormant.

Its my goal to blog at least once a month and to keep blogging. Joel’s post “5 realizations that helped me write regularly” is one of my key inspirations to keep me focused. Thank you Joel.

Posted in Blogging

To set the Title for a BPEL instance Name in Oracle SOA 11G.

use ora:setCompositeInstanceTitle() in Java_Embedding or in an Assign Statement.

for example :

<assign name="assign_InstanceTitle">

puts the instance name as “LOGIN:User1” in the em console

Posted in ORACLE SOA 11G, Oracle SOA BPEL, SOA BPEL 11g

Prevent CSRF (Cross Site Request Forgery) Attacks in SharePoint Application Pages.

Cross-Site Request Forgery (CSRF) is an attack outlined in the OWASP Top 10 whereby a malicious website will send a request to a web application that a user is already authenticated against from a different website.  Much detailed & better explanation is here

To prevent CSRF attacks in SharePoint application pages, which POST’s (http) data to the server, use SharePoint FormDigest Control. This FormDigest Control inserts a generated digest (token) into the form page, when it is requested (usually through GET )& in the code behind we can validate this token using SPUtility.ValidateFormDigest()to make sure that the form/page is not tampered with.  Its a good practice to validate the FormDigest in the code behind, which writes data to the DB/Server/SP list,..ideally any write operation that uses  RunWithElevatedPrivileges . Two steps:

1. Initialize FormDigest control in the custom application page.

 <SharePoint:FormDigest runat="server"/>

2. Check for


in the code behind POST methods of application pages to make sure that the form is not tampered with.

Posted in C#, Sharepoint 2010

Deploying referenced project assemblies to GAC through sharepoint WSP

To deploy referenced project assemblies to GAC through SharePoint WSP:

1. Open the Package designer in the SharePoint project.
2. Select the Advanced tab.
3. Click the Add button.
4. Select the Add Assembly from Project Output menu item.
5. Use the Source Project dropdown to select which project in your solution should have its assembly included.
6. Make sure the Deployment Target is set to GlobalAssemblyCache.
7. Click OK, Build & Deploy the Solution, the referenced assemblies should be in GAC.


Posted in Sharepoint 2010

Get maxPwdAge for a Domain in AD.

Get Domain level directory entry with username/password, get the property value for ‘maxPwdAge‘ (which would be System.__ComObject)
Convert System.__ComObject to datetime/int.
We have to use COM Interop Libraries for this one, ActiveDs.dll (you can find it on the web)

System.Int64 largeInt=0;
IADsLargeInteger int64Val = (IADsLargeInteger) ent.Properties["maxPwdAge"].Value;
largeInt = int64Val.HighPart * 0x100000000 + int64Val.LowPart;
long ticks = Math.Abs((long)largeInt);
TimeSpan passwordAge = TimeSpan.FromTicks(ticks);
Console.WriteLine("PasswordAge={0}",passwordAge );
Console.WriteLine("PasswordAge in Days={0}", passwordAge.Days);

For more information on converting Large Integer Property Type, please check

Posted in Active Directory, C#

“Please close SPWeb objects when you are done with all objects obtained from them, but not before”

DO NOT use SPList directly from methods in webparts & application pages. SPList is a sharepoint object & will instantiate a new SPWeb Object,
if used outside of its parent SPweb object. Always perform operation on SPObjects with in the SPWeb(parent SPObject) context.

or else
We will get the exception with this message : “Please close SPWeb objects when you are done with all objects obtained from them, but not before

Muchos Muchos Gracias to Jonas for the explanation & pattern in this article 

Posted in Sharepoint 2010

Anonymous Custom Application Pages in SharePoint Sites.

We sometimes want custom application pages in SharePoint solution , which needs to be enabled for anonymous access, for example: SiteLogin.aspx or AppError.aspx. By default, when we create an custom application page in visual studio in a SharePoint 2010 solution, it inherits from Microsoft.SharePoint.WebControls.LayoutsBasePage . so by default this custom application page needs login

To make an application page anonymous, just Inherit from Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase & override AllowAnonymousAccess()  property to return true;

Posted in C#, Sharepoint 2010

Recycle IIS Application Pool’: 0x80070005Access denied

While deploying SharePoint 2010 solution from Visual Studio 2010, we often stumble upon the below deployment error:

Recycle IIS Application Pool’: <nativehr>0x80070005</nativehr><nativestack></nativestack>Access denied

Solution: The Deploy Solution user that is running the visual Studio needs to be site collection Admin on the site , in my case, its Domain\Administrator

Posted in Sharepoint 2010, Visual Studio

Extending the Active Directory User Schema

Active Directory user schema has enough properties/attributes to cover most user profile information, but in some cases , we might need to extend this schema to add our own custom attributes. Microsoft Active Directory provides this capability to customize the user schema at various domain/forest hierarchy levels. The below article was tremendously helpful for us to achieve this. Thanks a lot Kurt Hudson.

Unique X.500 Object Id: is an  unique object identifier for an attribute. This is NOT auto-generated when extending user schema, we need to come up with one or use this script to generate one. For more information, please check Obtaining an Object Identifier from Microsoft

Posted in Active Directory, Sharepoint 2010
  • RT @KCTrades_: Powerball over $1 billion 🤯 I bought a bunch of tickets for tonight’s drawing! Everyone who likes & retweets this post will… 4 weeks ago
  • RT @TopTradingEdge: $SPY Market update as Market hit the resistance area $380 neckline of W pattern once that resistance breaks then we cou… 1 month ago
  • RT @TopTradingEdge: NETFLIX $NFLX EARNINGS EPS $3.10 Beats $2.13 Estimate Sales $7.93B Beat $7.84B Estimate 1 month ago
  • RT @TopTradingEdge: $SPY Market update as Market filled the gap left two weeks ago "island gap" I notice more short covering today than reg… 1 month ago
  • RT @TopTradingEdge: $SPY Market update as Market in compression mode until gap to fill at $372 and waiting for earning to start and rake t… 1 month ago
%d bloggers like this: