How to get random element from array with JavaScript

Imagine you have an array of numbers.

Goal is to get a random element of an array. There are several solutions posted on stackoverflow.com. But most of them are just too complicated, so I created my solution.

I have extend Array to add function random. What is does it uses random number and length of array to create a random index. Let’s use it in action.

That’s it. Happy coding.

Update:

Actually it’s very bad practice to extend prototype. Reasons are problems with browser compatibility. It’s better to create a function and use it. Or you can always use libs like underscore and it’s method sample.

Hekovnik & start:Cloud – why me, why now and why should I f*cking care?

I have already been member of one startup Osmosis, the charity for 21st century. We won the well established ImagineCup competition in Slovenia in 2012 and finished 7th at world finals. It was an amazing experience (I would like to thank again to all that helped us) and after 1 year I still have live memories of our hard work and determination. But the focus was totally elsewhere. TAM, SAM, SOM, WHAT? Is that something I can code with? No. Then I don’t care. We were focused on our product and not how others see it and how they could use it. So when we finally approached the market, we realized that what we imagined will never work. Our knowledge of charity market was insufficient and our product didn’t fit. At the same time we ran out of steam so we decided to stop Osmosis.

There is nothing worse then to fail in Slovenia. People look at you strange and they see you as failure. As someone who doesn’t know what they are doing and will never succeed. Because if you don’t succeed for the first time, you never will. Period. I don’t think the same. I was determined to start over and try something else. This is where Hekovnik comes in. Hekovnik is, I quote

Hekovnik Startup School provides targeted accelerator courses to hackers, entrepreneurs and academia to help them change the world.

In other words. Hekovnik is a startup school which will guide you from your idea to your first product and customers and even beyond that. It’s a place where like-minded people hangout and share ideas and knowledge. It’s A MUST place if you are just starting and you need help or just want to meet new people.

But let’s not talk too abstract. Let me describe how Hekovnik, their workshops and the guys working there helped us with MEDinar. I’m will divide it in 3 sections: working space, programs & workshops and team.

1. Working space

It’s located in the old Technology Park Ljubljana (Teslova 30, 1000 Ljubljana), 1 minute from Faculty of Computer and Information Science. It offers 3 big rooms: Tearoom (Čajnica), Black hole (Črna luknja) and Storming room (Viharnica).  For us most important is Tearoom. We used it as our office for few months for free. With it’s many big white boards it’s perfect for brainstorming and working. At the same time, it’s the gathering point, so you can meet many great people and get answers to your questions. We sure did. The bottom line is. Don’t sit behind computer at home. Come in Hekovnik because it offers amazing work-space. Plus they have a fast Wi-Fi.

2. Programs & Workshops

Hekovnik offers many programs. I cannot talk about all of them, but from rumors I heard, they are amazing. I can talk about start:Cloud program, about our experience and how it works. When you signup (as a student we paid 50€) you get a book The Startup Owner’s Manual: The Step-By-Step Guide for Building a Great Company. I highly recommend it. Program is divided in weekly workshops (every Tuesday and Thursday). On the workshops, first there are lectures and then you get to work. Hekovnik follows Lean Startup Methodology and during workshops they will demonstrate different tools and how to use them to test your hypothesis, find you customer segment, build your MVP and so on. At first, we didn’t know where to start. With talking to people and reading articles we tried to learn as much as possible about medical industry. With workshops and their help we found our customer segment and what problems they have. We made simple landing page to test our hypothesis, started building a web channel to reach them, offered them our solution and on the end calculated how much it’s gonna cost us to develop it, and for how much we will sell it. We made small, but steady progress each and every day.

The idea when all the teams are in the same room, each working on their product, on the end presenting what they did, commenting and receiving comments from other teams is just AWESOME. I really mean it. Because ideas don’t bounce off blackboards, they bounce off people. This is my favorite advice from Kristjan. Getting the comments from others and learning from mistakes helps you advance much faster. Workshops are intense and packed with knowledge and information. On the end they give you the right tools and frameworks, enough knowledge and experiences, and most important of all: they prepare you for the real world.

3. Team

There are many experts in Slovenia. There are also many so-called experts. But I think based on experience and professional approach, Hekovnik team knows what it’s doing.

Kristjan is the visionary and leader with wast knowledge in building startups. He hosts most of the workshops and talks with passion.  I always remember him walking in Tearoom like Kramer from Seinfeld. They are about the same height and both have crazy ideas. But he always asked how we are and what we are doing. After we told him and described our problem, he gave us some ideas and pointers. Keeping someone like him near is very important to stay focused.

Next team member is Tomaž. I think his job is to make sure everything runs smoothly. He helped us with our questions regarding start:Cloud. He also helped us with business questions and connected us with the right people. You just have to ask him nicely. When we went to annual Geekend, I remember him telling us Silicon Valley stories around camp fire. I think he could write a book about them.

Third member is Filip. He has a lot of experience in presentations. Even though he is a head smaller and probably weights half my kilos, I was terrified of him. When we worked on presentation, slogan, short description or anything else meant for general public and presented it to him, he always “destroyed” us. I remember him saying: I only hear blablabla.  He doesn’t mean anything bad, but he really helped us to better describe and express our product and always pushed us to make it better.

There are also other members, Matic and Matic. One responsible that all information reached us, and other that all the technical things worked. He also made sure we were not hungry during workshops. All I can say, Subway who? Hekovnik sandwiches FTW!

Few days ago we finished our start:Cloud program. I will like to thank everybody that helped us and supported us. From my family, girlfriend, friends, other teams and so on. For the end, let me try to answer those 3 questions in post title.

Why me? Where me means you; you who is reading this post. If you have entrepreneur spirit, then Hekovnik and their programs are perfect for you. But aware! If you are doing this only because you’re bored or neighbor kids are also doing this and you also want to be cool, then don’t. I have saw many teams come and go, because they got stuck at first obstacle. Having a startup means being tough. Hekovnik will make you tough.

Why now? Look around. We live in wonderful, but strange world. Because we people like to complicate things, the number of problems is rising each day. Problem of not having a job, deadly diseases lurking upon us, not able to have a stable WI-FI, etc. See your startup as problem solver. Best problem solver. Hekovnik will help you accomplish that.

Why should I f*cking care? Few years ago I had no idea about Hekovnik. I didn’t even bother to take 30 mins away from my busy schedule to visit it. I feel bad about it. But when I finally visited it, I was surprised in a very positive way. With great people, wonderful programs & workshops and fast WI-FI you will achieve your dreams. The last one is most important. Joking aside, what I wanted to say is. Give it a change, Hekovnik has many wonderful things to offer, you just have to be willing to work and believe in your idea.

How to remove related videos when using YT.Player for embedding YouTube videos

Today while working on MEDinar we had a problem with our presentation videos. We are using YouTube to host it. But when our customer finishes watching, they are suggested related videos. All of them were not related plus it’s not good for them to get distracted. The video is about how MEDinar is awesome and not some cat videos.

We are using YT.Player to embed video.

The reason is why we are using this way is to also track events when usre pauses and completes watching videos.

Many solutions on the internet suggested to specify additional parameter rel=0 to end of the URL. But how to do this with YT.Player? We needed to check official Google documentation https://developers.google.com/youtube/player_parameters#rel. By adding additional parameter in YT.Player initialization, we were able to remove related videos. The final code is.

Simple, right?