Sails.js v0.10 release is coming

Finally long awaited release of Sails.js is coming.


This version of Sails.js  v0.10 is going to have some new features and changes like Associations, hooks and generators etc

Follow Sails.js on twitter

Watch Sails.js v0.10 on Youtube

Meanwhile checkout new documentation at

Posted in just another post

How to identify the disk drives on linux

One cool thing about linux family is that everything is a file, even a device connected to it.
The files that are related to devices are stored in location /dev/.

If You see these kind of files you are on right place:
    autofs, tty34, ram13, sda1, loop3
Files for drives look like these:
    hda / sda / sdb / sdb3 /hdc1

I will use example of sdb3. The name consists of three parts sdb3 = sd + b + 3

Part 1:
    hd - IDE drives
    sd - SCSI

Part 2:
    a - physical disk a
    b - physical disk b

Part 3:
    1 - partition 1
    2 - partition 2

So drive sdb3 means ‘3’ partition SCSI device ‘b’.

Posted in Technical, Unix-family

Django forms: Custom attributes for input tag

While making a form directly in html you may have done

<input id="keywords" type="text" name="keywords" placeholder="Enter your keywords here">

to make a input field that looks like :


But in django Forms or ModelForms automatically generate some boilerplate code for you including that input tag.
You may be doing {{ form.as_p }} or {{ form.tag }} in the templates, there is no option(or not an obvious one) to do this directly into templates.
But you can do this in __init__ function of your Form or ModelForm like the following

class TagsForm(forms.ModelForm):
	class Meta:
		model = Tags
		fields = ("keywords",)

	def __init__(self, *args, **kwargs):
		super(SearchForm, self).__init__(*args, **kwargs)
		self.fields['keywords'].widget.attrs['placeholder'] = "Enter your keywords here"

Similarly you can add other attributes as well:

self.fields['keywords'].widget.attrs['value'] = "sensible default"

this will add value attribute in the input tag

<input id="keywords" type="text" name="keywords" value="sensible default">
Posted in Django, Prgramming/Coding, python, Technical

Change the order of nesting of keys in a dictionary.

I have faced a problem where wee need to change the order of nesting of keys in a dictionary, to accomodate in a loop

Assume we have a dictionary:

nested_dict = {
	'outer_alpha': {'inner_alpha': 10, 'inner_beta':20},
	'outer_beta': {'inner_alpha': 100, 'inner_beta': 200, 'inner_gamma':300 },
	'outer_gamma': {'inner_gamma':3000 },
	'outer_empty': {},

By looking the dictionary we can tell that value of:
nested_dict[‘outer_beta’][‘inner_gamma’] is 300

but you may want that indexing of these sohuld be in reverse
so that nested_dict[‘inner_gamma’][‘outer_beta’] will give 300

You can do this by two methods
1. Using dict.setdefault()

reversed_nested_dict = {}
for outer_key , inner_dict in nested_dict.iteritems():
	for inner_key, value in inner_dict.iteritems():
		reversed_nested_dict.setdefault(inner_key, {})[outer_key] = value

2. And Using defaultdict from collections

from collections import defaultdict

reversed_nested_dict = defaultdict(dict)
for outer_key , inner_dict in nested_dict.iteritems():
	for inner_key, value in inner_dict.iteritems():
		reversed_nested_dict[inner_key][outer_key] = value

And the Result is

	'inner_alpha': {'outer_beta': 100, 'outer_alpha': 10}, 
	'inner_gamma': {'outer_beta': 300, 'outer_gamma': 3000}, 
	'inner_beta': {'outer_beta': 200, 'outer_alpha': 20}}
Posted in Prgramming/Coding, python, Technical

Custom widget in django ModelForm

I was trying to override the widget of an editable field that is automaticaly generated by ModelAdmin in list_editable mode.
The problem was the use of ModelForm that create a Form automatically by inspecting the definations of your model.

What is ModelForm? According to django documentation: It is a helper class that let you create a Form class from a Django model.

One Choice is to Create a Form manually.

But You may want all the features that ModelForm provides, and dont want to code all that just to change a widget.

The Solution is get_changelist_form(Refer to Django Official documentation on this topic)

# Your custom ModelForm
class BlogPostForm(forms.ModelForm):
    class Meta:
        model = BlogPost
        widgets = {
        'field': SpecialFieldWidget(),

# Your ModelAdmin
class BlogPostAdmin(admin.ModelAdmin):
    form = BlogPostForm

    #just return the ModelForm class BlogPostForm
    def get_changelist_form(self, request, **kwargs):
        return BlogPostForm
Posted in Django, Prgramming/Coding, python, Technical

Its a wonderful start

It’s been a month since I got the glimpse that i must have a wonderful blog. I had those long nights when i was thinking about a cool name and some initial content i need to put on my blog. I would like to thank:

  • The article that give the motivation to start the blog that tells what should be your content and who are your target audience and some good stuff about blogging.
  • My friends who suggest me such a cool name aryanix  arya + nix, “arya” (is my last name) and “nix” (came from “unix” that we all love in in one form or other, just look at the phone you carry, websites you visit)
  • “The Art of the Start”: Book by Guy Kawasaki
Posted in just another post