Simple Chat Application Using Jaggery Framework

In this blog post, it’s going to guide you through the steps which involve in creating a simple chat application using WSO2‘s Jaggery Framework.

What is Jaggery?

Jaggery is a framework, which offers a completely Javascript way to write all parts of Web applications and services as a way to minimize impedance mismatches across different layers of the Web application and API development experience while closing the gap between Web apps from Web services by allowing one to create both applications and APIs at the same time.

Functionality of the Chat Application

In this tutorial, it will only focus on providing these basic requirements for the Chat application.

  • Create a chat room with a unique id.
  • Join existing chat-room using it’s unique id.
  • Have multiple chat rooms opened in multiple tabs.
  • Kick off users from the chat room.

Continue reading Simple Chat Application Using Jaggery Framework

How to create a Persistable Dictionary in Python

I came across a situation where I had to implement a Python class which can;

  • handle dynamic attributes
  • can be initialized with a dictionary
  • can be persisted on the local storage as a file
  • can be used as a dictionary as well as a object. ( allow both  foo['key']  and  foo.key  to access its attributes )

So I came up with this Class. It inherits from python’s built in Dictionary class ( dict ). Therefore it can be initialized with an existing dictionary.  And it also overrides  __getattr__   __setattr__  __delattr__ . Therefore it can handle dynamic attributes and act as a dictionary as well as a object. Finally It uses Python’s cPickle to serialize and persist it self in the local storage.

Please share your thoughts on this approach. 🙂

Iterate and Initialize all sub classes in python

In various situations, we need a mechanism to Initialize all Sub classes for a given Super class. For instance, let’s assume that we have a Super class called ArithmeticOperation and another 4 classes derived from it (Addition, Subtraction, Multiplication and Division).

One way of doing it is Initializing each Sub class separately.

But if there are hundreds of Sub classes, we need to think of another mechanism.  That’s where .__subclasses__() becomes very useful. We can use that method to Iterate and Initialize all Sub classes for that given Super Class. You can do it like this,

Hope this post helped someone who’s looking for a way to Iterate and Initialize all Sub classes for a given Super Class using python. 🙂

 

How to use ( set, get, delete ) cookies in JavaScript

In this post you can find to how to set, get (retrieve) and delete cookies using JavaScript. This might comes in handy when you want to securely  store small amount in the client side.

 

Working example : click here

 

 

Shuffle an array in javascript

This code snippet can be use to Shuffle an array in JavaScript.

working example : http://jsfiddle.net/grainier/J4BuD/