Monday, April 28, 2025

My ranking during algorithm contest

My Coding Contests

My TopCoder Contests

Slime harvester

This one have cool GUI, cool multi-agent problem. It creates a distributed environment where the **thread affinity** is a thing. Here is my code in github.

My HackerRank Contests

Contest Solved Rank
Week of Code 37 5/6 181

My LeetCode Contests

2025

Contest Solved Rank
Weekly Contest 432 3/4 413
Biweekly Contest 152 3/4 536

2024

Contest Solved Rank
Weekly Contest 385 3/4 925
Weekly Contest 390 4/4 866
Weekly Contest 402 4/4 753
Biweekly Contest 146 3/4 823
Weekly Contest 429 4/4 567

2023

Contest Solved Rank
Weekly Contest 343 3/4 546
Biweekly Contest 105 4/4 752
Weekly Contest 347 4/4 630
Weekly Contest 368 4/4 316
Weekly Contest 369 3/4 992

2022

Contest Solved Rank
Weekly Contest 296 4/4 826
Biweekly Contest 81 4/4 738
Weekly Contest 322 4/4 287
Weekly Contest 326 4/4 886
Weekly Contest 329 4/4 868
Weekly Contest 333 3/4 583

2021

Contest Solved Rank
Weekly Contest 229 4/4 529
Biweekly Contest 49 3/4 829
Weekly Contest 235 3/4 741
Weekly Contest 237 4/4 902
Biweekly Contest 59 3/4 343
Weekly Contest 255 3/4 434
Weekly Contest 256 3/4 793
Weekly Contest 259 3/4 729
Weekly Contest 267 4/4 556
Weekly Contest 269 4/4 211
Weekly Contest 273 4/4 730
Weekly Contest 283 4/4 1090

2020

Contest Solved Rank
Weekly Contest 221 3/4 900
Weekly Contest 227 3/4 877

Monday, March 10, 2025

Min Treap on top of a Segment tree

As we know treap is the combination of Tree and Heap. It is a tree like structure that has a rigid order when traversed. We can find the lowest value or the lower value than K near a given position.

Treap

Tree Structure
  • As heap it contains the smallest item near the root.
  • As tree, when traversed in-order, it gives the items in sequential order we inserted them. That means that we can insert an item at certain position.
Benefits
We can find the lowest value or the lower value than `K` **near** a given position.
Drawbacks
Treap is not a balanced tree. So the cost of lookup is not always logN.

Treap on top of a Segment Tree

Segment tree structure
  • It has all the values in the leaves.
  • All internal nodes that are not leaves contains the minimum value in the subtree.
Benefits
The query is logN.
Drawbacks
My implementation is fixed size.

My treap

The full implementation is here in this project. You are welcome to try this for example in this problem,

Sunday, March 27, 2016

Summary of Algorithms

This page is moved to [github](https://github.com/kamanashisroy/algosnippet/blob/master/algorithms_summary.md). There I am doing bug-fixes and adding with new things that I learn.

Sunday, February 14, 2016

JavaScript will evolve faster as a language than a compile target

Author:Kamanashis Roy
Note: I wrote this blog on request

JavaScript survived and thrived to be one of the most popular language for web development. There was concern over the best-practice and performance issue in JavaScript. Some people went further to say JavaScript language is Buggy. But it served it’s purpose as client-side scripting.

The main criticisms against JavaScript were,
- JavaScript has fragmented implementation( because of the lack of standardization and the browser-war.)
- Standardization that resulted JavaScript to be compiler target rather than a language itself.
- JavaScript is slow.

The criticism against the JavaScript gave rise to compilers that target it. These source-to-source compilers generate acceptable JavaScript code. One of them being Google Web Toolkit. It generates JavaScript from Java. The idea is to impose the best practices. Again after standardization and wide-spread acceptance of JavaScript there have been development in source-to-source compilers that target JavaScript. But JavaScript eventually is more popular for web-development than those compiled language. Let’s see how JavaScript got away with the criticisms.

Fragmented implementation and lack of standardization

The browser-war gave rise to reversed-engineered implementations of JavaScript. And individual programmers could not effort time to write JavaScript for each browser. So some people preferred to generate automated code for different browsers using compilers.

To solve the problem Netscape allowed it to be standardized as ECMAScript. Now there are multiple open-source implementations of JavaScript. And the most popular of them uses Just-in-time compilation. So it provides better opportunity to write uniform code for the developers. Again there are frameworks like jquery that wrap the platform depended code to give an uniform API. Finally the fragmentation is not a problem anymore.

Standardization that resulted javaScript to be compiler target

Again the cross-browser compatibility of javaScript gave the rise of source-to-source compilers (such as Emscripten) that target asm.js and NaCl. The asm.js is precompiled(ahead-of-time compilation) javaScript that allow the browser to run asm.js based application much faster.

JavaScript is slow

JavaScript performance is affected for varied reason. One of them being the support for dynamic type. Another being the dynamic binding. There are ways to get away with this things. The V8 engine actually uses JIT compiler that compiles the javaScript into native code on runtime, instead of interpreting. And the V8 developers compare the JavaScript performance with C/C++. They have some best practice suggestions about JavaScript. The idea boil down to ,

  • not to use undefined rather use static types,
  • to avoid arrays of varying types,
  • finally to use less constructors and initialize all the variables in the constructors.

The poor coding can be identified by some static analysis. And these tools can be integrated in the IDE and browser. This way the programmers get notified of the performance issues.

Frameworks are the right way

Now there are some emerging trends of development regarding JavaScript. It is done by some frameworks and runtimes. Some of them are,

  • jquery(It is more like library than a framework with easy-to-use API with a lot of open-source modules),
  • prototypejs,
  • threeJS,
  • reactJS,
  • backboneJS
  • nodeJS(Not a framework but a runtime for server-side-javascript and desktop application, it features a lot of packages/modules as npm),

Some of them are domain specific and some are for general use. These frameworks feature popular programming patterns for object based language. They allow us to use those well-written patterns. It makes the user code small. It is like “write less do more”. Less code gives less bugs and may be less performance hazards. In that sense less is good. Again these frameworks allow us to write browser independent code. These frameworks also take advantage of the ahead of time compilation. This is why they are immensely popular.

A note on nodeJS

NodeJS is the JavaScript runtime that works on the vast range of platforms. It uses event-driven approach of concurrent programming which is closely relates to observer-pattern that is popular in Object-Oriented paradigm. There were a lot of issue dealing the concurrency and scalalibity in server-side scripting. NodeJS was keen to solve the problem in event-driven way. And as JavaScript is already popular in the web-development arena, NodeJS got huge success. It is supported by big companies. And there is an package-ecosystem, npm, based on nodeJS.

Again there are a lot of frameworks that work on top of NodeJS. Some of them being Express.js, Socket.io and Koa.js. And there is popular Atom IDE(runs over ioJS/(nodeJS variant) runtime) that support development based on NodeJS and JavasCript.

Future

As a C developer, I want to share that I like C so much. But I also knew that it contains a lot of blotted code. It makes things harder because it does not have a memory manager. But one intriguing thing about C is the portability as the ability to compile it in wide range of platforms, in the same way JavaScript has portability in the browser.

I worked on those things and I wrote a compiler that eventually generates C code out of Object-Oriented garbage collected code. And I grew some framework to support server-side development. I targeted C the same way that the source-to-source compilers target JavaScript.

But sometimes I get back to C for some reason. I discovered that my framework written in C also support doing cool things with small dependable code. I think my compiled-framework gave me greater understanding of cool stuff in C.

I think the compilers targeting the JavaScript are also giving new directions for JavaScript based development. JavaScript is now getting developer attractions by featuring runtimes, frameworks and IDEs. In fact there are a lot of packages available on these frameworks. Now they are also being used as desktop tools(GUI), command-line application and server-side scripting.

Wednesday, February 3, 2016

Memory profiler for shotodol framework

C programming language does not come up with garbage collector. It is not object oriented. But C is inevitable. C programs are portable into different platform. A lot of libraries and server applications are written in C. The Aroop compiler gives the developer flexibility to write object oriented Vala code that can generate C code. Likewise it is also possible to use existing C library in Vala code.

So Aroop is the source-to-source compiler. It compiles Vala code into C. The Aroop compiler is a fork of original Vala compiler. The Vala compiler generates code that uses the GObject library to represent the Object data. On the contrary the Aroop uses object pools.

Shotodol is an application framework based on Aroop compiler. It has instrumentations for memory profiling, dependency injection and more. In this blog we will disect the memory profiling feature.

The profiler can give the memory usage of specific module, it can dump existing string allocations and more.

help prof
Executing:help prof
<            help> -----------------------------------------------------------------
SYNOPSIS:
    profiler
         -heap          <none>  Show all the memory allocated in all the factories
       -string          <none>  Dump the string buffers
       -object          <none>  Show the objects
       -module          <text>  Select/filter out a module
<      Successful> -----------------------------------------------------------------

For example, if we investigate the memory usage of “core/console” module, we get the following.

prof -module core/console
Executing:prof -module core/console
<        profiler> -----------------------------------------------------------------
Source               Line  Module     -- pools      allocated  used       objects    slots      bitstring  pool size 
vsrc/ConsoleCommand.  2116 core/conso --          0          0          0          0          0         56         16
vsrc/ConsoleCommand.   954 core/conso --          0          0          0          0          0         56         16
vsrc/ConsoleCommand.   804 core/conso --          1      13792       8560         10         10         56         16
13792 bytes total, 8560 bytes used
<      Successful> -----------------------------------------------------------------

The table above says the line number where the memory pools are created. “vsrc/ConsoleCommand.c” is the generated C source. The pool allocates 16(it is set when the pool is created) slots at a time. Each slot size is assigned when the pool is created. The first two rows say that the pool is empty. The last row says that it contains 10 objects taking total 8KB space while the pool has 13KB(16 slots) allocated. And it says there is only one pool.

The profiling helps to set the optimal pool size. In optimal condition the pool does not waste too much unused memory and there is less system-call for malloc for pool creation.

It also identifies the memory leak or circular refernce that can invalidate garbage collection. This feature is particularly useful in the server application. In that scenario memory-leak is not desirable at all.

I hope to describe other shotodol features in the future. I just like to explain what the cool things it does.

Monday, February 1, 2016

Line of code

It is nice to have some numbers associated with my identity. I like the numbers and I like to define myself. As a part of that I did a project of know “which language you are”.

I admire the cloc application. It calculates the line of code out of an archive. Line of code gives a number that measure the amount of work. In that sense my work summary is as below.

File files blank comment code
libsync.txt 241 8649 9998 56467
aroop.txt 256 3561 2506 22042
miniim.txt 88 1757 3824 8572
shotodol.txt 134 574 867 6564
roopkotha.txt 66 737 990 4903
opp_factory.txt 23 517 308 3875
roopkotha_vela.txt 56 302 638 2689
hciplus.txt 29 207 141 2089
barrel.txt 47 270 135 1864
shotodol_net.txt 20 115 161 1454
shotodol_web.txt 20 116 189 1151
shotodol_db.txt 12 74 122 689
shotodol_script.txt 8 34 39 354
shotodol_media.txt 2 12 20 100
SUM: 1002 16925 19938 112813

That is glorious. 112K lines of code is big work. Needless to say, it only calculates major works.

Language files blank comment code
C 127 8070 7770 58476
Vala 424 3483 3279 27305
C/C++ Header 171 1662 3710 6752
Java 30 830 2867 3868
Vala Header 19 283 245 3387
C++ 16 448 589 2959
PHP 46 272 173 1907
CSS 19 372 138 1789
XHTML 26 325 62 1463
JavaScript 13 238 727 1438
make 66 571 50 1423
Lua 25 198 110 1252
Bourne Shell 7 51 93 221
Ant 2 22 28 155
m4 2 28 17 110
Perl 1 32 36 107
Assembly 2 14 41 84
HTML 2 6 0 41
XML 1 0 3 27
Bourne Again Shell 1 9 0 24
NAnt script 1 9 0 23
DOS Batch 1 2 0 2
SUM: 1002 16925 19938 112813

I also wrote small script to generate pie chart out of this data.

pie

Saturday, January 3, 2015

The dart experiment

Something to measure, the objective study

The darts game is very simple. But it takes a lot of attention or sagacity or something to perform better. Additionally it has a way to get numbers for measuring. I was trying to measure the something in effect of some activity.

Our world is a chaos

The relation of cause and effect is very hard to associate when our practical world is full of chaos. For example, eating something or doing something may or may not affect the something straight-forward. There are so many things interacting each other.

But there are measurements

I did the experiment for fun. Though I have a vogue intention to find the causality. I kept the records of the events and how they affect the performance of the darts game. The events are given below,

  1. Eating rice, cauliflower, soya nugget, olive oil, spinach, orange dish.
  2. Eating areca nut.
  3. Cognitive task and swimming.
  4. Meditation.
  5. Rosemary tea.
  6. Tea.
  7. Super-food.
  8. Coding.
  9. Song and dance.
  10. Late night. (The idea was to find if I am night owl or morning person.)

The result

The result shows that my performance peaked after song and dance. I do not know if the result is something to do with song and dance. I do not know if the effect is reproducible. But I know that there is an effect called the mozart-effect. I assume that did the trick.

Life is not darts game but a guided missile

The something we measure here may or may not have great effect in life. One important thing to note that life is more like guided missile than a simple dart. Once born we have inner power to change our path. And there are a lot more skills than just throwing the dart.

More

The results are affected by the causes that have immediate effects. But the things that take hours, months or more cannot be traced in this way of experiment. It may or may not demonstrate the effects of stimulants like tea or coffee or songs in short-term. I hope to come with more experiments on darts game, especially with the reproducibility of the effects. It is very interesting.

Thursday, December 18, 2014

Drupal plugin

Drupal is a PHP content-management framework for web development. The popularity of drupal is evident in the vast community and contributed modules. The popularity comes from the ease of customization and simplicity of design. In this article the plugins of drupal aka the `modules` are analyzed. This is a continuous effort to investigate plugins in different projects.

Drupal modules are grouped into a folder/directory named after that module. The directory contains the following files,

  • .info file. The content of the .info file enable us to know about the module without loading it or installing it. These informations are kept in key-value pairs. They contain the name, description, version, package and testing information etc.
  • .module file. This is a PHP script containing primarily the hooks that needs to be loaded when the page is hit. To write a drupal module one must write the .module file and write at least one hook function.
  • .install file. This file is used only for installation and uninstallation. They may create database or do other tasks that are done at the time of installations. It contain the _install and _uninstall hooks.
  • .inc files. These files are loaded on demand. They are PHP sources containing instructions which is not needed in every page hit.

There are other files for testing and for command line operations. But those are not covered here. The cardinal part of the module is in the .module file. It contains function definitions. The function names are identified by the hooks using the PHP reflection feature. For example, a module can add menu by writing the following functions.

function mymodule_menu() {
    $items['abc/def'] = array(
        'page callback' => 'mymodule_abc_view',
    );
    return $items;
}
function mymodule_abc_view() {
    return "Here is the abc content";
}

The above code is for module named mymodule. So the menu hook is the function named mymodule_menu. It is derived by prefixing the module name before _menu. And the return value of the hook is the array containing the menu items and the functions to be called on the menu hit. The ‘abc/def’ is the menu path identifying a page. It appears on the address bar of the browser.

All the _menu hooks can be called and executed by module_invoke_all function. It is possible to call user defined hooks to be populated by other modules.

function module_invoke_all($hook) {
  $args = func_get_args();
  // Remove $hook from the arguments.
  unset($args[0]);
  $return = array();
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    if (function_exists($function)) {
      $result = call_user_func_array($function, $args);
      if (isset($result) && is_array($result)) {
        $return = array_merge_recursive($return, $result);
      }
      elseif (isset($result)) {
        $return[] = $result;
      }
    }
  }

  return $return;
}

In the code above the function name is created by code $function = $module . '_' . $hook;. So it is conjunction of the module name and the hook name. The function above is responsible to call all the hooks of the loaded modules.

Now let us investigate the blog module.

The purpose of this module

The blog.info file contains the description of the module. It enables blogging for drupal users.

Loading and unloading

The blog.install contains blog_install and blog_uninstall functions which are the _install and _uninstall hooks.

The blog_install() alters the blog node and adds body field for it. The node is the parent object and it has it’s own defined way to save, load and render data. The blog is kind of subclass of the node. Anyway the abstraction of node is not covered here.

The blog_uninstall() just deletes unnecessary variable.

Note that the blog_install() function is called while installing and blog_uninstall() is called while uninstalling. But they are not called in each page hit. While in each page hit the blog.module file is parsed but none of them are executed.

Extension points

The blog_menu function defined in blog.module file is the _menu hook. Here _menu is the extension point. This hook is called when the module is enabled for use. Once called the total menu tree is built and kept in the database. It is not executed in per page hit.

/**
 * Implements hook_menu().
 */
function blog_menu() {
  $items['blog'] = array(
    'title' => 'Blogs',
    'page callback' => 'blog_page_last',
    'access arguments' => array('access content'),
    'type' => MENU_SUGGESTED_ITEM,
    'file' => 'blog.pages.inc',
  );
  $items['blog/%user_uid_optional'] = array(
    'title' => 'My blog',
    'page callback' => 'blog_page_user',
    'page arguments' => array(1),
    'access callback' => 'blog_page_user_access',
    'access arguments' => array(1),
    'file' => 'blog.pages.inc',
  );
  $items['blog/%user/feed'] = array(
    'title' => 'Blogs',
    'page callback' => 'blog_feed_user',
    'page arguments' => array(1),
    'access callback' => 'blog_page_user_access',
    'access arguments' => array(1),
    'type' => MENU_CALLBACK,
    'file' => 'blog.pages.inc',
  );
  $items['blog/feed'] = array(
    'title' => 'Blogs',
    'page callback' => 'blog_feed_last',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    'file' => 'blog.pages.inc',
  );

  return $items;
}

Note that the menu has it’s own plugin-system and the extension-points. The blog, blog/%user_uid_optional, blog/%user/feed and blog/feed are the extension-points aka paths of menu-plugin-system. And blog_page_last, blog_page_user, blog_feed_user and blog_feed_last are the hooks registered in those extension-points respectively. This is an added twist in drupal architecture. It decouples the menu-extension-points from the core extension-points. This makes it flexible and separable.

And with added benefits these menu related hooks and callbacks are defined in separate file named blog.pages.inc to make the blog.module slimmer. The blog.pages.inc file is loaded when the related pages are loaded. Thus it reduces the processing time too.

Summary

Drupal project is based on functional programming in PHP. It still affords complex architecture and development needs. The reflection property of PHP function makes the hooking effortless. The analytic minds are tuned to find dumb instruments in the code. Drupal is very compulsive in that sense.

Saturday, November 22, 2014

Avoid distractions, practice internet fasting

Civilization is built in free time

Technology is the capstone of human civilization. At the advent of civilization we learned to use fire. We learned to cook. And cooking made the nutritions available to our body in less time and effort. This gave us time to think about other things, like art, culture and technology. We can now save a lot of our time using the technology. We can shop online, we can go places in cars or by trains. These all save our time and give us more time to think about us and to think about other ideas.

Now distractions are eating our time

On the other hand humans build habits, they are prone to classical conditioning. Today we are doped with the connecting technology. In the same way the over-nutrition caused us to become overweight and predisposed to some diseases; the overuse of social networking sites and internet made us occupied with social thoughts. We certainly lost our ability to wait and the ability to pursue a goal for a long time. Our personal tasks are overshadowed by the thoughts of society, politics and news-channels. The internet has made it easy to create and publish more information. Our desire for more online information caused information anxiety. And provided that anxiety we used up a lot of time gathering those informations. This resulted in reduced productive time and increased procrastinations.

Time is short and attention is limited resource

Life is short. This makes our attention limited. So we need to choose what we care most. We need to have a plan. And we need a sense of control. There are people who use the laws of economy to understand attention. And they call it attention economy. I find it very interesting.

Know thyself

In the earlier blog I talked about self profiling. We can use that profiling to measure the outcome of a month. In this way we can find what we are lacking and what we are overusing.

Formulating the solution

As I figured out that I spend a lot of time online, I formulated a simple solution. Too many of things are bad. Like in old days saints abstained themselves from food, we need to practice austerity using internet. It is like internet-fasting. We need to practice a ‘no-internet-day’ to edify our ability to think of ourselves.

Tuesday, October 21, 2014

Plugin and object oriented programming

Object oriented programming has the features like class, object, abstraction, encapsulation, polymorphism, inheritance. Interestingly plugin has some of those features. This is a continuous effort to investigate plugins.

Object

A plugin is simply a singleton object. It can be initiated and destroyed. And the registered extensions are it’s fields in analogy to an object.

Abstraction

Plugin can use any named extensions even they are not registered by any actions. In this way they are less specific and abstract. For example, an application lets plugin to do certain things before exit. And it executes the actions under the onQuit extension point. Initially it can be empty.

On some point of execution a new plugin may be loaded that registers action to onQuit. Suppose the action is just to print Good Bye on the screen. So before the application exists it executes the action registered at onQuit and eventually it says Good Bye to the user.

Encapsulation

Encapsulation makes your code more flexible, because the developer is not concerned about who is using the inner code. And the inner code can be changed anytime without modifying the other plugins. It is like advertising less makes things flexible(less is beautiful). Plugin just hides its internal code blocks as they are not registered to any extension point.

Inheritance

Plugin has the basic feature of overriding. It lets a code block to register to an extension point. In this way it overrides the behavior of that extension point.

Suppose in the earlier example, we load a new plugin which overrides the onQuit with action to print See You. In that case the application may execute both the actions before exit resulting it to say Good Bye See You .

Polymorphism

Polymorphism is the idea of abstraction. It is the idea that the behavior of the code may be changed. And Plugin has this idea too. Different plugins make the application behave in different way. In the earlier example of inheritance, the behavior is changed from doing nothing to saying Good Bye and to saying Good Bye See You before exit.

Advantages of plugins over object oriented design

  • Object oriented programming is sometimes a mess. Plugins are good point of decoupling. The figure below shows the idea.

Readings

SOLID
Philosophies

Monday, October 20, 2014

Ejabberd plugin

Ejabberd is very popular scalable XMPP server. This server is an instant messaging or chatting server. It is written in erlang. It implements it’s features in forms of modules. These modules can be seen as plugins. Here is how it works. This is our continuous effort to investigate plugins in different projects.

Here the mod_last is taken as example. Most of the modules here in ejabberd are small and less than 500 lines. Here is a small window of the output of find -iname "mod_*.erl" | xargs wc in linux shell. The values in left column are the number of lines.

....
    198     825    8244 ./src/mod_echo.erl
    173     566    5827 ./src/mod_proxy65_sm.erl
    682    1991   22312 ./src/mod_register.erl
    351    1082   11792 ./src/mod_last.erl
   1463    4336   48959 ./src/mod_shared_roster.erl
   1347    3897   45857 ./src/mod_irc.erl
    270    1087   10304 ./src/mod_carboncopy.erl
    109     380    3650 ./src/mod_time.erl
     97     330    3437 ./src/mod_service_log.erl
....

It is interesting that mod_last contains only 351 lines of code including the code comments. So this file will be easy to follow.

The purpose of this module

This module keeps a record of the time when a person is last seen online.

Loading and unloading

The modules here are loadable. They have a start and stop functions to initiate and deinitialize them. The start function takes two arguments and stop takes one argument.

Extension points

The start function here registers hook for following events.

  • unset_presence_hook
    The on_presence_update function is called when user is logged out of server. It just stores the time entry in the database.
    ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE,
                       on_presence_update, 50).
on_presence_update(User, Server, _Resource, Status) ->
    TimeStamp = now_to_seconds(now()),
    store_last_info(User, Server, TimeStamp, Status).
  • remove_user
    When the user is removed permanently from server he is deleted from last_activity database.
    ejabberd_hooks:add(remove_user, Host, ?MODULE,
                       remove_user, 50),

There are other hooks that answer the user activity information and do other things.

Summary

This is very interesting to see how small the code is. And it is very precise too. Programmers will love to write modules here. It can be given 500 points for the mechanism (there will be more points coming for other projects). Thanks to erlang, nice language.

Thursday, September 18, 2014

Plugin

Plugins are features added out of box. It is not needed to know all the internals of an application to write a new plugin. And the application does not need to know about the feature internals. The new plugin feature is called the extension to the existing software. To make the total thing work, the extensions are registered to an extension point.

There are two things that incorporate plugin.

  • Loadable separate code.
  • Features/extensions that are registered at some extension point.

Example of a plugin

Suppose there is a need for feature to share a webpage content as emails. The feature is to send email with less interaction from the user. The user does not need to open a web application interface in the browser to send email. The feature can be implemented by a email plugin of the browser. The email plugin may insert a ‘send page’ button through registering in menu-item-extension point. And when the user clicks the ‘send page’ button from the browser-menu it opens up few text-boxes. Eventually the user types the address and subject and presses the send button to send the email.

Here is a component diagram to demonstrate the idea,

This is an email sending feature that is implemented by email plugin. And the plugin registers in menu-item-extension point. The plugin know very little about the core features or other plugins. And the core application does not know the internals of the plugin at all.

Actually this type of plugin exists for firefox browser. For firefox the plugins are called addons. And there is an addon named send page. The code is available here.

<menupopup id="menu_FilePopup">
  <menuitem id="menu_sendpagebyemail" label="Send page by email..." key="spbe_sendPageKey" 
    oncommand="spbe_showDialog();" insertbefore="menu_sendLink" accesskey="e"/>
</menupopup>

The xul code above registers a menu-entry labeled ‘Send page by email…’ in popup menu.

Finally the addon is provided in distributable package which firefox can load easily on demand.

The plugin system makes it possible to implement the beautiful correlation above.

Modules and plugins

Plugins and modules come hand in hand. Both modules and plugins are pieces of code. Both of them emphasize on separation of concern. In a module certain things are grouped together for development-ease or other purposes. But in a plugin they incorporate a feature and the basic idea is separation from the core features.

Sometimes module loaders facilitate a way to load plugins. In this case modules are also special type of plugins. They are loaded in the invisible extension point of the application binary.

Advantages

Developing parts as plugins is a useful approach. It comes with some benefits.

Make little things work quickly and easily

Plugins are written to give some specific features. And their concerns are limited. So is the development time. This time-tuning is important because of human bias of instant gratification.

Additionally the separated code can be tested and debugged in absence of other features(of which it is not dependent). Thus separation helps development,debugging and testing units. For example, if it is needed to think of a feature to write a browser plugin to send email, then it is not needed to worry about other browser plugins like video player or something. In this way it is possible to be more focused and productive.

Plugins improve motivation

Plugins makes it possible to write a small separate segment of a big task. So it gives the satisfaction of achievement. Though it is a portion of big task, still it motivates to finish the unit. It helps the unit-bias of human psychology to finish an unit task.

Plugins and extension point mechanism makes things simple

Extending a big application is big cognitive load. To know all the internals is mandatory. Otherwise it can lead to bugs. And there is need to know the big APIs too. But in plugin the scope is small. It is not necessary to worry about the whole application but only the plugin-api. For example, to write an email sending feature for existing browser which has plugin support, it needs very little for the integration,

  • To know the plugin API. (To know the skeleton plugin that does nothing.)
  • To know how to add an extension.

Additionally, there are other things like showing an edit box and sending an email, but they have nothing to do with the core application.

OK, this is all about plugins now. In future, there will be discussions on how people facilitate plugins in their applications.

Wednesday, September 17, 2014

The extended mind

The brain and body is limited

Human has a limited brain and body. Though there are different thoughts and ideas that come into mind but pursuing them all is impossible. And even it is very difficult to reach a limited list of goals. One of the cause is the limited capability to remember all the tasks needed to be performed.

The brain is just like a computer

To a computer scientist the brain is comparable to a computer. And it has memory just like the computers. The memory can fall into two catagories,
- Short term memory or working memory(WM) in psychology is something more aligned to the RAM of the computer.
- Long term memory in psychology is like the hard disk.

On execution, thoughts and work processes are loaded in working memory to let it shuffle and get things done. For example, suppose a person is opening a lock with his key. At first, he thinks about the key in his pocket and grabs that in one hand, while he saves the goal(to open the lock) in the WM(working memory). And then he inserts the key into the lock to open it. This is easy.

Multitasking and context-switching problem

But the brain is not as good as the computer when it has to perform two cognitive tasks together. Suppose a person is thinking to open the lock and he has grasped the key in his hand. He has the goal to open the lock in his WM. At that very moment, someone calls him on the cell phone. The WM is full of the urgency of incoming call. As WM is limited, the thoughts to open the lock may be erased by the new information. He may mistakenly grab the key and put that in the ear. This may happen. Doing more than one cognitive task at a time may mess things up.

It is possible to extend the mind

For human it is hard to multitask. So the right thing is to do things one by one. If he has different things to do then it is helpful to maintain a list. A to-do-list. It is a small paper that holds your memory for future execution. In this way human can extend his mind.

People have used this idea of extended mind for long time. One of such extension is the written books. The books are the concepts of mind that are put into papers for recalling or for transmitting to people. Or the extended mind can be any written paper. Suppose someone wants to sum two big numbers (eg, 23874283 + 238479283742 = ? ). It may not be possible to do that using the WM only. But it is possible to do that easily using pencil and paper(like in the young days).

So it is a very old idea. Humans are curious about the inner working of themselves. To know the limitations is one way to know that. And to know the work-around is the novelty.

Monday, August 25, 2014

Profile thyself!

This is an idea to profile yourself. The idea is derived from three core thoughts ,

  • Know thyself.
  • We are what we repeatedly do.
  • You can only trust the numbers.

The three thoughts are connected. You see, you first understand you need to know yourself . Now who are you ? you are what you repeatedly do . And the way to know what you do repeatedly and how well you do that you need to count them. Finally you are inclined to profile yourself.

And there is a saying(not proved though) that doing something more than 10,000 hours may make you expert. I just want to know how many hours I do one such thing. So I profiled myself. Here is a page full of report.

There are other people trying this too,

Friday, December 16, 2011

Portfolio


MiniIM is messaging client for jabber/xmpp protocol. (Java2mobile edition) Try it here at desktop.
Get source here,
svn co https://miniim.svn.sourceforge.net/svnroot/miniim/trunk miniim_trunk
It renders xml(some that is used to minimize gui coding like qml) to gui on fly .

MiniIM is messaging client for jabber/xmpp protocol(rewritten in C, Qt).(UNFINISHED)
Get source here,
git clone git@github.com:kamanashisroy/miniim.git
The development platform is now debian linux. It uses Qt to render GUI . It includes a small memory manager that I call object pool plus. This memory library includes a lock-free queue (tested in production) . And It uses the Object Oriented notion in C .

Wednesday, December 10, 2008

Discussion Group

There is a new discussion group open for MiniIM project. Thanks go to google-group-team for such wonderful support. Vision, action and community support mean success.

Serializable kdom rocks

The kxml project means a lot for j2me. I have done some modification to make a document serializable in Recordstore. Here is the code. You can follow the usage examples in the code to make it work for you.

To use this code you just need to get the code from trunk. The obfuscator will skip the classes you do not use.

Browser features explained

Earlier I talked about my vision. In that application there are pages like "More", "About" they are rendered from markup files(more.xml, about.xml, ..) found here. They are following markup.dtd rules. Surely you can create documents on fly and work on DOM.

Note that it is svn-branch, the trunk is always containing the updated features.

And there are application-switches making it possible to interact with user. Here are the responsible code doing the magic.

The markup is not rich in features. It was good to follow an existing markup rule. I am hoping to do that in future. And I am keeping eye on w3.org for that.

Tuesday, December 9, 2008

XMPP client with browser-like features

I am back to j2me again. In my earlier attempt I was trying to render a WML content. Now I am here with a little advanced browser like feature to show web content. Note that I have dropped the idea of writing WML renderer. I have added a markup renderer. To be specific it can render a list of markup items. Here we can show on line content. It is stylable on compile-time.


Motivation
When I want to add some feature to my sweet application, it just gets bigger in size. And bigger size prevent it to work in low end mobile phones. So the idea is to write little j2me code and add most of the features in the servers. And here I am sharing the implementation of the idea in a hope that it gets richer and useful to you.

Similar efforts
There is something similar available in ZK project. And there is also a browser feature in j2mepolish project. I prefer mine, because I believe that it has very small footprint, it is light-weight(reuses objects) and I am willing to process any feature request that will suite this. Mobile Ajax is another interesting project.

Input fields
It has textbox, selection(multiple) box, checkbox, radio input ideas implemented. I am hoping to add some multimedia feature as well. Like an input box for image, sound etc and also playback of the media content.

Benchmark
It is tested on WTk monitor output that shows low object instantiation.

Caveats
It is using document parser from kxml project. The document and elements there uses vectors and it makes the parsing little slower. I am looking for some alternative to this.

Thinking forward
I think this is a step forward to social features. The next thing to do is to write web application to represent information from social sites. I am now looking for any kind of reusable component for this. I mean I am not trying to reinvent. And it is hard to maintain too. If you think you have nice idea or have something to say please feel free post comment or email me directly.

Additionally it has a IM framework to develop end to end application too.

Please consider testing MiniIM in your mobile.

Wednesday, August 6, 2008

Pidgin as instant messaging gateway

Pidgin is the most powerful IM client I have ever seen . This is because of the big community support and also because I am big fan of Mark Spencer :-P .. The libpurple (Pidgin/Finch core) library can be used as IM gateway . I implemented such gateway for event notification . Something like a bot .



It keeps libpurple connected to the IM servers of different protocol and takes message request from UNIX socket . For example the following code will send a message to Chitrangoda ..


#!/usr/bin/perl -w

use strict;
use Socket;

my $sock_file = $ARGV[1] || "./im_socket_file";
my $msg;
die "provide a socket file address" unless $sock_file;

socket(SOCK, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
print "connecting ..\n";
connect(SOCK, sockaddr_un($sock_file)) || die "connect: $!";

print "writing ..\n";
$msg = "chitrangoda\@example.com MSN This is sent to Chitrangoda via MSN server.".chr(0x1A);
send(SOCK,$msg,0);
recv(SOCK,$msg,100,0);
print "done\n";
close SOCK;



And here is the code with examples pidgin_send_im (please let me know if the link is broken).It works with Pidgin version 2.4.2 and upper (I am not sure about the lower version) ..

Again, there are more than one way to do it. You can use the perl/php bindings or plugins .. I expect you show those howtos in the comments.