Kushal Likhi

Javascript/Ajax/JQuery, Node.js

Defining custom errors – NodeJS

Any well written piece of code should be defensive by nature with defensive error handling understanding that things could go wrong. Things would be great if we can define our own custom error classes which we can pass or throw in order to distinguish various errors. Custom error constructors helps in: ⇒   Identifying...

23-Jun-2014

Javascript/Ajax/JQuery, Node.js

JavaScript: Hex String To Int64 conversion (similar to Int64.parse)

Recently in our Node.js application we had a task where we needed to convert the Windows hexadecimal Live Id (lid) to sighed 64 bit Integer such that it can be used in the API calls. But there was no direct way to convert that in JavaScript, but here i will discuss the workaround we took.   The problem with 64 bit Integer in...

30-Dec-2012

HTML/UI/CSS

HTML5 Offline Applications – IndicThreads Conference PPT

Hi,   Recently i presented in "IndicThreads 2012" conference on the topic "HTML 5 Offline Applications".   You can view the slides at Slideshare at: http://www.slideshare.net/kushallikhi/indic-threads-delhisessionhtml5-offline-applications   Topics which are discussed in this presentation are: Desktop Vs...

31-Oct-2012

Grails

Cool way to get/set processed HTML Markup in filters

Hi,   There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used:   Note: This is just an example, you can use this concept to do thousands of cool things, like: pdf export...

27-Sep-2012

Grails

Fire Plugin OnChange/onConfigChange Event at Run Time Manually

Hi,   Suppose you have implemented some logic in your application which updates the Config at runtime.   Now after you have updated the config, you should notify the plugins about configChanges such that they reload their configurations. This can be done by firing the onConfigChange Event of the plugins.   Similarly...

26-Sep-2012

Javascript/Ajax/JQuery

JavaScript: Currying in JavaScript

Hi,   Currying is a very simple and useful concept in JavaScript. Here we can set the context of the function to any object or variable.   So let us study this concept using the practical examples and code as follows: [js] //Let us first create a function "curry" function curry(thisObject, func){ return...

25-Sep-2012

Javascript/Ajax/JQuery

JavaScript: Replacing Logically using String:replace() method

Hi,   When working with JavaScript, we might sometimes require to run some regEx on a string and replace its matches logically. This can be easily done using the String:replace() method.   Lets Take an example to understand the concept: Suppose we want to write a function which converts the normal string to CamelCase...

25-Sep-2012

Grails

Inject Methods/Properties to be available in all GSP Pages

Hi,   There could be cases where we would need to inject some methods or properties in all GSP pages.   As we know that the GSP pages extends GroovyPage class, hence injecting properties/methods in GroovyPage class can solve out purpose.   Example: Lets add appVersion property and a method to provide logo link...

25-Sep-2012

Grails

Dollar-Slashy Strings in Groovy [Ver 1.8+]

Hi,   Groovy took another leap ahead in the methodology of defining Strings by providing us with "dollar-slashy" strings which further minimized the need of escaping any special character as compared to simple "slashy" Strings.   In the Groovy ver:1.8+ you can define Strings as follows: [java] //A dollar-slashy string ...

25-Sep-2012

Grails

GDSL Awesomeness – Setting a global context

Hi, Sometimes we need to set the context for the GDSL contributor to all the possible files and scripts in the project scope. This is a rare case scenario, but could be handy on some implementations.   This can be done by two techniques: Ignoring all filters passed to the "context" method. Setting the "ctype"...

25-Sep-2012

Grails

GDSL Awesomeness – Introduction to GDSL in IntelliJ Idea

One of the disadvantage of using meta-programming and DSL is that we don't get auto-completes in Our IDE. Hence IntelliJ provided us with an awesome and intelligent toolkit to handle dynamic properties and methods when writing code in groovy. In IntelliJ IDEA we can write GDSL Files in order to give us the auto-completes(code...

25-Sep-2012

Grails

GDSL Awesomeness – Defining dynamic properties in a class

We can define dynamic properties in a class as follows:   Suppose we have injected a property named "UTCTimeInMills" in Date class which is of type "long". Now we need to enable syntax hinting for it, We can do it as follows: (See inline comments for description) [java] //First we need to define a context def...

24-Sep-2012