Why to-do apps for JavaScript frameworks

Somehow whenever I see some new Javascript framework, most of them always have the same To-Do application as their showcase sample. If someone/ some company is going to build a new framework and going to tell me, we built an awesome framework you can do so much with that and then they go ahead and give me a sample of a To-Do application, anyone would be like meh!!

How difficult can a to-do application be that the said framework is going to make your life much easier.

Just wrote a small to-do app myself, it only needs 1 single line of javascript, yup you read that right.

<!doctype html>
<html>
<head>
<title>Sample To-Do</title>
<style type="text/css">
section {margin: 0 auto;width: 100%;}
h3, h5, li {float: left;width:100%;}
ul {list-style: none;}
input[type=checkbox], p { float:left;margin: 0;}
</style>
</head>
<body>
<section>
<h3> To-Do Application</h3>
<h5> Add your todo below</h5>
<div>
<textarea id="newtodo" placeholder="Enter your todo here..."></textarea>
<button id="newtodosub" onclick="addtodo();">Add</button>
</div>
<ul id="todos"></ul>
</section>
<script type="text/javascript">
function addtodo() {
document.getElementById("todos").insertAdjacentHTML('beforeend',
'<li id="todoitem"><input type="checkbox" onclick="function rem(el) {el.parentElement.lastElementChild.style='
+ '\'float:left;text-decoration:line-through\';el.setAttribute(\'disabled\', \'disabled\')};rem(this);" />'
+ '<p style="float:left;">&nbsp;&nbsp;&nbsp;' + document.getElementById("newtodo").value + '</p>'
+ '</li>'
);
}
</script>
</body>
</html>
view raw todo.html hosted with ❤ by GitHub

All the things you need are –

  1. Text area for the To-do
  2. Button to add it.
  3. Checkbox to mark the todo complete.

The addtodo() function inside the <script> tag is what does all of this.

I feel designers, developers need to come up with something more innovative than a todo list app. Just saying!

Script Processor in EDQ is cool

So I started with a bit of work on EDQ and I must say its a pretty neat tool. Basically Oracle EDQ stands for Enterprise Data Quality where you get to fix all the invalid, inconsistent and simply put bad, very bad, very very bad data.

I was just playing with it a bit and found the script processor very handy since I could do anything I want with use of a scripting language like javascript or groovy.

I just wrote a sample script to have convert the currency values of products from one currency to another. Maybe this could help someone writing a script for the first time in EDQ.

Here is what my data looks like –

+--------+--------------+------------+-----------------+
| Value | Convert From | Convert To | Converted Value |
+--------+--------------+------------+-----------------+
| 100.14 | INR | USD | |
| 290.19 | INR | GBP | |
| 310.05 | INR | EUR | |
| 110.67 | INR | CAD | |
| 200 | EUR | EUR | |
| 10 | EUR | GBP | |
| 3 | EUR | INR | |
| 6 | GBP | INR | |
| 6 | EUR | INR | |
+--------+--------------+------------+-----------------+

I created a quick web service on mockable.io. It is a pretty neat tool where you can create a web service to output any data that you want to, here is the sample data I created –

{"base":"EUR","rates":{"CAD":1.4469,"HKD":8.4742,"ISK":139.3,"PHP":55.538,"DKK":7.471,"HUF":339.28,"CZK":25.344,"AUD":1.6565,"RON":4.805,"SEK":10.5813,"IDR":15221.86,"INR":77.9195,"BRL":4.7741,"RUB":71.2368,"HRK":7.4605,"JPY":120.13,"THB":34.664,"CHF":1.0606,"SGD":1.5204,"PLN":4.3094,"BGN":1.9558,"TRY":6.6981,"CNY":7.6329,"NOK":10.2113,"NZD":1.7273,"ZAR":16.4555,"USD":1.0875,"MXN":20.806,"ILS":3.7429,"GBP":0.8415,"KRW":1322.29,"MYR":4.5952}}

And finally here is the code of the script processor which will convert the values to specific currency, the data used is pretty self explanatory.

addLibrary("http");
var output1;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://demo7684243.mockable.io/curr_rates&quot;, false);// Here goes your web service URL
xmlHttp.send();
var responseData = xmlHttp.responseText;
var dataJSON = JSON.parse(responseData);
var baseCurr = dataJSON["base"];
var baseCurrRate = dataJSON["rates"];
var convertFrom = input1[1];
var convertTo = input1[2];
var convertFromRate = dataJSON["rates"][convertFrom];
var convertToRate = dataJSON["rates"][convertTo];
if (convertFrom == convertTo) {
convertToRate = 1;
convertFromRate = 1;
}
if (convertTo == baseCurr) {
convertToRate = 1;
}
if (convertFrom == baseCurr) {
convertFromRate = 1;
}
var convertedVal = (input1[0] * convertToRate) / convertFromRate;
output1 = convertedVal.toFixed(2);

There are few things which I am sure, you would know if you have used EDQ before.

  1. All inputs and outputs have to be used in the form of array. input1[0], input1[1], input1[2] and so on will be automatically mapped with your columns which you would have selected.
  2. There can be only one output of the script and you need to store it in output1 variable only.
  3. You can simply ignore the logic of Currency conversion in the code, since this is for a very specific task.

All this was just to show you how you can manipulate data with the use of Web Services in EDQ. Hope this helps 🙂

A blog a day challenge

I am going to start with the blog a day challenge. Simply put for the next 100 days I am going to write a blog every single day without fail on any topic.

I need to invest a considerable amount of time in learning new things for career growth and my own as well. Having a regular blog should help in prioritising the activities in that direction.

How do we start?

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

Where do we belong!

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.

Stackoverflow ?

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!!

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.

What I am working on

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 🙂

Start of Job hunt

hey guys!!!

long time no see… So finally after almost 2 years, I am starting to search for a job. These days I feel, finding a job has become like finding the right pair of shoes for you. The ones which fit the bill, aren’t that good and ones which look cool are not that comfortable 😦

Need to find a job which is somewhere in the middle of pay and play. First preference to money though, because in the Immortal words of the Wolf of Wall street – ‘Let me tell you something. There’s no nobility in poverty. I’ve been a rich man, and I’ve been a poor man. And I choose rich every fucking time.’

Life made easy

I am wondering

Why? always ?

sudo nano file_name
sudo apt-get install whatever
sudo apt-get install -f
sudo apt-get remove

Why not just!! Simplify.

Edit your ~/.bash_profile.

nano ~/.bash_profile

and add something like the following lines, which you use on a daily basis.

alias snano='sudo nano'
alias apt-update='sudo apt-get update'
alias apt-fix='sudo apt-get -f install'
alias apt-remove='sudo apt-get remove'

close and re-open it.

Now you can simply use apt-fix instead of typing sudo apt-get -f install

Life made simpler 🙂