Book Review - Object Oriented JavaScript

OOJS

Object Oriented Javascript

By: Stoyan Stefanov

I found that this book covers JavaScript in a way that makes
it easier to grasp some of the quirks of JS as well has the proper way
to use it without a lot of “don’t try this in a real program, kids” way.
Some of the things are not covered in much depth but that’s when you crack
open JavaScript the definitive guide which is still, in my opinion, the
ultimate JS bible. I’m going to give this book 5 out of 5 stars for great
advice and an awesome refresher.


Storing objects in localStorage

Storing objects in localStorage

In the past week I’ve been looking into the different flavors of client side
storage and how they differ. localStorage is one of the solutions offered which has
the advantage of being covered by a W3C spec but only saves key/value pairs so if you
want to store an object you’re out of luck, right? Wrong.

First a little about local storage…

The formula for adding to localStorage is pretty straight forward.

localStorage.setItem('key','value')

…saves a key/value pair while…

localStorage.getItem('key')

retrieves a set key/value pair. You can also remove an item by calling..

localStorage.removeItem('key')

or remove all items in your site’s storage
with…

localStorage.clear().

Now back to storing objects. Take the following petNames object below as an example:

var petNames = { dog: 'TiVo',
                  cat: 'Flickr',
                  fish: 'Frank'
               };

If you store petNames directly into local storage like this:

localStorage.setItem('petNames', petNames);

and you access the values like this:

var storedPetNames = localStorage.getItem('petNames');

console.log(storedPetNames);

you get this:

[object Object]

That bites, but there is a way to get around this by storing the petNames object as a string.
We can accomplish this by bringing in our old pals JSON.stringify and JSON.parse.

Here’s how to do it:

localStorage.setItem('petNames', JSON.stringify(petNames));

var storedPetNames = JSON.parse(localStorage.getItem('petNames'));

console.log(storedPetNames.cat);

And there you have it - A way to save and retrieve an object in localStorage.
Up next I’ll look into the basics of indexedDB.


Book Review - Here's looking at Euclid

Here's looking at Euclid

Here’s looking at Euclid

By: Alex Bellos

I was late to the world of mathematics. I was going to be a rock star and a drummer at
that so who needs to know anything beyond 1, 2, 3, 4and1, 2, 3, 4and. Really, after years
of being told that some people aren’t good at it I cut my losses and left it behind. Until
I started liking all the cool stuff you could do with it like predict things and figuring
out chicks birthdays at the bar after a rock show. Fast forward to today, I do try to read
at least one good book on mathematics every year and this was, fortunately was one.
Mr. Bellos takes you on a journey through history and gives context to many common mathematical
theories we take for granted today. A very interesting read and worthy of 5 out of 5 stars.


Book Review - Your Money and Your Brain

your money and your brain

Your Money and Your Brain How the new science of NeuroEconomics can help make you rich.

By Jason Zweig

I do like the thought of being rich but I’m not easily fooled by claims most investment books make in their titles. The ‘help make you rich’ part turned me off so I put off getting this book for two years. Fortunately I came across a copy in a used bookstore and was able to actually crack open the book to see that it wasn’t at all about getting rich in that sleazy get rich quick way. After reading the book I don’t remember anything but good, solid investment advice backed by real scientific studies about how your mind reacts to losing, gaining and retaining money. I give this 4 out of 5 stars, 5 out of 5 goes to the author while the marketing department for this publishing company gets a -1 star for the silly and misleading title.


a blog. finally.

Hello again.

I started working on building a new blog site 4 months ago and was
only able to get one up now. I guess that’s what happens when you
work 50+ hours at your day job and then pick up a freelance gig on
the side. Well, there is that and I’m trying to sell a house while attending
one wedding every weekend this summer including my own.. Whew. I have a half complete
diy blog cms that I started working on but due to the time constraints
mentioned above I ended up hijacking Hexo from git hub instead.

What is this blog about?

What you’ll find here going into the future may include tricks and tips I stumble
across while working, book reviews, and updates on my projects. Nothing too
out of the ordinary - it’s a blog - but I’m still really excited to share what I learn
with others no matter what it is, especially if it helps someone out with a project
they’re working on.