Saturday, 02 November 2013

Self Freezing Coca-Cola (The trick that works on any soda!)

http://www.youtube.com/v/5T68TvdoSbI?autohide=1&version=3&showinfo=1&feature=share&autohide=1&attribution_tag=mlEac6pbTeavddVGEj1_fA&autoplay=1

Sunday, 13 October 2013

So Singletons are bad, then what?


So Singletons are bad, then what?

This was taken from an article/question posted on stackexchange, Just got schooled this explaintion couldnt have put it in a better form if i tried!
Thanks to Aaronaught 
It's important to distinguish here between single instances and the Singleton design pattern.
Single instances are simply a reality. Most apps are only designed to work with one configuration at a time, one UI at a time, one file system at a time, and so on. If there's a lot of state or data to be maintained, then certainly you would want to have just one instance and keep it alive as long as possible.
The Singleton design pattern is a very specific type of single instance, specifically one that is:
  • Accessible via a global, static instance field;
  • Created either on program initialization or upon first access;
  • No public constructor (cannot instantiate directly);
  • Never explicitly freed (implicitly freed on program termination).
It is because of this specific design choice that the pattern introduces several potential long-term problems:
  • Inability to use abstract or interface classes;
  • Inability to subclass;
  • High coupling across the application (difficult to modify);
  • Difficult to test (can't fake/mock in unit tests);
  • Difficult to parallelize in the case of mutable state (requires extensive locking);
  • and so on.
None of these symptoms are actually endemic to single instances, just the Singleton pattern.
What can you do instead? Simply don't use the Singleton pattern.
Quoting from the question:
The idea was to have this one place in the app which keeps the data stored and synced, and then any new screens that are opened can just query most of what they need from there, without making repetitive requests for various supporting data from the server. Constantly requesting to the server would take too much bandwidth - and I'm talking thousands of dollars extra Internet bills per week, so that was unacceptable.
This concept has a name, as you sort of hint at but sound uncertain of. It's called a cache. If you want to get fancy you can call it an "offline cache" or just an offline copy of remote data.
A cache does not need to be a singleton. It may need to be a single instance if you want to avoid fetching the same data for multiple cache instances; but that does not mean you actually have to expose everything to everyone.
The first thing I'd do is separate out the different functional areas of the cache into separate interfaces. For example, let's say you were making the world's worst YouTube clone based on Microsoft Access:
                          MSAccessCache
                                ▲
                                |
              +-----------------+-----------------+
              |                 |                 |
         IMediaCache      IProfileCache      IPageCache
              |                 |                 |
              |                 |                 |
          VideoPage       MyAccountPage     MostPopularPage
Here you have several interfaces describing the specific types of data a particular class might need access to - media, user profiles, and static pages (like the front page). All of that is implemented by one mega-cache, but you design your individual classes to accept the interfaces instead, so they don't care what kind of an instance they have. You initialize the physical instance once, when your program starts, and then just start passing around the instances (cast to a particular interface type) via constructors and public properties.
This is called Dependency Injection, by the way; you don't need to use Spring or any special IoC container, just so long as your general class design accepts its dependencies from the caller instead of instantiating them on its own or referencing global state.
Why should you use the interface-based design? Three reasons:
  1. It makes the code easier to read; you can clearly understand from the interfaces exactly what data the dependent classes depend on.
  2. If and when you realize that Microsoft Access wasn't the best choice for a data back-end, you can replace it with something better - let's say SQL Server.
  3. If and when you realize that SQL Server isn't the best choice for media specifically, you can break up your implementation without affecting any other part of the system. That is where the real power of abstraction comes in.
If you want to take it one step further then you can use an IoC container (DI framework) like Spring (Java) or Unity (.NET). Almost every DI framework will do its own lifetime management and specifically allow you to define a particular service as a single instance (often calling it "singleton", but that's only for familiarity). Basically these frameworks save you most of the monkey work of manually passing around instances, but they are not strictly necessary. You do not need any special tools in order to implement this design.
For the sake of completeness, I should point out that the design above is really not ideal either. When you are dealing with a cache (as you are), you should actually have an entirely separate layer. In other words, a design like this one:
                                                        +--IMediaRepository
                                                        |
                          Cache (Generic)---------------+--IProfileRepository
                                ▲                       |
                                |                       +--IPageRepository
              +-----------------+-----------------+
              |                 |                 |
         IMediaCache      IProfileCache      IPageCache
              |                 |                 |
              |                 |                 |
          VideoPage       MyAccountPage     MostPopularPage
The benefit of this is that you never even need to break up your Cache instance if you decide to refactor; you can change how Media is stored simply by feeding it an alternate implementation ofIMediaRepository. If you think about how this fits together, you will see that it still only ever creates one physical instance of a cache, so you never need to be fetching the same data twice.
None of this is to say that every single piece of software in the world needs to be architected to these exacting standards of high cohesion and loose coupling; it depends on the size and scope of the project, your team, your budget, deadlines, etc. But if you're asking what the best design is (to use in place of a singleton), then this is it.
P.S. As others have stated, it's probably not the best idea for the dependent classes to be aware that they are using a cache - that is an implementation detail they simply should never care about. That being said, the overall architecture would still look very similar to what's pictured above, you just wouldn't refer to the individual interfaces as Caches. Instead you'd name them Services or something similar.

Friday, 03 August 2012


The iPad’s Smart Cover Could Someday Be A Second Display








Apple is trying to patent a Smart Cover for the iPad that has an embedded secondary display. Or in other words: eat it, Surface.

The cover would use a connector on the side of the iPad that would supply data and power to the cover. Here’s Apple’s description from the application:


[The] accessory device comprising: a flexible flap having a size and shape in accordance with the host device display, wherein at least a portion of the flexible flap is covered by a flap display configured to present visual information; and a connecting portion, the connecting portion arranged to provide at least a communication channel arranged to convey information between the host device and the accessory device wherein at least some of the information is presented visually on the flap display.

It looks pretty cool. But applying for a patent doesn’t necessarily mean we’re going to see this, or that Apple even has the technology to pull this off. For now, it should put Microsoft and its Surface keyboard covers on notice. [USPTO via Engadget]

Thursday, 26 July 2012

Android NFC 'hacking' is ingenious, but not yet dangerous


Android Central


The Black Hat Conference takes place in Las Vegas this week, where hackers, security experts and representatives from major companies meet to discuss all things relating to information security. If you're following the news out of the conference today, you may have come across reports of a new security vulnerability in Android (and NFC-enabled Meego phones) that could allow a malicious NFC (near-field communication) tag to beam malware directly onto your phone. Sounds terrifying, right? Now hackers can take over your smartphone without you even doing anything. But as is always the case with these kinds of security issues, it's not as simple as it seems, and this NFC 'hack,' sexy and technically impressive as it is, isn't really anything particularly scary to regular smartphone users.
Read on to find out why.
First off, we should quickly explain what NFC actually is. It stands for near-field communication, and it's a a very short-range wireless communication technology designed for sending small amounts of data instantly over very short distances. On smartphones, this can be used to transfer things like URLs from one handset to another, or alternatively to scan NFC "tags," which can themselves contain small quantities of data that the phone can then act upon. It can also be used for facilitate payments, for example via Google Wallet. (Read more in our Android A-Z)
Multiple sources report that security researcher Charlie Miller demonstrated a variety of techniques for hacking into the Nexus S (on Gingerbread), the Galaxy Nexus (on Ice Cream Sandwich) and the Meego-powered Nokia N9 at Black Hat this week. Many of the scariest exploits were found on the N9, but we'll focus on Android here, 'cause that's what we do. (And that's also what many of today's headlines focus on.)
Starting at the high end, on the Galaxy Nexus Miller demonstrated that NFC-enabled Android phones running Ice Cream Sandwich or later use Android Beam, a feature which some (but not all) them have turned on by default. Amongst other things, Beam lets users load URLs from another phone or NFC tag directly into the device's web browser. That means it's possible, with a malicious NFC tag, to send an unassuming user directly to a malicious web page. For that to work, though, the tag needs to be within the very short range at which NFC radios can operate -- basically all but touching the back of the device. Android Beam opens tagged URLs automatically without any prompt, by design. It's a valid security concern, but not an exploit in the traditional sense, as in order to do anything you need to find a vulnerability in the user's web browser of choice.
If you're using the built-in Android browser on Android 4.0.1, then such a bug exists, and that could allow a specially designed web page to run code on the device. Again, an entirely valid security issue, but using NFC as a delivery method for this kind of exploit is far from practical. (Not to mention Android 4.0.1 was only released on the Galaxy Nexus, a phone which has since been updated to Android 4.0.4 or 4.1.1, depending on your carrier.)
Miller also demonstrated how he could exploit bugs in Android 2.3's memory management to cause a Gingerbread device with NFC support to execute code using a malicious tag. That potentially gives an attacker the ability to take complete control of the device using only an NFC tag, but we should point out a few factors that make this a less serious issue that you might think. Sure, Android 2.3 Gingerbread is still the most-used version of Android, and many new Android devices ship with NFC support, but there's little cross-over between the two. The Nexus S was the first Android handset to support NFC, but that's since been updated to Jelly Bean. Other NFC-supporting devices may remain on 2.3, but most of the mainstream Android phones with NFC run at least version 4.0.3, which isn't vulnerable to the exploits used in this demo. In fact, we can't think of a single Gingerbread phone with NFC that's yet to be updated to at least Android 4.0.3.
So vulnerabilities certainly exist, but right now the only serious ones are limited to a very small subset of the Android population with NFC, and a very specific OS version. What's more, the phone needs to be powered on, the NFC radio needs to be enabled, and the user needs to be distracted enough so as not to notice the tell-tale NFC tone or vibration.
Ultimately, any exploit involving physical access to the device being hacked is going to be of limited use to the real bad guys. Taking control of a smartphone over NFC in the real world is going to be dangerous and impractical, even after the methods shown at the Black Hat Conference are publicized. If I have access to your phone, powered on, for an extended period, with malicious intent, NFC isn't going to be my first port of call. The exploits demonstrated by Charlie Miller this week are ingenious and cool to read about, but it's easy to exaggerate the real danger posed by them, especially when mainstream reporting of these hacks is light on important technical details.
Bottom line -- if you enjoy using NFC on your Android phone from time to time, you're safe to continue doing just that.

How Roku Could Win Media Streaming

How Roku Could Win Media Streaming

How Roku Could Win Media Streaming


The Roku is a hell of a media streamer: its only real competitor is the Apple TV, but it costs half as much. No brainer. Which is exactly what News Corp and British Sky Broadcasting seem to think—as they've just ponied up $45 million to help Roku win the streaming race.
Announcing the investment this morning, Roku explained that it will be using the cash to expand its current organization and push forward with the Roku stick which it plans to launch this fall. The stick, which packs all the features of the small box currently available, will shove straight into the back of your TV. Completely unobtrusive, and potentially brilliant.
The investment will see News Corp's Chief Digital Officer Jon Miller join the Roku board, but most importantly it will give the company a shot in the arm which could see it jump from key player in the sector to market leader. It'll be exciting to see what Roku does next. [All Things D]

Wednesday, 18 July 2012

LARGE BREASTS: A FEMALE PERSPECTIVE



LARGE BREASTS: A FEMALE PERSPECTIVE


She's had big boobs for 20 years and here's her view from the other side of the mountains

by Sarah Miller
Mens Health


I'm 32, so let's say, roughly, that my breasts were on their path to greatness halfway through the De Klerk administration. By the time Mandela was sworn in, I was officially stacked.

I first realized I had big breasts when I was about 12, in, of all places, a fish market on Cape Cod. For years, the fishmonger had been showing my buxom aunt marked favoritism. "This is for you," he would say, measuring out what she'd asked for, then, with a wink and a glimpse at her bustline, tossing on a few more shrimp or an extra fillet.

On this particular day, he threw a handful of extra shrimp onto the pile and, ignoring my aunt, turned his gaze on me. "A little extra nutrition for the growing girl," he said. Holy hell, I said to myself, I have big boobs, too!

By the time I was 13, I had a C-cup, and by the time I was 15, a D. Today, I hover between a 34 and a 36D, depending on whether I'm on the Pill, and, disgustingly, how much beer I've been drinking. Either way, they garner their share of attention—wanted or otherwise.

There are times when it all seems quite silly to me, when I look at mine in the mirror and think, what a lot of excitement over two little—okay, enormous—mounds of fat! Then again, there's the occasional moment when I'll pull an old cotton T-shirt out of the dryer and slip it, still warm and quite tight, over my head, the name of my old university straining across my front.

And as I happen to catch a glimpse of myself in the mirror, I can't help but think of Teri Hatcher's line from that old Seinfeld episode: "They're real, and they're spectacular."

I know men like to think that women lie around all day touching and staring at their breasts. Well, every once in a while, in fact, we do. But aside from the odd afternoon interlude, most women don't find their own breasts especially sexual. Our breasts kind of have two—well, four—personalities. There is How We See Them. And then there is How Men See Them...
How We See Them

As fashion accessories. When I buy a dress, I don't consciously think, Wow, this is going to make all the men in the room want me. More like, How will it offset my best feature?

I know what you're thinking: Nothing low-cut was ever purchased in innocence. I swear to you, my breasts and I, we never conspire. We're just trying to look our best.

I feel about my breasts the way Audrey Hepburn felt about her neck. They're just part of my outfit, along with the right shoes, the right hose, the right earrings. All of which, of course, means nothing when confronted with...
How Men See Them

Simple: as the very focal point of the entire world. The male gaze flies past all my attempts to craft an individual style and makes a beeline for the breasts.

On the one hand, this is not so bad. I have worn the same tasteful yet cleavage-enhancing black dress to every party I've been to for 3 years. I've thought about buying a new one, but who would notice? Think: Who at your Thanksgiving table will complain about mashed potatoes or squash when your bird is so plump and juicy?

I am not always the best-looking or most sought-after girl at the party. But I always look appropriately festive, men tell me that I look nice, and if you ever spot someone waving a twenty at the bartender to get his attention...chances are that someone isn't me.

The downside is that many potentially fascinating conversations get lost inside my plunging neckline. For a while I tried wearing necklaces—I read in a women's magazine (a dubious source of information on any topic other than osteoporosis) that this would "draw the eye upward." Unfortunately, it merely provided an excuse for men's eyes to linger in this general area:

"Hey, is that a necklace? It's nice; where did you get it?"

"England."

"I've never been to England, but the longer I look at this necklace, you know, the more I feel I have."

My advice, should you find yourself chatting with an amply endowed female, is to practice restraint. It's not that we mind you looking at our breasts; it's just that seeing you do it is creepy. The stare, obviously, is bad, and the quick, subtle glance is never as quick or subtle as you hope.

Try using your powers of reconnaissance; stare sideways at a woman while you're talking to another man, and then, later, when you start up a conversation with her, look her in the eye while enjoying the mental picture of her breasts.

This might all sound complicated, but it's really not. For those of you who need a little motivation, remember that while prisoners get time off for good behavior, you get shirts off.

Of course, it's during the shirts-off phase that the difference between How We See Them and How Men See Them is most interesting. Men are always a bit amazed to see a pair of naked breasts, and their amazement level increases with quality and size.

So I come to that naked-from-the-waist-up moment with mixed emotions. On the one hand, I am so totally over these things. On the other hand, hello, you are beholding items of serious quality, and son, you'd better recognize it.

If this sounds like just one more damned-if-you-do, damned-if-you-don't chick rule, I apologize. I have always been a fan of the quick, sincere compliment. ("Whoa, nice rack," is not what I have in mind. "Wow, you have gorgeous breasts," is more like it). Living every day with these things, we tend to forget how interesting and sexy they are to people who don't live with them, and it's nice to be reminded.

That takes care of the talking part. As to what you do, well, it's really a matter of personal taste among consenting adults. I was with a group of women lately, and one wished her boyfriend would touch her breasts more when they had sex. Her friend made a face and said her boyfriend was much, much too fixated on hers. I suggested they switch boyfriends.
Bottom line:

If you ask most women what they like, they'll be happy to tell you.

After 20 years of having big breasts, I look down at them and ask, What have you done for me lately? I do get to walk around as the proud owner of these things that women want and men want to touch. On bad days, when I'm heartbroken, or just plain broke, I have consoled myself with this fact. (Yes, I do know that's lame.)

I'm aware of the preconception that women with big breasts can coast through life unchecked, but I haven't gotten as much free fish as you might think. Rental-car agents don't neglect to charge me when I scratch the Toyota Corrolla. When I speed, cops write me massive tickets just like everyone else.

I get the same amount of bad news and good news everyone else gets; it's just that whoever delivers it often does so staring at my boobs.

Still, even though women and men--possessors and obsessors--don't see breasts the same way, our two worldviews can coexist. We women need to remember that what we take for granted are two of your main reasons for living. You men need to remember that breasts are flesh and blood, not Fisher-Price toys.

Let's cut a deal. We'll wear nothing but low-cut shirts... if you promise to listen to everything we say when we're wearing them.

Tuesday, 17 July 2012


iPhone 5 will use nano-SIM

The iPhone 5 will be the first mobile handset to use the new nano-SIM design and European networks are already stocking-up



















The iPhone 5 will be launched soon and it’ll be the first device to use the new nano-SIM card design, which is even smaller than micro-SIMs. 
A report from the Financial Times claims carrier networks in Europe are now stocking up on nano-SIMs in anticipation of the iPhone 5 release
The nano-SIM design was recently approved as new standard by the European Telecommunications Standards Institute (ETSI) after reaching an agreement with major manufacturers. 
There was some reasonably well-publicised competition between Apple and a collective of Motorola, RIM and Nokia, each with different proposals for the new nano-SIM design, but after prompting from ETSI the group eventually reached a consensus. 
The new cards are 40 per cent smaller than existing micro-SIMs, which are themselves still by no means ubiquitous – there are still plenty of handsets on the market using conventional, full-size SIM cards. Micro-SIMs first appeared with the iPad in 2010 and now several premium smartphone models use them, including the HTC One X and the Nokia Lumia 800. 
The new design measures 12.3mm long by 8.8mm wide and there’s now very little excess material surrounding the metal chip component. ETSI’s announcement assured that the new SIM could be ‘‘packaged and distributed in a way that is backwards compatible with existing SIM card designs.’ 
The smaller form factor of micro-SIMs and nano-SIMs enables manufacturers to come up with thinner, unibody phone designs, although current rumour surrounding the iPhone 5 suggests it’ll feature an aluminium back panel.