How do we start?

Leave a comment

Hi Guys

Long time no see 🙂 sometimes I feel like I should tell that to myself as well.

So how do we start, we start by noting down what we need to do, and while we are at it, we note down what we didn’t write in the first place and also few more things which you should have thought of before. To do things is to improvise, learn and also to keep on adding more things to do, obviously a to-do list never ends, because to do something or to learn something, you need to do a lot of things 🙂

To understand that lets write a blog post 🙂 This is going to be quick. All you need is rails setup in your system.

Lets start with creating a blank app

rails new todoapp # this will create a blank slate for you to work on

rails g scaffold todo task:string complete:boolean parent_task_id:integer # this will create your model/views/controller/migration etc etc files which you will do the work for you

rake db:migrate # if this throws an error, you gotta do “rake db:setup first” this will create your database migration and the schema for todo tasks.

Now we need to build something like the below to sorta have a parent child relationship between the tasks. Why ? just read the 2nd para again from top.

Parent Task 1
—- Child Task 1
—- Child Task 2
Parent Task 2
Parent Task 3
—- Child Task 1
——– Child Task 2

In your new and shiny app/models/todo.rb add these two lines to create the parent child hierarchy.

has_many :child_tasks, :class_name => 'Todo', :foreign_key => "parent_task_id"
belongs_to :parent_task, :class_name => 'Todo', :foreign_key => "parent_task_id"

Now a bit of magic is needed to the views to allow us to easily select the Parent tasks for any child task.

Head over to your app/views/todos/_form.html.haml or *.erb file depending on the templating engine and change the f.parent_task_id to a collection_select

.field
= f.label :parent_task_id
= collection_select :todo, :parent_task_id, Todo.all + [Todo.new], :id, :task

This will allow us to choose a parent task, whenever we are creating a new task with – not a very bad hack? 😛

Finally in the show and index page, we need to display the parent task.

replace your todo.parent_task_id with
Todo.find_by_id(@todo.parent_task_id).task rescue "No Parent Task"

And the end result is tada!!!

Todoapp

Advertisements

Stack Overflow Questions

Leave a comment

Hey Guys!! Howdy!!

These days I have a lot of free time on my hand due to my new assignment at work. I have no work absolutely 😀

Strangely it came to my mind, I could pass my time at work by answering some SO questions related to tech that I have been working on. Seems like a good idea, right!!

However just going to the website and searching for new questions every 5 odd minutes seems like an overkill and boring. So I am thinking, why shouldn’t I make a small Stack Overflow linked application which would fetch 10 New questions attached to a specific TAG and mail it to me every hour. Let me get on with developing that and ofcourse I will post the code on My Github

Stay Tuned and Stay Happy 😀

Series – Coding Interview Book (part 1)

Leave a comment

So, I have started to have a look at the Coding interview book. Have been reading about how interviews happen at top 5 IT firms like Google, Amazon, Apple Inc etc.

To think, or even dream, I could be part of such awesome organizations is like a very very far fetched thought. Wouldn’t have my hopes so high ever.

Then again, that doesn’t mean, I shouldn’t start practising some cool coding questions for some interviews. In the first few pages, I found out a few easy questions, which I will try to write code of and put it somewhere online for everyone’s review. Yeah! Together we learn 😛

The questions/sample exercises seem to be pretty easy. So here we go!!!
1. Design an algorithm to sort a list
Question: What sort of a list? An array? A linked list?
Answer : An array.
Question : What does the array hold? Numbers? Characters? String?
Answer : Numbers.
Questions: And are the numbers integers?
Answers : Yes.
Question : Where did the numbers come from ? Are they IDs ? Values of something ?
Answers : They are ages of customers.
Question : And how many customers are there ?
Answers : Around a million.

I will leave some analysing of the question to you guys. Let me just quickly write down some code for solving the problem.

So the code is available here magic_sort.rb You guys can have a look, I am using the Benchmark module of ruby to capture the execution time. As always insertion sort is faster for smaller arrays. But when the array size increase beyond 10000, the performance is significant for our magic sort 🙂
Have a look and let me know, if we can improve it even further.

What I am working on

Leave a comment

For a long time, I always wanted to make a one stop dashboard for me, which would allow me to do everything, for which, I have to go to a lot of different websites, Twitter, Facebook, Gmail, WordPress, checking stats of my sites, notifications, calendar, tasks etc etc.

In the end, I gave in to the temptation of making a personal dashboard which would really help me in solving the problem of having so many tabs open in my browser. 🙂

Will keep on blogging about the development on the dashboard and would put a github link soon 🙂

MongoDB class

Leave a comment

Hey guys! Since we started with the MongoDB course. Just saw the first video, which has some writing code in it, so I thought, I will write some, since ❤ ruby ❤
The link for the class video is – link. You can go ahead have a look and see, what it does. I just wrote a similar code which lets us do the same thing in ruby. Using sinatra( bottle is being used with python in the video)

Thats it folks, we are done. Head over to http”//127.0.0.1:8080/hello/world and see for yourself.

MongoDB courseware

Leave a comment

Hi Guys, Long time no see. Just been busy with some stuff. Today I am going to talk a bit about MongoDB. Well its too much in news, these days, your clients wanting you to use it, people telling you about scalability factors, even if you are just bulding a food recipes site. sigh!

So I thought, I might as well jump onto the bandwagon to learn some mongodb as well. So like fortunately, I found out that 10gen the company behind mongodb is having an online courseware for learning mongodb. So I enrolled with it. Oh Well, yeah its in python, I ❤ ruby. so what? Let me try and have a series of blog posts, with similar code in ruby as is taught in class in the courseware in python. Hope you guys will learns something with me too.

Time to learn 🙂

Don’t forget to check the link

Sencha Touch. HTML5?

Leave a comment

Yo! whats up guys?

I have always felt UI/UX being an integral part of application development. What? Well not really if you are the developer of the ugly looking enterprise apps. Can’t help your poor souls though. But if you fall in the niche category, where you get to develop something cool! Lets talk about the ONGOING Sencha Touch – Are you HTML5 ready? contest. Sencha touch has been one of my favourites, ever since I first started with it, Now well, to be honest, I have always been a backend guy with developing core functionalities rather than making designs, designing UIs, dabbling on UX. But I always had this urge to make something that looks gorgeous and well yeah! which is kind of easy to make. So well, there are two of the more popular frameworks out there, one being jQuery Mobile and other being Sencha Touch built over the popular framework Ext/js, which has been there from sometime now.

Anyways – Contest to build HTML5 apps –> http://www.sencha.com/html5-is-ready

They have kind of defined a few categories, though its not necessary for you to to stick to those categories, but they kind of make it established that you are in a better position to win if you keep within these categories –

  1. Weather
  2. To Do/Reminder
  3. Calculator
  4. Stocks
  5. Camera/Photos
  6. Calendar

Well, no ones stopping you though, you can create as long as it satisfies you, if it does, I guess, it should be good enough to win 🙂 so what brush up your javascript, brush up your MVC and start with it.

Guess I will make something up for the contest too 😛

Older Entries