RSS
 

Archive for the ‘Google Reader’ Category

Local Storage And How To Use It On Websites

11 Oct


Smashing-magazine-advertisement in Local Storage And How To Use It On WebsitesSpacer in Local Storage And How To Use It On Websites
 in Local Storage And How To Use It On Websites  in Local Storage And How To Use It On Websites  in Local Storage And How To Use It On Websites

Storing information locally on a user’s computer is a powerful strategy for a developer who is creating something for the Web. In this article, we’ll look at how easy it is to store information on a computer to read later and explain what you can use that for.

[Offtopic: by the way, did you already get your copy of the Smashing Book?]

Adding State To The Web: The “Why” Of Local Storage

The main problem with HTTP as the main transport layer of the Web is that it is stateless. This means that when you use an application and then close it, its state will be reset the next time you open it. If you close an application on your desktop and re-open it, its most recent state is restored.

This is why, as a developer, you need to store the state of your interface somewhere. Normally, this is done server-side, and you would check the user name to know which state to revert to. But what if you don’t want to force people to sign up?

This is where local storage comes in. You would keep a key on the user’s computer and read it out when the user returns.

C Is For Cookie. Is That Good Enough For Me?

The classic way to do this is by using a cookie. A cookie is a text file hosted on the user’s computer and connected to the domain that your website runs on. You can store information in them, read them out and delete them. Cookies have a few limitations though:

  • They add to the load of every document accessed on the domain.
  • They allow up to only 4 KB of data storage.
  • Because cookies have been used to spy on people’s surfing behavior, security-conscious people and companies turn them off or request to be asked every time whether a cookie should be set.

To work around the issue of local storage — with cookies being a rather dated solution to the problem — the WHATWG and W3C came up with a few local storage specs, which were originally a part of HTML5 but then put aside because HTML5 was already big enough.

Using Local Storage In HTML5-Capable Browsers

Using local storage in modern browsers is ridiculously easy. All you have to do is modify the localStorage object in JavaScript. You can do that directly or (and this is probably cleaner) use the setItem() and getItem() method:

localStorage.setItem('favoriteflavor','vanilla');

If you read out the favoriteflavor key, you will get back “vanilla”:

var taste = localStorage.getItem('favoriteflavor');
// -> "vanilla"

To remove the item, you can use — can you guess? — the removeItem() method:

localStorage.removeItem('favoriteflavor');
var taste = localStorage.getItem('favoriteflavor');
// -> null

That’s it! You can also use sessionStorage instead of localStorage if you want the data to be maintained only until the browser window closes.

Working Around The “Strings Only” Issue

One annoying shortcoming of local storage is that you can only store strings in the different keys. This means that when you have an object, it will not be stored the right way.

You can see this when you try the following code:

var car = {};
car.wheels = 4;
car.doors = 2;
car.sound = 'vroom';
car.name = 'Lightning McQueen';
console.log( car );
localStorage.setItem( 'car', car );
console.log( localStorage.getItem( 'car' ) );

Trying this out in the console shows that the data is stored as [object Object] and not the real object information:

Console-e1285930679229 in Local Storage And How To Use It On Websites

You can work around this by using the native JSON.stringify() and JSON.parse() methods:

var car = {};
car.wheels = 4;
car.doors = 2;
car.sound = 'vroom';
car.name = 'Lightning McQueen';
console.log( car );
localStorage.setItem( 'car', JSON.stringify(car) );
console.log( JSON.parse( localStorage.getItem( 'car' ) ) );

Console2-e1285930703974 in Local Storage And How To Use It On Websites

Where To Find Local Storage Data And How To Remove It

During development, you might sometimes get stuck and wonder what is going on. Of course, you can always access the data using the right methods, but sometimes you just want to clear the plate. In Opera, you can do this by going to Preferences → Advanced → Storage, where you will see which domains have local data and how much:

Storage-opera in Local Storage And How To Use It On Websites
Large view

Doing this in Chrome is a bit more problematic, which is why we made a screencast:

Mozilla has no menu access so far, but will in future. For now, you can go to the Firebug console and delete storage manually easily enough.

So, that’s how you use local storage. But what can you use it for?

Use Case #1: Local Storage Of Web Service Data

One of the first uses for local storage that I discovered was caching data from the Web when it takes a long time to get it. My World Info entry for the Event Apart 10K challenge shows what I mean by that.

When you call the demo the first time, you have to wait up to 20 seconds to load the names and geographical locations of all the countries in the world from the Yahoo GeoPlanet Web service. If you call the demo a second time, there is no waiting whatsoever because — you guessed it — I’ve cached it on your computer using local storage.

The following code (which uses jQuery) provides the main functionality for this. If local storage is supported and there is a key called thewholefrigginworld, then call the render() method, which displays the information. Otherwise, show a loading message and make the call to the Geo API using getJSON(). Once the data has loaded, store it in thewholefrigginworld and call render() with the same data:

if(localStorage && localStorage.getItem('thewholefrigginworld')){
  render(JSON.parse(localStorage.getItem('thewholefrigginworld')));
} else {
  $('#list').html('

'+loading+' '); var query = 'select centroid,woeid,name,boundingBox'+ ' from geo.places.children(0)'+ ' where parent_woeid=1 and placetype="country"'+ ' | sort(field="name")'; var YQL = 'http://query.yahooapis.com/v1/public/yql?q='+ encodeURIComponent(query)+'&diagnostics=false&format=json'; $.getJSON(YQL,function(data){ if(localStorage){ localStorage.setItem('thewholefrigginworld',JSON.stringify(data)); } render(data); }); }

You can see the difference in loading times in the following screencast:

The code for the world info is available on GitHub.

This can be extremely powerful. If a Web service allows you only a certain number of calls per hour but the data doesn’t change all that often, you could store the information in local storage and thus keep users from using up your quota. A photo badge, for example, could pull new images every six hours, rather than every minute.

This is very common when using Web services server-side. Local caching keeps you from being banned from services, and it also means that when a call to the API fails for some reason, you will still have information to display.

getJSON() in jQuery is especially egregious in accessing services and breaking their cache, as explained in this blog post from the YQL team. Because the request to the service using getJSON() creates a unique URL every time, the service does not deliver its cached version but rather fully accesses the system and databases every time you read data from it. This is not efficient, which is why you should cache locally and use ajax() instead.

Use Case #2: Maintaining The State Of An Interface The Simple Way

Another use case is to store the state of interfaces. This could be as crude as storing the entire HTML or as clever as maintaining an object with the state of all of your widgets. One instance where I am using local storage to cache the HTML of an interface is the Yahoo Firehose research interface (source on GitHub):

The code is very simple — using YUI3 and a test for local storage around the local storage call:

YUI().use('node', function(Y) {
  if(('localStorage' in window) && window['localStorage'] !== null){
    var key = 'lastyahoofirehose';
  
    localStorage.setItem(key,Y.one('form').get('innerHTML'));
  
  if(key in localStorage){
      Y.one('#mainform').set('innerHTML',localStorage.getItem(key));
      Y.one('#hd').append('

Notice: We restored your last search for you - not live data'); } } });

You don’t need YUI at all; it only makes it easier. The logic to generically cache interfaces in local storage is always the same: check if a “Submit” button has been activated (in PHP, Python, Ruby or whatever) and, if so, store the innerHTML of the entire form; otherwise, just read from local storage and override the innerHTML of the form.

The Dark Side Of Local Storage

Of course, any powerful technology comes with the danger of people abusing it for darker purposes. Samy, the man behind the “Samy is my hero” MySpace worm, recently released a rather scary demo called Evercookie, which shows how to exploit all kind of techniques, including local storage, to store information of a user on their computer even when cookies are turned off. This code could be used in all kinds of ways, and to date there is no way around it.

Research like this shows that we need to look at HTML5′s features and add-ons from a security perspective very soon to make sure that people can’t record user actions and information without the user’s knowledge. An opt-in for local storage, much like you have to opt in to share your geographic location, might be in order; but from a UX perspective this is considered clunky and intrusive. Got any good ideas?

(al)


© Christian Heilmann for Smashing Magazine, 2010. | Permalink | Post a comment | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine
Post tags: , , , ,

 
 

Life after Google: Brad Neuberg’s HTML5 start-up

11 Oct
Former Gmail programmer and Google developer advocate believes it's time to break with past browsers and really push what can be done with new Web technologies.

Originally posted at Deep Tech

 
 

25+ Web Designs with TyPoGrApHy as a Dominating Design Element

10 Oct

25+ Web Designs with TyPoGrApHy as a Dominating Design Element

I lave the diversity and creativity found in web design. With hundred millions of web pages to compete with it is important to have a unique and compelling look and feel. There are many ways to achieve this and working with typography is certainly a good option. This article present a bunch of web sites that have designs making heavy use of typography to deliver the main message.


WooThemes - Made by Designers
WooThemes - Made by Designers

waytoogood

salfordstories

foxbone

davidbatra

jprasanen

ourdollarwedding

piksal

surinderthakur

stockholmhairdresser

youandigraphics

.freshme

solidpink

egoitzosa

galp

lemo-design

talkingtelford

thisismypixel

.fsmdesign

tvlcorp

ins.pire.me

fealves htgmeb

Feed provided by tripwrire magazine, Visit this post here: Permalink

 
 

Happy Douglas Adams Day!

10 Oct
Douglas Adams fans would know that 42 is the Ultimate Answer to the Ultimate Question of Life, the Universe, and Everything, calculated in 7.5 million years by a supercomputer named Deep Thought. Today is the 10th day of the 10th month of the year, and if Y2K never happened, this year would be ’10. In binary notation, 101010 is 42 in base 10. Today’s the answer to Life, the Universe, and Everything! Happy Douglas Adams Day!
 
 

Happy Douglas Adams Day!

10 Oct
Douglas Adams fans would know that 42 is the Ultimate Answer to the Ultimate Question of Life, the Universe, and Everything, calculated in 7.5 million years by a supercomputer named Deep Thought. Today is the 10th day of the 10th month of the year, and if Y2K never happened, this year would be ’10. In binary notation, 101010 is 42 in base 10. Today’s the answer to Life, the Universe, and Everything! Happy Douglas Adams Day!
 
 

Google pulls an Asimov, announces self-driving cars smart enough to take on traffic

09 Oct

Knight Rider“So we have developed technology for cars that can drive themselves,” Google engineer Sebastian Thrun nonchalantly announced on the company’s blog earlier this afternoon.

Thrun, who is the director of the Stanford Artificial Intelligence Laboratory and co-inventor of Google’s Street View service, said that the company’s goal is to prevent traffic accidents, give people more free time, and reduce carbon emissions by changing the way people use their cars.

Google CEO Eric Schmidt said last week at the TechCrunch 50 conference in San Francisco that he believed self-driving cars would eventually do a better job of driving than people. While some may have considered his vision to be a far off work of science fiction, today’s announcement proves that self-driving technology is already here — and apparently it works very well.

The automated cars — which are manned by trained operators — have covered over 140,000 miles so far with occasional human control, the New York Times reports. Seven cars have driven 1,000 miles without any human intervention at all. They’ve traveled from Google’s Mountain View offices to its Santa Monica location and on to Hollywood Boulevard. “They’ve driven down Lombard Street, crossed the Golden Gate bridge, navigated the Pacific Coast Highway, and even made it all the way around Lake Tahoe,” Thrun writes.

The cars use radar sensors, video cameras, and a laser range finder which helps them detect other traffic. They also take advantage of detailed maps, which are collected by Google’s manually driven vehicles. The company is working with engineers who’ve taken part in the DARPA Challenges — autonomous vehicle races put together by the U.S. government. Thrun himself led the Stanford team to win the 2005 Darpa Challenge with their Stanley automated car.

Thrun believes that Google’s automated cars could potentially cut the 1.2 million lives lost every in road accidents (according to the World Health Organization) in half. He’s confident that the cars will reduce car usage, change the shape of car sharing, and create new “highway trains of tomorrow.” “These highway trains should cut energy consumption while also increasing the number of people that can be transported on our major roads,” he wrote.

The project is certainly a major new step into robotics for Google, although the company doesn’t yet know how it will create a business from the automated cars. Google may be able to sell its information and navigation services to autonomous vehicle makers, or it might sell or give away the navigation technology itself, according to the New York Times.

Tags: , , , ,

Companies: , ,

People:




 
 

Cool Evolution Trick: Platinum Turns Baby Snails Into Slugs

08 Oct

Marisa cornuarietis snail

Evolution doesn’t have to operate at a snail’s pace, even for snails. In experiments designed to simulate the evolutionary transition that produced slugs, researchers exposed baby snails to the metal platinum, causing the animals to develop without external shells. The research illustrates how a big leap on the evolutionary path of animal body plans might have occurred. It also reopens a can of worms concerning the development and evolution of an entire class of shelled creatures.

sciencenewsScientists reared Marisa snails, best known for cleaning up algae and other debris in home aquariums, in petri dishes containing varying concentrations of platinum. At certain exposures, all of the roughly 80 percent of snails that survived were shell-less, Heinz Köhler of the University of Tübingen in Germany and his colleagues report in the September-October Evolution & Development. The researchers posit that the platinum is causing effects similar to the genetic mutation that turned off shell production in some snails, paving the way for their slug descendants.

“This shows that you can get really dramatic changes that could be similar to the genetic mutations that drive evolution, without worrying about doing everything in small incremental steps,” says comparative physiologist Roger Croll of Dalhousie University in Halifax, Nova Scotia. “This is a very concrete demonstration, a very clear demonstration of a large-scale change in body plan. All of a sudden you get shell-less animals.”

Evidence suggests that transitions from snails to slugs — or rather, from having a concrete outer shell to a greatly reduced internal one — have happened numerous times in evolution. Such losses or gains occurred repeatedly within the Mollusca, an enormous group that includes clams, oysters, squid, octopuses and of course the gastropods —snails and slugs. The internal flat bone of cuttlefish and squid, for example, is thought to be a pared-down version of an ancestral outer molluscan shell. And the shell game continued within the gastropods. Within the marine gastropods known as sea butterflies and sea hares, for example, there are both shelled and shell-less species.

Though the new study shows that shell loss in gastropods can happen in one fell swoop, it also suggests that another evolutionary transition might have required several steps to complete. Torsion is an anatomical hallmark of the gastropods that makes them look like their bottom halves were rotated 180 degrees relative to their top halves, putting their anuses over their heads. The term torsion also refers to the hypothetical evolutionary process that purportedly led to this awkward anatomy, says evolutionary biologist Louise Page of the University of Victoria in British Columbia.

The new research suggests that torsion might not have occurred in one grand swivel. In many gastropods the anus, gills and mantle cavity are rotated 180 degrees. But in some there is partial rotation. And in the snails that Köhler and his colleagues exposed to platinum there was partial rotation as well: The anus swiveled but the gills and mantle were left in their original positions. This suggests that the gastropod body plan could have arisen through physiological means other than torsion, such as asymmetrical growth, where one half of the body atrophied and the other blossomed.

“This paper helps people to think about the fact that these anatomical positions are not necessarily coupled together,” says Page. “It really demonstrates that development is modular, that you can have quite drastic modifications of the development of one component of the body plan but not others.”

See Also:

Image: Goethe University

 
 

A computer learns the hard way: By reading the Internet [Artificial Intelligence]

08 Oct
At Carnegie-Mellon university, a massive computer system called NELL (Never Ending Language Learner) is systematically reading the internet and analyzing sentences for semantic categories and facts, teaching itself English and educating itself in human affairs. We spoke to NELL's creators. More »
 
 

Extreme black holes billions of years ago overheated the universe [Mad Astrophysics]

08 Oct
Global warming really isn't just a local problem...universal warming ran through the universe 11 billion years ago, doubling the temperature of intergalactic helium. The cosmic temperature spike was so bad, it stopped galaxies from developing for 500 million years. More »
 
 

Solar System’s Deepest Canyon Sinks Miles Into Mars

08 Oct

Mars Valles Marineris rift valley

On the Martian surface, the mountains are high and the canyons are low. Really, really low.

Not only is the martian volcano Olympus Mons the highest peak in the solar system, Melas Chasma, the canyon pictured above, is the deepest in the solar system. In this image from the European Space Agency’s Mars Express orbiter, the valley on the left (darker area) sits a whopping 5.6 miles below the plateau on the right (lighter area).

Compared to the average shape of Mars, known as the “aeroid,” the canyon floor sinks down about 3.1 miles. Planetary scientists would love to use sea level measurements to describe Martian surface features, but there’s no ocean on the red planet anymore and any signs of an ocean are long since warped by millions of years of surface deformation.

The photo above covers about 7,700 square miles, or about the size of New Jersey, which makes it only a tiny postage stamp of Mars’ deepest, longest and most prominent scar — the 2,500-mile-long Valles Marineris rift valley (below).

Valles Marineris rift copyright of JPL

ESA also released the following 3-D rendering of Melas Chasma in addition to the satellite imagery, revealing the valley in all its topographical glory (via Nancy Atkinson at Universe Today).

Melas Chasma 3-D

Images: 1) Melas Chasma – high-resolution image, ESA/DLR/FU Berlin (G. Neukum), 2) Viking 1 and 2 orbiter image collage of Valles Marineris canyon – high-resolution image. Courtesy NASA/JPL-Caltech, 3) Melas Chasma – high-resolution image, ESA/DLR/FU Berlin (G. Neukum),

See Also:

Follow us on Twitter @davemosher and @wiredscience, and on Facebook.