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

Where do we belong!

Leave a comment

Hey guys!

Writing something down after a long time. I always get these urges to write something, but never do that due to lack of time or investing time in other worldly problems.

Of late, I have been thinking about the direction in which my career is heading. Even though I like my current job, understanding how large manufacturing companies work and implement oracle for them. However it is not entirely what I imagined myself to be doing when I was a kid.

Ofcourse when are are younger, we imagine us to be a lot of things, lots of dreams and then when you grow up, we stop chasing the dreams and start running to just get the things done in front of us. Somehow the tasks at our hand are too pressing and we forget what we always wanted.

All of us want to find our place in the world. Some find it, some make one and some just are happy with what they get. What if you are one of those, who have to make a place for yourself in the world and it is always there in the back of your mind. Even if you choose to ignore it, your sub conscious mind keeps on telling you, you don’t belong here. There are places you must go to and see for yourself, where you fit and if you don’t make a place for yourself. I have always loved Anime series. You get to learn a lot from them.

One of the Characters in the show Nanatsu no Taizai says, if I live long enough, maybe something will happen to me, I am waiting for that something to happen. We long for that something to happen, but it never might. We have very limited time in our hands and cannot wait an eternity for that moment. We have to work towards reaching that moment. We can only wish.

With that wish in my ghost, I will try to find the place where I belong.

 

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 πŸ˜€

Coursera Courses

Leave a comment

Hey guys!Β  wassup!!

I am free, yeah really free! coz it’s weekend πŸ™‚

So planning to catch up on the coursera courses I have been attending.

Need to complete the 1st week of the rails course aaaanndddd the deadline is tomorrow.

Welcome to Ruby on Rails Web Services and Integration with MongoDB!

So off to studying πŸ™‚ cya later πŸ™‚

 

Stackoverflow ?

Leave a comment

Hey guys!! wassup!

I have been a member of StackOverflow since 4-5 years now, but just recently, I thought, why do I search for answers and not help others with their questions. So I have started answering questions on SO as well. I try to help people with SQL, Web Development related queries and related techs.

Now that I think about it, I am not entirely sure, why I never tried it in the first place, but then again, better late than never. Planning to be active and try to help as many people I can πŸ™‚ come on now, an answer from you, makes their day at office easy πŸ™‚

So yeah! guys go out there and try and be active at communities on stackexchange.

You can find me on SO @ http://stackoverflow.com/users/1013142/sudipta-mondal

Things that matter to me!!

Leave a comment

I have always been thinking, about what matters to me the most. I like coding, I like sweet things, I like to be around people, cute things. I like soft and fluffy things πŸ˜› I like my laptop a lot, like really a lot. I can marry it. If I don’t get to touch my laptop for a few days, I get withdrawal symptoms and after a few days, I just want to hug my laptop πŸ˜₯

Too many things interest me and I feel, I can’t just keep my head into a single thing, I wanna try out so many things out there. I wanna try A, I wanna try B, till I get hang of B, I wanna try out C or whatever. I am random. ADHD perhaps.. not sure.

I used to live in one of the major cities in India and never ever lived or cared too much about people outside of that big city. Neither did I know much. Thank fully I got to work in a company, where I got to meet people from all over India. I have absolutely loved it.. There are so many people from so many places, with so much varied experiences, talent.

I have learned, I am not smart, I am definitely not intelligent. people are out there, some who think like you, some who are different, some who hate you, some whom you like. But people, so many to experience. I used to think, my way was always the right way, that I was correct in thinking always. I was so god damn wrong, for like 23-24 years of my life πŸ™‚ I have learnt, about mistakes that I had made, thinking they were right. I could do only after meeting so many people. These things were never taught in college or school. These things you can only learn, if you go out there and experience, learn, see, listen.

Go, Get out there, talk to people, share your view, hang out, go to movies, but most importantly listen, to what everyone has to say. Listen and understand. I am sure, you will figure out the real you.

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.

Older Entries