GotchaCode

Using HTML5 localStorage Into Your App, Check ldb.js

Last night, I was hacking on a small utility library for use when using HTML5 localStorage. When you work with localStorage, it often gets into repetitive state when use use same command again and again. This library just abstracts the process and makes things easier for you. It would work on all modern browsers.

/**
* Ldb.js
* Copyright(c)2013 Vinit Kumar
* MIT Licensed
*/

var Ldb = function () {};

/**
* [check Checks for localStorage support on the browsers]
* @return {[String]} [status of localStorage Support]
*/
Ldb.prototype.check = function () {
if (!localStorage) {
return 'Please use a Modern browser, your browser does not support localStorage yet';
} else {
return 'Bingo, your Browsers supports localStorage, phew!';
}
};

/**
* [get Gives the data stored in the key]
* @param {[String]} key [Key to retrive the data stored in localStorage]
* @return {[JSON]} [The JSON data stored | Error message saying no data stored with that key]
*/
Ldb.prototype.get = function (key) {
if (localStorage.getItem(key)) {
return JSON.parse(localStorage.getItem(key));
} else {
return 'No such key exists, Are you sure you have saved data with the key?';
}
};

/**
* [set Saved data in the localStorage database]
* @param {[String]} key []
* @param {[JSON]} value [The JSON data that gets stored in the localStorage]
*/
Ldb.prototype.set = function(key, value) {
if (typeof (value) === 'object') {
var stringValue = JSON.stringify(value);
localStorage.setItem(key, stringValue);
return 'Successfully saved your data to the key' + key +' key!';
}
};

/**
* [remove description]
* @param {[String]} key [Key for the data to be deleted]
* @return {[String]} [Status message for the remove operation]
*/
Ldb.prototype.remove = function(key) {
if (localStorage.getItem(key)) {
localStorage.removeItem(key);
return 'Successfully removed data with the key'+ key +' !';
} else {
return 'No such key exists, nothing to remove';
}
};



This is all code for the utility as of now. More features are going to flow in coming weeks. Also, you can just install it using 'npm install ldb' or 'bower install ldb.js'. The code is Open Sourced here. https://github.com/vinitkumar/ldb.js

Classes in JS

Here is an interesting example for Classes in JS. Classes in JS don’t have a class keyword.

How To Focus And Learn One Thing Perfectly?

In Software development, there are so many things to learn. Especially, if you are web developer there are so many things to learn. Should you learn Rails, Django or .NET? Or should you learn Angular, Backbone or Ember?

It is a very tricky question and has been puzzling me for quite sometime. But some time back, it kind of dawned on me that I should just try and own one technology at one time. Say if it's Django try and learn everything about Django. Become the best in your company at Django. The benefits are two fold:
- You will have a stable career and you will be happy with the quality of your work.
- You can use that understanding of that technology with understanding and learning other technologies really fast.

Another problem that I sometime face is lack of motivation to learn if something gets really tough. I learned that instead of setting a super tough goal, I should rather split it up and own it one by one. First of all, it gives me a sense of achievement and confidence. Also, my whole effort would be on completing that goal with best of my abilities.

The things I said above is not rocket science, but if you are at my stage of learning. It might be useful to you.


With that said, May the Force be with you!

                ____                  
_.' : `._
.-.'`. ; .'`.-.
__ / : ___\ ; /___ ; \ __
,'_ ""--.:__;".-.";: :".-.":__;.--"" _`,
:' `.t""--.. '<@.`;_ ',@>` ..--""j.' `;
`:-.._J '-.-'L__ `-- ' L_..-;'
"-.__ ; .-" "-. : __.-"
L ' /.------.\ ' J
"-. "--" .-"
__.l"-:_JL_;-";.__
.-j/'.; ;"""" / .'\"-.
.' /:`. "-.: .-" .'; `.
.-" / ; "-. "-..-" .-" : "-.
.+"-. : : "-.__.-" ;-._ \
; \ `.; ; : : "+. ;
: ; ; ; : ; : \:
; : ; : ;: ; :
: \ ; : ; : ; / ::
; ; : ; : ; : ;:
: : ; : ; : : ; : ;
;\ : ; : ; ; ; ;
: `."-; : ; : ; / ;
; -: ; : ; : .-" :
:\ \ : ; : \.-" :
;`. \ ; : ;.'_..-- / ;
: "-. "-: ; :/." .' :
\ \ : ;/ __ :
\ .-`.\ /t-"" ":-+. :
`. .-" `l __/ /`. : ; ; \ ;
\ .-" .-"-.-" .' .'j \ / ;/
\ / .-" /. .'.' ;_:' ;
:-""-.`./-.' / `.___.'
\ `t ._ / bug
"-.t-._:'





Buying New Books

In the span of two days I have ordered three books: