Blogs

Random number generation in JavaScript

Generating a random number in JavaScript is simple if you don't care about quality, more complicated if you do. When I say "in JavaScript" I mean both of the JavaScript runtimes - the browsers with their DOM/window, and Node.js without those things - and without all the modern browser APIs.

  1. The default, old-fashioned way to get a random number in JavaScript is by using Math.random(). However, the numbers produced from Math.random() are not secure for crypto applications as they are known to contain predictable patterns. The reason for this non-randomness isn't simply

  2. ...

MEAN vs LAMP stacks defined and compared

The long popular web development stack LAMP is slowly being chipped away from its dominant position by newer, trending technologies, letter by letter. MEAN is one total replacement which has been gaining ground lately.

What do those acronyms mean?

  • MEAN: MongoDB, ExpressJS, AngularJS, Node.js
  • LAMP: Linux, Apache, MySQL, PHP

MongoDB is a NoSQL database which won't support your existing applications because they would require some sort of relational database with SQL querying capability, probably including a whole lot of very custom...

Google Nexus 5X vs Nexus 5 original

I've had the Nexus 5X since it came out. And have still been using my Nexus 5 this whole time. At first I was unsure how I felt about the 5X which I had pre-ordered sight unseen. Now I feel I can give a fuller review and comparison.

  1. I really liked the size of the Nexus 5, the dimensions as well as the weight. The Nexus 5X is actually thinner than the 5, ever so slightly, but significantly taller and noticeably wider when you place the two phones back to back. The 5X also feels bigger in the hand and the difference in length makes it balance differently, sometimes feeling

  2. ...

Querying the database in Drupal 7 using db_select

Drupal, unlike plain old blog software, gives you the ability to create custom content object types with backing storage in the database as custom tables, doing all this without requiring any programming knowledge. When you create a new custom Content Type and add fields to it, in effect, you are creating a new database table for those fields.

Drupal also gives you ways to access and query the data without writing code. The most powerful form of this is Views, which every Drupal site should install as soon as starting. In the Views UI, you can select which fields (database columns...

Python-like List Comprehensions in JavaScript

Python has a neat syntactic feature where you can take a literal list constructor's bracket notation (e.g. [2, 4, 6, 8, 10]) but have code statements generate the list's contents. So instead of writing out the 5 even numbers in the example, one could write [(x+1)*2 for x in range(5)] which turns out to be more characters but you can imagine the savings if the series in the list was longer. Instead of range() we could have a literal list [0, 1, 2, 3, 4] or even a generator function, anything which is iterable.

How could we do this...

List Comprehensions in PHP (how to emulate Python)

Python has a sweet syntactic feature where you can take a literal list written out in bracket notation (e.g. [1, 3, 5, 7, 9]) but have inline expressions generate the list's contents. So instead of writing out the 5 consecutive odd numbers like above, in Python we can say [(x*2+1 for x in range(5)] which turns out to be more characters but you can imagine the savings if the series in the list was longer and not just odd. Instead of range() we could have a literal list [0, 1, 2, 3, 4] or even a generator function, anything which is...

Learn CSS by playing with resources at hand: Chrome Developer Tools

CSS is all around us. It's the invisible language that dictates how every web page, including the one you're reading now, looks - from color to size and shape, layouts and positions of each piece, all that we call "style". CSS stands for Cascading Style Sheets, a stylesheet simply being the text file containing the CSS definitions. You can take a look at a stylesheet now by right-clicking somewhere in a web page and selecting "Inspect" in Chrome or "Inspect element" in Safari. But you should use Chrome for this exercise.

...

Vim windows and window-splitting

A lifechanging feature of Vim for me was the window-splitting feature. In MacVim, you can even access a tiny slice of this through the Apple menu (File -> Split-Open). So you can view multiple files in other "windows" in the same Vim session. In fact, you can view the same file at different lines in different windows. And you can split windows both vertically (side by side) and horizontally (default). You can split already split...

The Difference between JavaScript and Java

Many non-programmers and young programmers are confused by the names Java and JavaScript. In fact, JavaScript was renamed to JavaScript as an afterthought and a co-marketing campaign together with Sun (the creator of Java). But there are succinct jokes for this naming coincidence: Java and JavaScript are the same like car and carpet, or ham and hamster.

First, the similarities. On a cursory look, some of the syntax of Java and JavaScript code look alike. This is because they're somewhat descended from C (putting them in the Algol family but they are both more similar to C than...

Isomorphic JavaScript myth

Isomorphic JavaScript is the idea of writing JavaScript that can run on the server just as well as in the browser, thus your otherwise frontend-only single page app (SPA), which only makes HTML appear after some post-load requests and execution, can also render the same HTML server-side (which is how things used to work) and give something to search engines to understand. AngularJS required hacks using PhantomJS to achieve this, by running a headless browser on your server.

In theory, a full stack web developer then only needs to know one language - JavaScript. In practice, knowing...