January 2013

archive

download website with wget Jan
18
1
3

wget --mirror -p --convert-links -P /path/to/download/directory example.com

comments

pretty print json in python Jan
15
1
3

import json
mydata = json.loads(output)
print json.dumps(mydata, indent=4)

comments

ordinal number in python Jan
15
1
3

## {{{ http://code.activestate.com/recipes/576888/ (r10)
#!/usr/bin/env python

def ordinal(value):
    """
    Converts zero or a *postive* integer (or their string 
    representations) to an ordinal value.

    >>> for i in range(1,13):
    ...     ordinal(i)
    ...     
    u'1st'
    u'2nd'
    u'3rd'
    u'4th'
    u'5th'
    u'6th'
    u'7th'
    u'8th'
    u'9th'
    u'10th'
    u'11th'
    u'12th'

    >>> for i in (100, '111', '112',1011):
    ...     ordinal(i)
    ...     
    u'100th'
    u'111th'
    u'112th'
    u'1011th'

    """
    try:
        value = int(value)
    except ValueError:
        return value

    if value % 100//10 != 1:
        if value % 10 == 1:
            ordval = u"%d%s" % (value, "st")
        elif value % 10 == 2:
            ordval = u"%d%s" % (value, "nd")
        elif value % 10 == 3:
            ordval = u"%d%s" % (value, "rd")
        else:
            ordval = u"%d%s" % (value, "th")
    else:
        ordval = u"%d%s" % (value, "th")

    return ordval

if __name__ == '__main__':
    import doctest
    doctest.testmod()
## end of http://code.activestate.com/recipes/576888/ }}}

comments

ordinal number in javascript Jan
15
1
3

Here's a slick way to create ordinal numbers in javascript that I found.

function getGetOrdinal(n) {
   var s=["th","st","nd","rd"],
       v=n%100;
   return n+(s[(v-20)%10]||s[v]||s[0]);
}

comments

mount virtualbox shared folder in ubuntu Jan
15
1
3

on virtualbox settings share a folder and don't auto mount

inside vm check uid/gid

id

create empty dir

mkdir share_folder

edit file

/etc/fstab

enter line

share_folder /path/to/mount vboxsf uid=1000,gid=1000 0 0

comments