Staying sharp as a developer

Staying sharp

Being a professional programmer is, for the most part, extremely fulfilling: it stretches you, challenges you and encourages you to venture to places you otherwise might not go. But sometimes work can lull you into a false sense of security where, instead of pushing you to find new ways of approaching a problem, you find yourself following the same old patterns.

In his PyWaw 2015 Keynote "Stopping to Sharpen Your Tools", Brandon Rhodes gave the advice that every now and then a programmer should take stock of the software they use — be it Vim, Emacs, an IDE, or a whole host of other supporting software — and consider what their tools are capable of and whether they are using those capabilities to their full potential.

I also believe that when it comes to using a programming language day-in-day-out it is important to keep your mind keen by constantly solving new and interesting problems.

Being paid to write code is a dream come true, but quite a lot of the time it involves maintaining someone else's code, submitting bug fixes, changing configuration files, or merging minor features. Rarely do you get the satisfaction of starting a project from scratch, or solving a problem from start to finish.

It is for this reason that I advise anyone who writes code for a living to "work" outside of work. It will remind you why you like programming and it will almost certainly improve your abilities as a programmer.

I recently followed my own advice by setting myself the challenge of solving the Project Euler problems in Python 3. To make it more interesting I limited myself to the standard library (which in Python isn't much of a limitation!), no peeking at solutions until I had one myself, use iterators and generators wherever possible, and to unittest everything! The main purpose of all of this was to become more familiar with creating a Python package from scratch with a comprehensive test suite and to use features of Python 3 that I don't usually get to use in my production code.

After a few weeks of solving problems I found, to my suprise, that the good practices I had developed for Project Euler started to seep into my work. An example of this occurred when I was writing some monitoring code. The solution included an AWS Lambda to pull access metrics from a number of log files in S3 and submit them to Cloudwatch. Each line of each log file represented at least one metric (maybe more), which needed to be processed before being submitted to Cloudwatch.

Boto, the Amazon Python client, has the ability to batch up 20 metrics into one request, which vastly improves performance by minimising expensive network I/O, but how should each batch be collected?

One approach would be to set up an empty list for the batch, take each log file, process each line one at a time, append metrics to the batch and, when the batch contains 20 metrics, send it. The code for that would look like this:

def lambda_handler(event, context):
    client = boto3.client('cloudwatch')
    s3_data = event['Records'][0]['s3']
    bucket = s3_data['bucket']['name']
    key = s3_data['object']['key']
 
    namespace = 'access-metrics'
 
    batch = []
    for event in parse_log(bucketkey):
        for metric in process(event):
            batch.append(metric)
            if len(batch) == 20:
                client.put_metric_data(
                    Namespace=namespace,
                    MetricData=batch,
                )
                batch = []
    if batch:
        client.put_metric_data(
            Namespace=namespace,
            MetricData=batch,
        )

(The parse_log and process generators are not included in this snippet for purposes of brevity, but they essentially retrieve a log file and parse each line into events, and process each event for one or more metrics respectively.)

One disadvantage to this solution is that it is very rigid. It is specific to this problem and cannot be reused elsewhere without significant refactoring. It can't be split off into a separate module or package for example. Another is just how untidy it looks. Appearances count for a lot in code and an ever increasing indent in loops and conditionals is a good sign there could be a better way. The duplication of client.put_metric_data to mop up any left over metrics in the last batch should also be a red flag that something isn't as good as it could be.

The opposite approach, and the one I went with, is to treat the log lines as a potentially endless stream of data. It doesn't matter where the stream is coming from, you just have to process it, as it arrives, and worry about batching later. The code for this approach looks something like this:

def batches_of(size, iterable):
    it = iter(iterable)
    while True:
        batch = list(islice(itsize))
        if not batch:
            return
        yield batch
 
def lambda_handler(event, context):
    client = boto3.client('cloudwatch')
    s3_data = event['Records'][0]['s3']
    bucket = s3_data['bucket']['name']
    key = s3_data['object']['key']
 
    namespace_prefix__ = key.partition('/')
    namespace = namespace_prefix + '-access-metrics'
 
    metric_data = (
        metric
        for event in parse_log(bucketkey)
        for metric in process(event)
    )
 
    for batch in batches_of(20metric_data):
        client.put_metric_data(
            Namespace=namespace,
            MetricData=batch,
        )

The advantage here is that the problems of processing log lines and creating batches are encapsulated in separate generators, which makes the approach extremely flexible. If the requirement changed and we needed all of the metrics at once it would be trivial to remove the batching code altogether. Also, the batching itself is independent of the processing code, it doesn't know anything about it; you could apply that function to any iterable and it would still do its job.

In fact, since writing this code I have found other places where batching is useful and have applied the batches_of function to them, despite the fact that they are slightly different problems.

So I guess the moral of all of this is not to expect your work to push you to all the solutions that could be out there. Go out and read about your programming language of choice, listen to talks and watch videos about it, but most of all, use the tools you work with; both in and out of work hours!

How we keep our kids safe online

We know keeping your children safe online can be daunting, but Cocoon is here to help. We’re on a mission to help you feel safe and protect those you love, online and offline.

“Children want their parents to be part of their online life and to talk to them about it just as they do about their day at school,” says Amanda Azeez, associate head of child safety online at the UK’s National Society for the Prevention of Cruelty to Children (NSPCC), in a recent interview.

“To children, online friends are real friends. Online life is real life. There is no distinction. Just like in real life, children need our help to stay safe online.”

It can be daunting to know how to start, and every family is different. We spoke with the parents in our team to find out how they go about it, it may help you:

John, Co-Founder and Head of Software at Cocoon

“There are a few things we do to keep our family safe online, and a few things we’ve tried to teach the kids to help them look out for themselves and each other.

“We use an advert blocker (uBlock Origin, but there are lots of other options out there) because we’ve found that some ads are relatively age-inappropriate. For the younger kids, we don’t let them use apps and games with multiplayer chat. For our older kids, we make sure they know not to trust what other people say about themselves online. They know to never share any details about themselves, especially names, locations and photographs.

“Importantly, they know that it’s OK to come and tell us about anything which worries them. They won’t get into trouble.”

Sanjay, CEO and Co-Founder at Cocoon

“I’ve been amazed at how great our kids’ schools are about online security. They’re not only teaching our kids but giving talks for parents too. As a result, our family is pretty well informed.

“Our children know not to put their real names online, even as an email address or social handle, and not to upload pictures and videos of themselves. They find it hard to understand but know that anything they put online could be there forever, so it’s best to never write anything when angry or upset. They’re pretty savvy! My nine-year-old daughter came home from school the other day saying “Daddy, did you know that if I put a picture on facebook and twitter it’s no longer my picture? They own it.”

“Emphasis has changed from stranger danger in the park to online. I’m really impressed with how our education system has stepped up to face that challenge in support of parents.”

Innes, Software Engineer at Cocoon

“Lila, my oldest daughter, is just 3 years old. The best way to keep her safe is by putting my phone, laptop and gadgets (including Cocoon) out of her reach on a shelf! On a more serious note, she is allowed to play some games on our iPad but she’s not allowed on the internet. Although she possibly still doesn’t know what it is! Our devices all have passcodes, which we don’t show her. This means she can only use them when we let her. It will get harder as she gets older, but for now I feel pretty confident we’re keeping her safe.”

Parmjit, Test Analyst at Cocoon

“My daughter is still too young to go online, but I’m very close to my nephews and help look after them lots. They can only go online during the week for homework, and at weekends. All our devices have a pin so the parents have to unlock it for them to use it. Veer who’s eight years old is really creative and likes making videos with iMovie. He’s not allowed any social media accounts. He can watch videos on youtube but he can’t share anything at all.”

Resources to help your kids go online safely

The NSPCC online safety website offers very detailed guidance with an amazing collection of free resources. They cover everything from helping children to play games safely online, through to what to do if you think they’re watching adult content or sending inappropriate pictures.

Get Safe Online is a government-backed website crammed with information on keeping yourself and your family safe online. It has some great checklists for how to look after your children’s internet use, tailored for different age groups:

And of course, if we can help at all do let us know. We’re experienced in cybersecurity and lots of our team have young families. We know that this stuff can be hard! Reach out at [email protected], we’ll make sure all information is treated sensitively and will respond with the best advice we can.

Cocoon home security now in 65 countries worldwide

In 2014 we launched on Indiegogo to help people around the world feel safe with smarter home security. Today, Cocoon looks after homes in 65 countries around the world.

Cocoon is fixing the broken home security market

Most people don’t have home security. It’s astonishing, but 19 million UK households are unprotected and this hasn’t gone unnoticed by criminals. 650,000 UK homes being broken into in 2016 alone. But here’s the thing, homeowners aren’t to blame. Traditional home security is broken, it has been for decades and the clunky, expensive traditional home security systems have resulted in the majority of people not having home security.

Cocoon is changing home security for the better with uncomplicated, affordable product powered by a unique technology that takes the hard work out of securing your home. Over the last two years we’ve been testing and learning, gathering feedback and building something that people love, and we’re seeing the result of this in our customer reviews. This is something our team are proud of.

It’s one of the reasons why Cocoon is now in homes in 65 countries around the world.  Our growth is helping to make homes around the world safer. You could call this our mission, the reason Cocoon exists.  

We’re trying to make the world safer, starting with your home.

We first launched Cocoon on the crowdfunding platform Indiegogo because we believe that the best way to find an answer to a problem is to get lots of people thinking about it. More brains means more brainpower, and since we first shipped devices in 2016, our early backers have not only supported the growth of the Cocoon business with their money, tweets and time. They’ve also tried, tested and helped us improve new features we’ve released.

The backers from our Indiegogo campaign showed that the problem we’re solving isn’t just local. Cocoon is solving a global problem and our technology is proving valuable to people around the world.

It makes sense. According to the World Data Atlas of Knoema, in 2014 the Netherlands had one of the highest global burglary rates, with 1,507.8 cases per 100,000 population. The top 5 countries in their data set include Grenada, Denmark, Sweden, and Belgium. Burglary isn’t just close to home, it’s a worldwide problem. Which means that our mission, to make people feel safe, should be global too.

Our customers reflect this global outlook. Cocoon complete home security systems are now looking after homes in 65 countries around the world. People want to feel safe and, according to amazing reviews from our customers, Cocoon truly delivers that. We set out to make home security without the hassle, and in so doing, we’re making the world a safer place.

If you want to find out if Cocoon is available in your country why not visit our website where you can chat live with our brilliant customer support team.

What is Subsound®? The ‘sound’ part.

Cocoon’s secret sauce is Subsound®. It’s the technology making our home security incredibly simple and powerful. Because of our unique Subsound® technology, protecting your home has never been easier. With Cocoon you can feel safe knowing it will alert you when it matters.

Subsound® technology works by using three things:

  1. Sound
  2. A smartphone
  3. Machine Learning

Here we’ll explain how Subsound® uses sound to sense movement, and how that gives you multi-room protection from one Cocoon. Part 2 and 3 (coming soon) will explain how it uses your smartphone and machine learning.

How can you detect movement through sound

Cocoon’s Subsound® technology uses sound to detect movement around your home, not just in the room it sits in. This is possible because sound travels through your home, causing the air and walls and floors to vibrate, essentially turning your house into an amplifier!

Have you ever felt vibrations from music with a heavy bass line? How, even if you can’t hear the notes of the music, you can feel them? They travel through the air, the floor, the walls. You sometimes even feel them vibrate in your chest. That’s because those notes, and all sounds we hear, are actually vibrations moving the air that our ears can detect.

Moving through a space makes the air you’re pushing through vibrate. Walking across a room sends vibrations through the floorboards you’re stepping on. Singing the right note, loudly enough, can make a glass vibrate so violently that it cracks.

Humans can only hear within a narrow band of sound. Within that range of 20 to 20,000 Hz we hear birdsong, dogs barking, children giggling and engines roaring. But go much lower than this and we don’t hear it at all. (Although we may well feel it!) The sound that is caused by movement is too low for us humans to hear, but not Cocoon! Cocoon hears what we can’t.

Put simply, Cocoon hears the sound of movement.

How can Subsound® give multi-room protection?

All sound travels at the same speed in air, but high pitched sounds travel as lots of short waves while lower sounds are longer waves. The shorter waves are more easily absorbed by objects they hit because they’re too short to wiggle around them. Picture how hard a toddler would find it to climb over their toys – while an adult simply steps over them. The toddler is the high note, it can’t travel far because there are too many obstacles it can’t climb over. The adults are the low notes, they can easily travel around your home because, what may be a tough barrier for a toddler, is only a small step for them.

Cocoon doesn’t listen for the high pitched sounds, but instead, for those deep sounds that we can’t hear, known as infrasound. The adult, not the toddler. You may have experienced the movement of sound as the walls of a nightclub shake with the music, or as your body moves with the drumbeat when you’re dancing near a speaker. You are feeling the vibrations of sound. Just think, as the bassline hits your ears the sound waves are travelling through you. You really are part of the music.

Low frequencies resonate through your home more easily than high frequencies. As movement creates very low frequencies, the sound of movement travels through the rooms and floors of your home. Tuned to sense these low frequencies, Cocoon has the power to give you multi-room protection from just one device.

How does Cocoon use the sounds we can’t hear?

In the same way that you feel the bass hitting you, Cocoon has a clever microphone inside it that acts as a motion detector. It listens for subtle vibrations in the air caused by movement, building up a picture of those sounds. Like a fingerprint, this is unique for every home. If you’re away from home and it senses movement that isn’t normal, Cocoon sends an alert to your phone. (More on this, coming soon, in What is Subsound®? Part 3: Machine Learning)

This means Cocoon can detect movement before something crosses in front of its camera lens. Unlike traditional motion detectors that are so easily set off by spiders and moths, or modern smart home security cameras that rely on something passing in front of them, Cocoon senses motion through walls and floors. It is unique in offering multi-room protection from one device, and this is possible because sound travels through the air of your home.

Cocoon is not listening to your conversations

Because Cocoon is tuned to listen for low level vibrations caused by movement – called infrasound, it does not listen to your voice in the way that Amazon Alexa does! If you’re away from home and Cocoon senses something suspicious moving through the air you get an alert. That alert will not be triggered by someone chatting loudly outside your house, unless their voice is so deep that it falls into the infrasound range, so other humans can’t hear them! This is because the vibrations caused by the sound of human voices are not like those of an intruder in your home. And Cocoon is smart enough to know the difference.

Subsound® never listens to audible sounds, like voices and music and Cocoon only does so when it’s recording video. This happens when you “Watch Live” or when there’s an alert sent to your phone. This is great for having a smart home security system that respects your privacy.

The power of sound for better home security

The power of sound means you can have multi-room home security, from one Cocoon. It’s complete security without installing sensors on windows and doors, or intrusive cameras throughout your home. Cocoon set out to make home security without the hassle, that’s simple but also incredibly powerful. And to package that all into one beautiful gadget. The way we did that? Our unique Subsound® technology.

Cocoon home security now in B&Q

We’re excited to announce a retail partnership that sees B&Q join Selfridges in stocking Cocoon smart home security systems. From today Cocoon is available to buy in B&Q stores across the UK and online at www.DIY.com.

What makes Cocoon home security unique?

Cocoon is the all-in-one home security system that protects more of your home – a new, hassle-free way to secure your house or apartment. 

Cocoon’s unique Subsound® multi-room protection technology learns about your home to better protect it. Cocoon detects intruders by the sounds they make, letting you know if anything unusual happens while you’re away. 

Installation takes just a few seconds. Each Cocoon contains a HD camera, loud siren and Subsound® multi-room detection technology. There’s no need to install any door or window sensors and as it’s smart enough to know when you’re home or away. Cocoon is making home security simple.

Where can I buy Cocoon?

If you can’t wait for Cocoon to be delivered to your door you can now pop into one of the B&Q stores today and ask the sales advisor for ‘Cocoon home security’.

If you prefer, shop online from B&Q or buy Cocoon direct from us. Cocoon works without a monthly subscription and shipping is free within UK for all purchases made on our website www.cocoon.life.

Need more information on home security systems?

If you’re struggling to decide which home security system fits the needs of your home and family, or just want to find out a little more about Cocoon, read our free Home Security Guide.

Amazon Alexa Skill launching soon

Our mission at Cocoon is to make it simple for everyone to feel safe at home. Today we’re excited to announce a big step forward. The Cocoon Amazon Alexa Skill will be launching in the coming months.

Imagine the simplicity of controlling your home security with your voice. Home security used to mean an ugly keypad by your door, punching in a code as you came and went, with frequent false alarms and expensive installation ruining the look of your home. Since we first launched on Indiegogo in 2014, Cocoon’s unique multi-room protection technology has been making it easier for people around the world to secure their homes. Now, in 2017 there’s change in the air again. With Amazon Alexa and Cocoon, protecting your home is about to get even easier.

Amazon’s voice control technology is changing the way people interact with their home and many Cocoon customers have embraced this change. Since the launch of Amazon Echo last year our community has been requesting an integration with Alexa. It’s no secret that our team listen, taking on board feedback as we plan the future for Cocoon.

And now, we’re excited to announce that our team are hard at work, building a Cocoon Skill for Amazon Alexa. In the coming months, Echo, Dot or Amazon Alexa gadget users will be able to control Cocoon home security with their voice.

What will I be able to do with Cocoon and Alexa?

There are many ways that integrating with Alexa will make Cocoon an even more hassle-free way to protect your home. This may be saying “Alexa, arm my Cocoon” as you turn off your bedside light. Or it could be sounding the siren without having to unlock your phone. If you have any ideas for features you’d like to see, we’d love to hear them. Simply pop them in the comments below and we’ll take them on board in addition to our customer research.

We’re keeping the details under wraps until we announce the Cocoon Skill to the world, but one thing is certain. With our Amazon Alexa Skill, you will have even simpler home security from Cocoon.

Cocoon will connect securely with Alexa to protect your privacy and security

Every element of Cocoon is carefully designed to respect your privacy and protect your data. As a result, any actions that could impact your security will require a secure passcode, to prevent unauthorised users from overriding your home security settings.

When will I be able to use Cocoon with my Alexa

We’re working hard to deliver this update. For now, we’re aiming to launch Cocoon’s Amazon Alexa Skill in the coming months. Keep checking the blog for more information and to find out which features will be available first.

Burglar alarms, do they actually make homes safer?

Ringing burglar alarms have been the soundtrack to suburban life since the early 80s. We dive into the facts to set the record straight – do home security systems actually work, or not?

Ringing burglar alarms get ignored.

Sirens and alarms have become background noise in our modern lives, with 76% of Brits ignoring them. This is, in part, because they’re so often false. Smart home security systems like Cocoon solve this by giving control of the siren back to the homeowner. This means a burst of loud sound can be used to startle and disorientate an intruder while you catch evidence of their dastardly deed on camera.

Burglars are less likely to target a home with a security system

When burglars break into a home they are calculating the odds of getting caught. They bet that they can get into your home, grab your valuables and get out before the police arrive. Having a home security system dramatically reduces the odds of them getting away without spending time in a police cell. Hardly surprising they avoid the risk! Dr. Joseph B. Kuhns of the University of North Carolina spoke to over 400 burglars behind bars and found that over 83% of them try to determine if a house had a home security alarm before breaking in. Over 81% of those burglars admitted to stopping or selecting another target if the property had an alarm installed.

Cocoon home security window sticker in the window of a home

The evidence is clear, having a home security system deters the majority of burglars. But hold on, before you rush out to install an ugly alarm bell box on the front of your beautiful home you should know that most smart home security companies now ship highly visible window stickers designed to do exactly the same thing, without denting your curb appeal.

What to do about the ‘professional’ burglars?

If you regularly read the website of the Metropolitan Police, you’ll know that home security alarms are “undoubtedly the most effective deterrent against burglary” and that stickers or signage “are proven to be a powerful deterrent against burglary”. It’s worth noting at this point that the majority of thefts in the home take less than 10 minutes, whereas Police response times across the UK average 12 minutes, so prevention should be an important part of how you plan your home security.

‘Professional’ or ‘career’ criminals know this gap in response times and up to 13% will continue with a break-in regardless of there being home security present. Despite home security putting off the vast majority of intruders, a hardcore group still exists.

Our advice, use a smart home security system to record evidence of the intruder in the act. This can help Police identify the intruder, recover your goods and help with a criminal conviction.  

The right home security could make a big difference to your home.

  • The average burglary takes 10 minutes,  two minutes quicker the UK Police average response time of 12 minutes
  • More than 650,000 UK homes are victims of burglary each year
  • More than 70% of UK homes don’t have home security
  • Only 10% of reported break-ins in the UK result in a Police conviction

Which burglar alarm works for me?

So yes, an alarm really does work to deter intruders. If you’re part of the 70% who don’t have any home security alarm, now may be the time to consider getting one. 

We’d recommend that you take a look at our home security guide to find the right system for your home. The Memo agrees: “Cocoon is the best smart home security you can buy”. Regardless of which home security system you choose to protect your home, having one will make your home safer and reduce your chances of being a victim of burglary.