Dependent / Cascading Select List with jQuery Select2

Select2 is one of the most popular select list plugin for jQuery. It has beautiful features and powerful customization options.

One missing feature of Select2 is built-in support for making select boxes cascading/dependent. In simple words, loading/refreshing options of a select2 list box using ajax based on selection of another select2 list box. So, I’ve written a reusable class for this purpose.

Get it here – Select2 Cascade (for v4.x)

Looking for a demo?

Here is it – live demo.

Thanks to Codepen, JSON Blob and Twitter Bootstrap for making demonstration so easy!

Continue reading →

Convert Excel TSV to CSV in vim

After Copy-Paste some data from MS Excel spreadsheet, it appeared to be half thousand TSV (Tab Separated Values) lines in vim. Then it took around 20 seconds to convert it to CSV! So, how did I do it so quickly?

Okay, it was just two simple replace command using vim regexp –


The first line is adding quotes around column values which have comma in it. And the next one is to replace tabs with comma. Done!

Hope this tip will save someone’s time someday 🙂

Store data to Google Sheets using PHP

Google SheetsIn some cases, when you need to dump some data to somewhere easily accessible, pushing to Google Sheets can be a good option. You can store data to Google Spreadsheet from cron jobs, background workers or even simple form submission. For example, in my case, I am logging some information from mailgun hooks.

While I were doing that, it seems like this easy task took more time then expected only because of lack of documentation. So, trying to write down an easy to follow tutorial that can make you set and pushing data to goggle Spreadsheet within 20 minutes.

Continue reading →

Multiple sites with Apache Server on different ports or domains

Apache Server multiple site on ports

Sometimes people become amazed with an awesome feature of his new shiny tool, and never discover that it was already there for years in his old boring tool. A good example of this phenomenon is – I see people choosing nginx for it’s ability of listening to multiple ports and domains.

Definitely there are solid reasons and cases for choosing nginx. But, I’ll say, this one alone is not a good reason for switching to nginx if you’re already running on and confident with Apache Server. Because, you can serve multiple apps/sites on different ports or domains using Apache too.

Let’s see some quick example of how Apache can do it. I’ll here just list a few example of Apache VirtualHost configs for various cases with a single server.
Continue reading →

Track or count online users in Firebase webapp


It’s a pretty common need to track online users of an web application. Sometimes for counting total online users, sometimes by isolated space, e.g., by chatroom or shared list. So, instead of doing similar things every time, I’ve written a javascript module to use in Firebase web applications – Gathering.js.

In this post, I’ll show how it can be used for various type of tracking needs with small code snippets.

BTW, if you are thinking what Firebase is, it’s a Google acquired app development platform for mobile and web. For web application, it’s providing ready made infrastructure with super fast realtime database, flexible Authentication, cross platform Cloud Messaging, static hosting, CDN… (almost) everything you need to develop an app (or a feature) quickly with robustness. You should give it a try.

Continue reading →

BootstrapFileField – File input with preview and restrictions, no ajax

The file input is one of those HTML elements that are complex to style with CSS.
As a result, now a days we see many ajax uploader plugins (e,g, DropZone) that helps to modify appearance of file input. Now, what if I have a/some html fields in a regular form (no ajax upload required), but I want to make it look beautiful? Additionally I want to have other cool things that those ajax uploader provides like showing image thumbnails and restricting file types?

One ready-made solution is – BootstrapFileField. A jQuery plugin to enhance html file input to look like bootstrap button, showing image thumb and apply useful restrictions (e.g. file types, size, number of files etc.)

BootstrapFileField - File input with preview and restrictions

Check this live demo, it’s usability + simplicity!

Continue reading →


I had to import a huge Oracle database dump into MySQL database today. One major problem in doing this was, TO_DATE function of Oracle (used to convert string to date) is not available in MySQL. This post is just to tell you the simple trick that I’ve used to resolved this issue.

The good news is, MySQL have a function STR_TO_DATE for similar purpose, but with different syntax. So I had to replace all the TO_DATE with STR_TO_DATE using the following regular expression (in SublimeText 3) –

Find: TO_DATE\(‘(\d{2})\/(\d{2})\/(\d{4})\s+00:00:00’,\s+’MM/DD/YYYY HH24:MI:SS’\)
Replace: STR_TO_DATE(‘\3-\1-\2’, ‘%Y-%m-%d’)

Then Replace All… Done!

BTW, to see all format characters and syntax of both function, you may check this article.

Symfony2 Forms with Bootstrap 3 : Datepicker for date field

Symfony2 Forms have a rich set of field types and many defined widgets for rendering fields. But still we may need a different representation of a field. For example, in a web application of today we cannot think of a date field without a datepicker.

Symfony2 Forms don’t have any built in widget for rendering a date field with a datepicker. But, Symfony Form’s customization options are so flexible that, actually there is nothing to be worry about. Just in few minutes, using a simple trick, we can turn our date filed into a datepicker. In this post, I am going to share the trick with an example.

Datepicker vs Symfony Form's default date widget

Continue reading →

Symfony Forms with Bootstrap 3 : Rendering a help block

It’s a pretty common need to show a help text with a form filed. Where we’ll tell the user about purpose of this field or some validation rules. Although Twitter Bootstrap already have a `help-block` class, Symfony Form component don’t have built-in support for rendering this kind of help block.

In this post I’ll share a simple trick that I use with Symfony Forms to render help block under form fields. Here is a sample output.


Continue reading →