Adam Beres-Deak
software developer, JavaScript enthusiast

Recent blog posts


Generating sound effects with client side JavaScript

6th April 2014

A few years ago I came across a simple library with which we can easily generate 8-bit sound effects for JavaScript games and apps. This library is very handy for hackathons or weekend coding sessions.

read more

Boilerplate for static site generation

25th March 2014

As I already mentioned before, I really like simple things like static webpages. To speed things up, I created a boilerplate, which can be used by anybody to generate static websites.

read more

Automatically loading Grunt tasks with matchdep

11th March 2014

Have you ever installed a new GruntJS-plugin and then forgotten to load it as a task in the gruntfile.js? Matchdep is a handy tool, which can solve this issue.

read more

A simple usability trick for Google Maps

10th March 2014

Embedding Google Maps in a website is very easy with its JavaScript API. A simple trick can improve the usability of large maps when users scroll with the mouse wheel over them.

read more

Switching background color of an image with Gimp

2nd March 2014

As a web developers we sometimes come across some tasks which are not that strictly related to development, but rather to design. For me such a task was a few days ago, when I found a neat background pattern, but the color just didn't fit the site I was working on.

read more

Panning and scrolling background images using the canvas element

1st March 2014

I'm planning to create a simple 2D game in plain JavaScript. As the first step I would like to show, how to animate (pan or scroll) a background image using the canvas element. I am also going to show some basic setup code in order to have a loop where we can draw the frames.

read more

Finding a random document in MongoDB (with benchmarks)

15th February 2014

Finding a random element is not a trivial task when using MongoDB - especially when performance is crutial.

read more

Tracking clicks with Google Analytics

14th February 2014

Every website has some links or buttons, users are clicking on them. But do webmasters know which ones do users click most often? Are there maybe some, which are not clicked at all? Maybe you just built a shiny new navigation and you may ask "do users use it?". Clicktracking gives you the answer. When using Google Analytics the results are just shown on your dashboard.

read more

Comparison helper for Handlebars.js

13th February 2014

Personally, I was always missing some sort of comparison helper in Handlebars.js. I know, I know, it's sort of being against the philosophy of Handlebars - being logicless. But I still wanted to have it.

read more

One more reason to check for strict equality in JavaScript

12th February 2014

Some JavaScript fun without further explanation.

var a = [0, 1, 2, 3, 4, 5, 6];
console.log(a[3]); // 3
console.log(a[[3]]); // 3
console.log(a[[[3]]]); // 3
console.log(a[[[[3]]]]); // 3
console.log(a[[[[[3]]]]]); // 3
console.log(a["3"]); // 3

console.log(3 == [3]); // true
console.log(3 == [[3]]); // true

console.log(3 === [[3]]); // false

3 === Number([3].valueOf().toString()) // true
console.log([3].valueOf()) // [3]
console.log([3].valueOf().toString()) // 3
console.log(Number("3")) // 3
// therefore:
3 === Number([3].valueOf().toString()) // true

Resources - questions on Stack Overflow:


Finally always wins, unless you crash your computer meanwhile

11th February 2014

In JavaScript it is perfectly valid to have a return statement in a finally block. But this doesn't mean, you should really put it in there. Consider the following code:

function whatDoesThisReturn() {
    try {
        return false;
    } finally {
        return true;
    }
}

console.log(whatDoesThisReturn());

Basically the finally block is called after the try block, therefore it overrides the return value.

So this function returns true.


Strange error when installing npm package globally on Ubuntu

10th February 2014

Installing modules globally has never been a problem for me, neither on Windows nor on Ubuntu. At least until today, when I ran into a somewhat strange problem.

read more

Defining properties in JavaScript

9th February 2014

JavaScript has always supported basic properties on objects. But the time is approaching when IE8 support is not relevant anymore, so we can use a more modern approach (ES5) for defining properties. There is one difference though to other programming languages - like C# - that we always define properties on objects and not on types.

read more

Playing Mario in the browser

5th February 2014

Have you enjoyed playing Mario in the old days? Me too. If you want to play with it again, you just have to follow some simple steps and the game is ready to be played right in your browser. Let's try it.

read more

Building desktop apps with node.js and web technologies

4th February 2014

Native apps with web technologies are not a mobile-only thing anymore. The node-webkit project makes it possible to write standalone desktop apps with JavaScript, HTML5 and CSS3. The coolest thing about this is, that both server side (node.js) and client side (jQuery, AngularJS, etc.) JavaScript libraries can be used.

read more

How to redirect www to naked domain and vice versa with NGINX?

3rd February 2014

One thing almost every website needs is redirection. Many websites decide to serve their visitors both over www and non-www site, just in case the user types it into the browser. But for SEO it's bad, when you have the same site over two different domains. Here is, how to solve this issue with NGINX.

read more

How to register a bower package

3rd February 2014

A few weeks ago I posted about my PubSub module. Since then I registered it as a bower package. It was actually my first bower package. I am going to show you how easy it was.

read more

Demystifying AngularJS' dependency injection

2nd February 2014

Many people think that it is some kind of magic, how AngularJS resolves dependencies given as function arguments. But it isn't any magic. I'll show you, how they achieve it. This technique can be used everywhere, not just with AngularJS.

read more

Hosting static web pages and assets with Google Drive

2nd February 2014

Have you ever needed to quickly deploy a website somewhere? Maybe to show a client some demo content? Or to show a buddy your newest static web app? Here's the solution.

read more

Strong caching with NGINX

2nd February 2014

Strong caching is very important nowadays since it can reduce page load times for the users (and eventually it can also reduce network transfer costs for the publishers). Here we see a simple example how to do it with NGINX for static files like css, JavaScript and images.

read more

Error handling in JavaScript

31st January 2014

Have you ever wondered, what's the proper way of throwing JavaScript errors? And how to handle them? Here we'll see some examples and we'll define some custom error types.

read more

Adding tab support to textareas

30th January 2014

Have you ever wondered how is it possible to support tabs in a textarea? Normally when you press the tab key, the focus jumps to the next element. But with some JavaScript 'magic' it's possible to indent or unindent the text.

read more

Serve - a practical command line webserver

30th January 2014

A few weeks ago I found a very amazing tool - it's called "serve".

read more

Fat arrows for JavaScript

29th January 2014

I have to admit, I have completely overseen, that fat arrows ( => ) are coming to JavaScript. The syntax is much the same as in C#. This also means that LINQ is also on its way to the JavaScript world.

read more

Why I chose to statically generate my website

26th January 2014

I was long searching for the perfect blog engine for this site. More precisely I was planning to build a blog engine myself. I wanted to keep it simple, so I didn't want to use something overkill like Wordpress or Drupal. And I also like to code. But then I realised I don't really need to do this. Building a blog engine is boring, time consuming and so on. So I had to find a simpler alternative.

read more

A simple PubSub module in JavaScript

3rd January 2014

I have always been a fan of simple things, such as the PubSub pattern. A few weeks ago I discovered this pattern again, when I was looking for a way to separate some JavaScript modules which don't really have to know about each other but have to have some sort of communication.

read more

Wow, I started a blog

1st January 2014

So the new year has come and I decided to start a blog. I try to learn new things every day. Here I want to collect my thoughts and document what I have learned so far, so that I don't forget them and don't have to learn them again later.

read more