I-Am-Bot Code, technology and life

27Mar/100

Lightweight Javascript inline editing

Posted by Srinath

Update 2: Core methods rewritten for compatibility with browsers. Check change log for details

Update 1: Script updated considerably

There are many excellent scripts to edit something inline using javascript (like jeditable), but not many that work standalone. If you hate wanting to include a 50 KB library just for this simple functionality, you are in the right page. This script is tiny (1.7 kB minified) and works on most modern browsers

Demo

Download

Steps:

1) Include the editable.js file in your page

2) Add the attribute class="editable" to a division, paragraph or table cell <td>

3) Click on the element for it to turn into a text box. Update the value, and press enter to save. Press tab or click anywhere on the page to discard updates and revert to the old value

Changelog

Version 0.2

  • Support for all major browsers
  • Table cell editing more robust
  • Added support for IE 7 and 8. Uses ie.js for support for getElementsByClassName

Initial Release

  • The editable box now fits to the size of the original element. You can see that in the demo
  • Support for inline table cell editing is now included (Proper layout/orientation only work in FF for now. Horribly out of place in other browsers and will be fixed later)
  • Editing of an element with other HTML tags now works better

Gotchas:

1) Only one element is editable at any instant (I wanted this specific feature for a project I'm working on)

2) The text box doesn't fit to the size of the original element (will be fixed)

Tested On:

Windows - Firefox 3.6, IE 7 & 8, Chrome

Mac - Firefox 3.6, Safari 4, Chrome

Terms:

Free to use for personal or commercial purposes, but please give credits

Notes:

I know it can always be better, and I'm just a beginner. So comments, suggestions always welcome!

21Mar/107

Thayir saadam, maavadu – Part 1

Posted by Srinath

“Wake up Sridhar!” Amma was screaming. “It’s time for you to goto office”.

I peeked at the outside world from under my blanket. The clock was ticking by lazily, reflecting my mood. 5:00 o’clock it said. For a moment I thought I had overslept, my siesta usually ended at 4:30 when Amma brought me hot coffee and vazhaikai bhaji or bonda to munch on. Then it stuck me that it was dark all around, and the usual hustle bustle of the household was non-existent.  I took a long hard look at the clock again - it was morning. And it wasn’t morning on just any day, it was THE day. I hoped it would never come, but my life had a horrible sense of humor. Suddenly I didn’t want to live anymore. I wished I’d have a seizure or advanced stage of blood cancer and would drop dead. I waited a few moments for that to happen, but it didn’t. So I did the next best thing. “5 more minutes amma” I screamed and covered myself with my blanket, hoping that I would suffocate myself to death.

“Not today! Get up fast and get ready. Your company bus will be here by 6:30”. It sounded more like your execution is at 6:30 so you better beautify yourself and say your last prayer. I was about to open my mouth in revolt, when paati walked in. “Enna da, still not ready? Naazhi ayduthu”. And when your paati says that, you just shut up, get up, brush up, clean up, dress up and eat up. So that’s what I did.

By 6:00 I was dressed as a waiter in a fancy 5 star restaurant. A boring beige trouser with a white-stripped shirt. And the tie – God the tie! I silently cursed the genius who decided that it was an absolute essential for some IT rat typing away furiously on his keyboard, who is 3000 miles away from the client, in a posh glass covered building. The reason for the tie – if the client visits us, we have to look professional. Professional my ass! I’m in Aminjikarai, not America!

I noticed amma staring at me, as I was lost in my train of thought. She was beaming with pride. “Chammathu payian! How responsible you are. See, I told you’d get into Azhagappa Information Solutions when you attended the interview. It’s such a big company with so many employees. That boy Parameshwar who cheated in the exam and got one mark more than you didn’t get in. Serves him right! Did he think there is no God and that he will let go of people who lie, cheat, blah blah blah…. and I heard another one of Amma’s famous speeches.

“Amma stop it! I got in, he didn’t! Can you please leave it at that!”

“See, now that you have a job you have started talking back at me. Oh how hard I had to struggle to bring you up. If you know the blah blah blah…..

“Aiyoo sorry. Please don’t start again. I don’t want to be late for my first day in office”

“Seri da, apparam pesalam. I’m so proud of you! Listen, I’ve made ‘getti thayir sadam’ and delicious maavadu. Your paati herself made the maavadu especially for you da. Eat it before 12 or the curd will go sour”

“What! Thayir saadam! Enna maa aachu unaku? This is an IT company, not a government office. People eat all stylish stuff like pizza, burgers, Chinese, Mexican. I told you don’t make thayir saadam yesterday. You never listen to me! I’m not taking it, that’s it!”

“Enna da anga satham” appa walked in. He had the usual stern face, with ‘vibudhi’ on his forehead after doing sandhi. As most fathers are, he was the villain in my life.

“Nothing appa”

“Parango, he is not taking lunch from home. He doesn’t like thayir saadam it seems. Oh he used to like everything I cooked before. He has changed a lot….” Amma started off, now having the support of Appa.

“It’s summer da. Don’t eat anything outside. Curd rice is very good for the body in summers. Nammaku andha masala ellam othu varadhu. Kanda kanda yennai potu samaipaaga. Abhistu abhistu”

I was so furious I was boiling like kanda kanda yennai. I screamed out “For God’s sake so many people eat masala and oily food outside, they all are doing fine! Don’t dictate where I have to eat! It’s my life! I’ll do what I want!” but the words never escaped my mouth. They dived into my stomach and disappeared in a knot.

“Seri Appa” I squealed like a mouse.

“It’s getting late! Drop him in the bus stop” ordered paati.

“Seri Amma” my dad squealed like a mouse.

It was 6:10. The bus stop was 2 minutes walk from my house. I wanted to protest again, so I walked out to wear my shoe.

“Nillu da! Go pray to God that everything will turn out good. Paatiya namaskaram pannitu po”

I silently went up to the puja room, sighed, said a couple of prayers cause I was the religious type, took blessings from paati and amma and appa and walked out.

I was trembling at the prospect of being the target on day one for my thayir saadam. I mean who carries that anymore! I though its days had ended when my parents were in school and carried it in small aluminium sambadam, having been told the same story that it was good for health, whereas the real truth was my grandfather was poor and couldn’t afford to feed him 5 children anything else. Apparently I had underestimated its lifetime, and its half-life increased with every passing year.

Appa started his old, rusty, trusty TVS scooty. I didn’t want to spoil my new clothes by sitting on the torn, soiled seat. I sat at the pillion silently, not wanting another encounter.

We got to the bus stop by 6:15. There was no sign of civilization. The few paperboys were delivering papers, and the aavin booth was stocking up on its day’s supply of milk. The company bus usually stops right at the PTC bus stop, as my father had enquired with a million friends and cross checked with the company’s bus in charge. A few small kids who were at the bus stop smiled at me, and my father gave them a beaming smile back. This was a very rare occasion and I attributed it to the fact that I was now employed, and my parents were proud of me.

“Paaru da Sridhar, you have to work hard. Respect you seniors. Be kind and considerate with you team mates. Since it’s a big company, there is bound to be lot of politics. But you should not get involved with that. Don’t waste your time. If there is nothing to do, read books or chant shiva shiva. Only then will you come up in life”

At the back of my head I thought you’ve done all that for 30 years, and look at where we are. I smiled bleakly.

End of part 1. To be continued...

Tagged as: , 7 Comments
18Mar/100

Status Update

Posted by Srinath

It's been a while since I posted anything worthwhile. This is a brief update on what I'm upto and what plans I have for this blog

1) I'm planning a minor update to dScript - to fix a couple of minor bugs, and make it easier to customize (Done!)

2) Work has started on a comprehensive PHP User authentication system - something that is simple, secure and has loads of customization options. I know there are a lot of options around, but I was looking for something that is pure OO and is extensible. It will require PHP 5+ compiled with PDO. Will be released with an appropriate open source license once done

3) Will release an PHP API for ZNISMS service. It is by far the best bulk SMS service I've used and I would heartily recommend it to anyone searching for such a service in India.

Other than this, I've finally figured out a bit more about JavaScript than before and even though they aren't new, I will put up those as code snippets for those who might find it helpful.

Code On.

Tagged as: No Comments
15Mar/100

CLOUDy with a chance of meatballs

Posted by Sandeep

Yes! You read it right! Cloudy with a chance of meatballs. But wait! I’m not here to talk about the movie with the same title name. Rather I’m here to talk about one of the most debatable and the current sizzling topics in the Information Technology world “Cloud Computing”. I don’t have to introduce what Cloud Computing is all about. Perhaps that is because all of us have heard it all before and probably there are masters of Cloud Computing out here. This “pay as you go” computing – allows businesses to lease computing resources as and when they are in need of it, information is shared over the network easily and blah blah … But what made me to think about this write up is that though it’s booming yet there have been few takers. Like many, I have serious concerns about the security.

How can anyone expect companies to give all their sensitive and confidential data to a black hole in the sky?

If you are thinking that cost-cutting is one of the major advantages of Cloud Computing then I guess you’re compromising your security of data with cost-cutting which is a serious issue to be thought about. By the way, cybercrime is on the march as online predators deploy armies of “botnets” and computers are hijacked without owner’s consent these days.

On a second thought, a lot of smaller companies and startups who don’t have a data security policy in place, and invest very little on security, cloud would be an attractive option to them. Complicating issues further, one can’t go and demand for a separate server or a processor for each and every individual customers. It’s a “virtual” machine – a slice of a machine with its own operating system that is partitioned off by the software from other customers. Ultimately, there is a sharing of processing and storage space. And so the analogy of the title :D

All said, Google will offer cloud-computing services designed specifically for U.S government agencies. Sounds paradoxical eh?

Filed under: technology No Comments
31Jan/104

Of application rewrites

Posted by Srinath

What will you do if you write a shitty application? And what will you do when you find that you have written a shitty application? I've been haunted by these questions for the past two days, and yes, I'm guilty as charged. Before someone thinks I sound like someone who knows programming, let me clarify - NO I DON'T. And that is exactly the reason for this post.

The application that I worked on wasn't something big and impossible. It was a simple school management system, written in PHP/MySQL with a liberal dose of javascript thrown in. Unfortunately, it just didn't make it to the servers, and I abandoned it about 6 months ago. Much has changed in that time, and thankfully. I now really understand the need to follow Software Engineering processes, the most important being Design. So why did my team, and I choose to ignore something we've actually studied in college? Were we dumb enough to think that we wouldn't be needing it? Probably. Were we not actually able to understand why we will need it? Possibly. The only reason that readily comes to my mind was because we never knew that we will actually need it.

Software Engineering courses in Indian colleges are often the most boring, monotonous and brain-dead courses among the lot. Throw in a thick rimmed, thick skulled man in his 40's who has never worked on a real application all his life, to teach it and you have a 2012 waiting to happen. And it often does. We students cram the Pressman's book a day before the exam, answer standard questions about SDLC, Testing, importance of SE, and get away with it. And that is that. We are never taught first hand on why we need it, how we should use it, how badly it will affect the software if you don't follow certain principles, or why learn SE at all! Those are left to the student to discover after a few years, just like I have.

So what exactly was my application? It was

  • Very simple and modular
  • Web based for universal access
  • Not that huge or complex (Our team of 4 completed it in 3 working months)
  • Architecturally simple

Then why did we screw it up? We did everything that we could think of. We first gathered requirements, refined them, thought we did some design, then went on with the coding. Too bad we thought we designed it! We did not. Looking back, I feel really stupid about some of the decisions we took based on our understanding of the system. We knew we had to design it properly, but we didn't take it seriously as we didn't really know its consequences. I am no programmer, and if I feel my app is shitty, it really has to be!

Where did I go wrong?

  • No framework
  • No separating of logic from presentation. It was all embedded in a single file in true PHP fashion
  • No proper design of the entire system. No HLD/DLD
  • No glue. The code looks like disjoint pieces of a puzzle

What I did right?

  • Probably the architecture
  • With PHP/MySQL
  • Revision Control which was never used seriously

So the question beacons - When does one decide to rewrite/redesign an application? I need not have decided on redoing the whole thing. I could have as well patched it up, and sold it as many still do. It would still work, can be understood by almost any developer, and I wouldn't have to waste time and money on a rewrite. Decorate shit and it will still be shit. If one doesn't learn from mistakes at the first instance, he/she probably never will. So I finally did what I should have done in the first place:

  • Designed a breakdown of the entire system into modules and the coupling between them
  • Decided against going for a fully blown framework like Symfony as that will add unnecessary complication to a simple application, but rather write my own simple framework to separate code from design
  • Chose mysqli as the database driver and developed a simple wrapper around it
  • Added a logging system which was entirely missing
  • Work on a custom design from scratch, which will also work on portable devices
  • Write a generic framework for the reporting module with custom graphs and charts rather redo the entire code
  • And many many more...

The point I'm trying to make is, no one is perfect to start with. As a programmer, I was happy with my code 6 months back. Now I despise it. It is not something I can work on anymore. So rather than choosing to ignore the mistakes, swallow your ego, acknowledge the mistakes and redo it. Yes it is hard, painful, time consuming and costly. But software is a continuous process and the continuity is there for us to learn, undo and redo things the right way. I bet I will find blunders again after 6 months, but they will not be as bad as those I've found now. Maybe then, I can afford to patch things up, and be on my way.

For now, back to Software engineering : a practitioner's approach by Pressman

P.S: This post is more of a reminder to myself than to others.

Tagged as: 4 Comments