Recent Updates RSS Hide threads | Keyboard Shortcuts

  • Facebook app to download pics from friends albums

    raza 10:47 am on April 28, 2012 | 0 Permalink | Reply
    Tags: , facebook,

    Recently i needed to download pics from a friends album locally to my machine.But the album had hundreds of pics and i was just too lazy to manually download all of them. Thats when an idea occured to me of making a program to do that for me. Laziness is the mother of all invention,isnt it ? ;) .
    So i hacked up a facebook app to do that.Its written in python using the django framework and makes use of the facebook graph api. Currently due to some glitches the app is accessible on chrome, firefox and opera but not on IE. The UI is not super cool but it gets the job done. I would be releasing the code on github soon. Meanwhile you can check out the app at http://apps.facebook.com/fb_albums_downloader .

    Bookmark and Share
     
  • Running a Django app on Heroku platform

    raza 9:52 pm on April 14, 2012 | 0 Permalink | Reply
    Tags: , , , heroku, , postgresql, pypi, , virtualenv

    I was trying to deploy a django application on Heroku. The official documentation given at https://devcenter.heroku.com/articles/django is very helpful but misses out some details,so i was not able to successfully deploy the django app to heroku by following those steps as is. So, for the benefit of those who may be facing this problem, im outlining the steps i followed to get a django app running on heroku platform.

    Im assuming you have already installed the heroku toolbelt and are are able to login to your heroku account from the terminal. If not, have a look at https://devcenter.heroku.com/articles/python#local_workstation_setup.

    Please note that this post is aimed at getting you up and running with django on heroku quickly, so i wont be covering stuff like using a production ready webserver for deployment or asynchronous task processing in your apps .With that said, here we go. Lets say, you are creating this heroku hosted app in a folder called Foo on your local machine. For every new django project you want to host on heroku create a folder for that project and after switching to that folder repeat step 2 onwards.

    Step 1. Create folder Foo and move into it

    mkdir Foo
    cd Foo

    Step 2. Create a virtual envirtonment using virtualenv and activate it

    virtualenv --no-site-packages venv
    source venv/bin/activate

    Step 3. Install django and psycopg2 (Python driver for PostgreSQL.Heroku provides each app with a full-featured PostgreSQL database) in your virtual environment

    pip install django
    pip install psycopg2

    Step 4. Create your django project

    django-admin.py startproject helloheroku

    Step 5. Create a .gitignore file and add venv to it,because we dont want to push our local virtual environment to heroku,it would be automagically created for us :) ,as described in the next step.Then,initialize a git repository using git init

    Step 6. In order for heroku to be able to replicate our local virtual environment by installing the required python modules we need to create a requirements file as follows

    pip freeze > requirements.txt

    Step 7. Create a file called Procfile with the following contents.The Procfile specifies how to run the inbuilt django webserver to start our application.

    web: python helloheroku/manage.py runserver 0.0.0.0:$PORT --noreload

    Step 8. Add our django project,Procfile and the requirements.txt file to the git repo and commit

    git add .
    git commit -m "first commit"

    Step 9. So, now we have our local setup ready for the first push to Heroku. But,before we push we need to create an application on Heroku using the Cedar stack, and then do a git push as shown below.On Heroku, your app will have a url like http://my-app-name.herokuapp.com

    heroku create --stack cedar
    git push heroku master

    If “git push heroku master” gives you an error “heroku does not appear to be a git repository”, run the following command to add heroku as a remote git repository.

    git remote add heroku git@heroku.com:my-app-name.git

    Step 10. And finally, we can start our application on heroku by issuing the following command

    heroku ps:scale web=1

    You can now access your app by visiting the url generated for your app by heroku :) .

    Here are some additional tips which would come in handy

    1. To check if your webserver process is up on heroku, run the command heroku ps
    2. To see the logs generated by the webserver , run the command heroku logs
    3. For a database to use with your django application, you can go for the free 5 MB shared postgresql database provided by heroku ( This shared database is to be used for development and staging only, and not recommended for production, for which you should go for a dedicated database ) by issuing the following command
    heroku addons:add shared-database:5mb
    We can see the url for this database by issuing the command heroku config and looking at the SHARED_DATABASE_URL parameter . This url would be of the format postgres://username:password@hostname/dbname . You can enter these database details in your settings.py and then after comming your changes and doing the git push run heroku run python manage.py syncdb

    Bookmark and Share
     
  • A .gitignore gotcha

    raza 6:57 pm on January 14, 2012 | 0 Permalink | Reply
    Tags:

    Today when working i needed to ignore to some files from getting checked in to my git repository. So, i created a .gitignore file in my projects root directory with the list of files and filetypes that i wanted to ignore. So, now when i do git add ., the stuff i have in my .gitignore is not added to the index, so wont get checked in.
    However,this works only for files which were not currently being tracked by git. For example if i wanted to ignore files of type x, then any untracked files of type x will be ignored by git, but the files of type x already under version control will still remain in the index and hence get checked in during the next commit. The way around this is to run the following command after we have created our .gitignore file:
    git rm -r --cached .
    This removes everything from the index, so we can now run:
    git add ., and the index will now not have the previously tracked files we wanted to ignore and the next commit will remove these ignored files from the servers repository too.

    Bookmark and Share
     
  • Voice controlled LED circuit on my arduino

    raza 8:21 pm on January 11, 2012 | 0 Permalink | Reply
    Tags: android, arduino, electronics, microcontrollers

    Recently had been hacking on my arduino microcontroller board. Created and programmed a circuit consisting of 3 led’s which i control using voice commands from my android phone.It was fun ! :)

    Bookmark and Share
     
  • Deploying a Node.js application to CloudFoundry

    raza 5:55 am on April 22, 2011 | 0 Permalink | Reply
    Tags: , cloudfoundry, node.js,

    I got the invite for VMWare’s CloudFoundry PaaS and decided to take it for a spin by deploying the chat demo for Node.js .I am assuming you have already installed the vmc gem and have set the vmc target and done vmc login. Heres how the Node.js chat app is deployed.


    git clone https://github.com/ry/node_chat
    cd node_chat

    The server.js file has to be renamed to app.js for vmc to recognize it as a node.js application.If we dont do this then we get the error : Error 306: Error retrieving file ‘logs/startup.log’

    mv server.js app.js

    Now, open app.js and change the listening port of the server by replacing process.env.PORT to process.env.VMC_APP_PORT.
    VMC_APP_PORT is an environment variable available to us when our application is running in the cloud.

    fu.listen(Number(process.env.VMC_APP_PORT || PORT), HOST);
    

    And we are done !. We can now push the app to the CloudFoundry Cloud by either doing vmc push, and answering some questions, or by simply running the following command to go with the defaults. The -n flag means we want to use the default settings.

    vmc push my_app_name -n

    You can now access your application at my_app_name.cloudfoundry.com ! :) . You can check the application i deployed at http://razanode.cloudfoundry.com.

    Bookmark and Share
     
  • bpython-An amazing python shell for *nix

    raza 3:11 am on January 5, 2011 | 0 Permalink | Reply
    Tags: ,

    I came across this awesome python shell called bpython.Unlike the default python shell, this one has lots of cool and really useful features like syntax highlighting,autocomplete,auto-indentation etc.
    Check out http://bpython-interpreter.org/downloads/ for installing bpython on your favorite distro . Have Fun ! :)
    bpython

    Bookmark and Share
     
  • Counting word frequency in a given sentence

    raza 1:28 pm on December 17, 2010 | 0 Permalink | Reply
    Tags: algorithm,

    Here is an interesting problem i came across. Given a sentence as a string with words separated by a whitespace, we have to determine the frequency count of every word appearing in it i.e. how many times each word appears in the sentence. For example, suppose we have sentence = “abc abcd abc abcd abcd abcd abcde” , the program should output abc-2, abcd-4,abcde-1.

    Its not a very difficult problem but the reason im writing about it is that i think this is a good example of how using the correct data structure for a problem can greatly simplify its solution. The right data structure in this case may not be immediately obvious,but once we realize what it is the solution just reveals itself to us !

    Taking a close look at the required output i.e. abc-2, abcd-4,abcde-1, we see that its nothing but a ’set of key value pairs’. Python being my language of choice (you can pick whichever u want :) ),that would be nothing but a ‘Dictionary’. And below is the solution coded in Python.

    s = "abc abcd abc abcd abcd abcd abcd abcde"
    l = s.split()  #Get a list of all words
    d = {} #Initialize our dictionary object
    for elem in l:
      if elem in d:
         d[elem]+=1
      else:
        d[elem]=1
    print d
    

    This i think would be one of many good ways of solving the above problem. If you know of some other way please let me know. :)

    Bookmark and Share
     
  • Synapse-A launcher app for Gnome on steroids !

    raza 7:41 pm on December 16, 2010 | 0 Permalink | Reply
    Tags: , gnome,

    I recently came across a great launcher app for Gnome, called Synapse. It can be used to launch applications, documents, videos, search results etc..all with just a few keypresses. It uses the Zeitgeist engine in Gnome to perform its magic.

    Synapse-file-launcher

    Synapse

    Heres how you can get it in ubuntu.
    sudo add-apt-repository ppa:synapse/ppa
    sudo apt-get update
    sudo apt-get install synapse

    Once installed launch it from Applications > Accessories > Synapse. Once launched it keeps running in the background, and you can launch it with the keyboard shortcut of Ctrl+Space (default, and can be changed from Preferences menu). Launcher window closes automatically after entering some text and hitting enter, but if you want to manually close it just hit Esc.

    Now, thats all the info you need to get started with this great app. So, go ahead indulge !. More information about Synapse can be found at http://www.omgubuntu.co.uk/2010/11/synapse-gnome-do-launcher-app-review-ubuntu/

    Have fun ! :)

    Bookmark and Share
     
  • Nokia N900, a phone thats free...as in freedom ! :)

    raza 12:30 am on July 12, 2010 | 0 Permalink | Reply
    Tags: debian, , maemo, n900, nokia,

    Ive been hacking away at my recently bought Nokia N900 . It runs the Maemo 5,which is a GNU/Linux distro based on Debian . Calling the Nokia N900 a phone would be an understatement, as its actually a mobile computer.Rather than a phone that can also compute,its really a computer that can also function as a phone !..simple,isnt it ? ;) . Below,is a pic of my phone..ahem,computer in all its glory :)
    N900

    Maemo is a Debian derivative,so its not pure Debian,but still that didnt stop me from getting all the Debian goodness on my device.
    All it took was installing the Easy Debian package,which downloaded a large Debian image file to my phone giving me access to stuff like OpenOffice.org, Gimp, the LXDE Desktop Environment, Evince, Firefox,Java etc and a lot of other precompiled apps from the Debian repo…kewl,isnt it ? :)

    Now, the programmer in me was dying to start programming the phone. And what better than Python for some instant nirvana ! ;) . To get started i wrote a simple hello world snippet,that makes use of the GTK libraries on the phone.The code is as follows:

    import gtk
    from gtk import Window, Button, Widget
    if __name__ == "__main__":
        window = Window(gtk.WINDOW_TOPLEVEL)
        window.connect("destroy", gtk.main_quit)
        button = Button("Hello World:)")
        button.connect_object("clicked", Widget.destroy, window)
        window.add(button)
        window.show_all()
        gtk.main()
    

    And below is a pic of the program running on my phone :) . Nothing really fancy,but definitely a step in the right direction !
    N900

    Well,thats all for now folks.Twitter has made me really lazy,so writing more than 140 character posts is now a huge task for me ;) . But,still ill try and keep updating about my n900 hacks and experiments. Bye for now, have fun ! :)

    Bookmark and Share
     
  • JQuerify any webpage

    raza 4:53 pm on January 5, 2010 | 0 Permalink | Reply
    Tags: javascript, jquery

    Im a big fan of JQuery. Its a truly versatile javascript library that greatly simplifies writing javascript code,and also one need not worry about cross-browser issues, which was the bane of plain old javascript.
    Recently i came across an interesting bookmarklet written by Karl Swedberg, called JQuerify. It is a small snippet of javascript code that we can bookmark and use to embed jquery support on any page we are currently viewing in the browser.
    Really useful for playing around with JQuery in the Firebug console. Go, give it a shot ! :)

    Bookmark and Share
     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
esc
cancel