Monthly Archives: January 2016

The 10 Most Entertaining StackOverflow Questions Of All Time

By Danny Markov

most-entertaining-stack-overflow-questions3

Oh StackOverflow, what would we do without you! You save us countless hours of bug fixing with a single spot on answer. But there was a time when Stack Overflow wasn’t only for technical answers, and a few entertaining gems could slip through. We’ve collected a few of our most favorite ones for your enjoyment.

Our Top 10

Here are our favorite entertaining Stack Overflow questions. They aren’t sorted by up votes or anything, we are going to let you decide which ones you like best. If we’ve missed your favorite, add it to our comment section!


Although this question is from 2011 and no one uses the HTML bgcolor attribute anymore, it’s still funny that someone tried to color their div chucknorris. Also, in case you were wondering, here is a chart showing which color represents the names of popular celebrities.


10. What's your favorite programmer cartoon?

A huge compilation of funny images and comics. Be careful, you might waste an entire work day with this one. Credit goes to xkcd for providing us with nerdy entertainment.


5. What is the best comment in source code you have ever encountered?

Some people don’t comment their code at all causing confusion and bewilderment, others add meaningful and on point hints to aid their colleagues and their future selves. And then there are the people in this thread.


13. What is your best programmer joke?

Some of these are bad, some of these are good, some of these are so bad they are good. You know a good joke that is not in the list? Post it to our comment section!


3. Pair socks from a pile efficiently?

Ever feel like your amazing programming skills are useless outside of the computer world? This questions proves they aren’t! Apply your knowledge and fix a very real everyday laundry problem.


11. What's the difference between JavaScript and Java?

This question is another evidence that Stack Overflow has a sense of humor. Choose your favorite answer and the next time someone asks you this question seize the opportunity!


4. Is it possible to apply CSS to half of a character?

Have you ever needed to style only half of a character? Neither have we, but surprisingly it is possible! In an incredibly detailed answer, the stack overflow user Arbel shows different techniques for doing it. The code has been released as a jQuery plugin.


9. Check checkbox checked property

How many checkboxes could a checkbox check if a checkbox could check checkboxes? But no, seriously, this is a helpful question solving a very common problem.


1. Why does ++[[]][+[]]+[+[]] return the string 10?

JavaScript is a weird language that often times works in mysterious and unpredictable ways. The snipped in question is not Brainfuck but valid JavaScript. Thankfully Stack Overflow is full with people who now their JS, and they took the time to explain how this mind bending code works.


12. What was the strangest coding standard rule that you were forced to follow?

Have you ever thought about how much you hate your workplace? Well, at lest it doesn’t impose nonsensical coding standard rules like the ones in this thread.

Bonus

7. Why does this code using random strings print hello world?

This question was asked in the java section, but the topic applies to all programming languages – random isn’t really random, it’s pseudorandom. Feel free to use this information to confuse other coders.

Source:: Tutorialzine.com

The Languages And Frameworks You Should Learn In 2016

By Martin Angelov

the-languages-and-frameworks-you-should-learn-in-2016

A lot happened in the software development world in 2015. There were new releases of popular programming languages, new versions of important frameworks and new tools. You will find a short list of the new releases that we think are the most important below, together with suggestions for the things we believe would be a great investment of your time to learn in 2016.

The Trends

Shift from the backend to the frontend

In the last few years, there has been a trend towards shifting the business logic of web apps from the backend to the frontend, with the backend being delegated to a simple API. This makes the choice of a frontend framework that much more important.

Quick browsers releases

Another significant advancement for the web as a platform in 2015 was the release of the Edge web browser. This is the successor of Internet Explorer which has an updated interface and faster performance. What sets it apart from IE is that it adopts the same quick release schedule that Firefox and Chrome follow. This is going to move the JavaScript community forward as updates to JavaScript and web standards will be available in weeks rather than years everywhere.

The death of Flash

It has finally happened! YouTube switched to HTML5 this year, ditching their legacy Flash player. Firefox started blocking the Flash plugin by default. Even the powerful Adobe Flash creation suite was renamed to Adobe Animate and defaults to HTML5 exports. This leaves the doors wide open for the web platform to shine.


Languages and Platforms

Python 3.5 was released this year with a lot of new features like Asyncio, which gives you a node.js-like event loop, and type hints. As a whole Python 3 is finally gaining popularity and we heavily recommend it over the older Python 2. Nearly all libraries are available for Python 3 and now is a good time to upgrade your legacy code base.

PHP 7 is a major new version that fixes a number of issues and brings new features and speed (see an overview here). PHP 7 is around twice as fast as PHP 5.6, which will have a big impact on large codebases and CMS systems like WordPress and Drupal. We recommend PHP The Right Way, which was updated for version 7. And if you need even more speed and don’t mind switching to an alternative runtime, check out HHVM, which Facebook uses and develops to run their website.

JavaScript also saw updates in the form of the ES2015 standard (used to be known as ES6). It brings us exciting new features and additions to the language. Thanks to most browsers adopting quick release schedules, support for ES2015 is great, and there is Babel.js which will help you bring your code to older browsers.

Node.js saw a lot of changes this year, with the community splitting between Node.js and io.js, and then joining forces again. As a result we now have an actively maintained project with lots of contributors and two versions of Node – a solid LTS (long term support) release, which gives stability for long lived projects and large companies, and a non-lts version which is quick to add new JavaScript features.

Swift 2 was released earlier this year. This is Apple’s vision for a modern programming language that eases the development of apps on iOS and OS X. As of a few weeks ago, Swift is open source and has already been ported on Linux. This means that it is now possible to build backends and server side software with it.

Go 1.5 was released a few months ago, and brough major architectural changes. In 2015 it has grown in popularity and has been adopted in leading startups and open source projects. The language itself is relatively simple, so learning it will be a weekend well spent.

TypeScript is a staticly typed language which compiles to JavaScript. It is developed by Microsoft and has perfect integration with Visual Studio and the open source Visual Studio Code editors. It will soon be quite popular, as the upcoming Angular 2 is written in it. Static typing benefits large teams and large code bases the most, so if one of these applies to you, or you are just curious, you should give TypeScript a try.

For the adventurous, you can try out one the functional languages like Haskell or Clojure. There are also interesting high performance languages like Rust and Elixir. If you are looking for a programming job, career languages like Java (which has some nice features in its 8th version) and C# (which thanks to Visual Studio Code and .net core can be run and developed cross platform) would be a good investment of your time in 2016.

Learn one or more of these: Python 3, Go, PHP 7, ES2015, Node.js, Swift, TypeScript


javascript

JavaScript Frameworks

JavaScript is a very important piece of the web development stack, so we are giving it dedicated section in our overview. There were two new standards this year – Service Workers and Web Assembly, which shape how web apps are developed from now on. There were also a number of new framework releases which we think you should keep a close eye on in 2016:

Angular.js has become the go-to JavaScript framework for enterprises and large companies. It has been known for some time that the next major version of the framework was coming, and earlier this year Angular 2 was released as a development preview. It is a total rewrite of Angular 1 and according to us is a great improvement over it. It is almost guaranteed to become the enterprise framework of choice once it is released, and Angular 2 experience will be a great addition to your CV. Our advice is to wait a few months for the final version to ship before picking it up, but you can read through their quick start guide right now.

React continued its ascend throughout 2015 and has seen new releases throughout the year and new projects adopting it as their library of choice. It shipped new development tools a few months ago. Facebook also released React Native which is a framework for building mobile apps for Android and iOS, which combines a native frontend with React running in a background JavaScript thread. See a quick tutorial about React that we published this year.

Polymer 1.0 was released in May. This marks the first stable and production ready version. Polymer is based around Web Components, which is a standard for packaging HTML, JS and CSS into isolated widgets that can be imported into your web apps. Web Components are only supported in Chrome and Opera at the moment, but Polymer makes them available everywhere.

Ember.js also saw a new release. Ember 2 brings modularity and removes deprecated features and optimizes the codebase. Ember follows semantic versioning and maintainers of the framework are careful to make updating as easy as possible. If you need a framework with stability and easy migration to new versions, you can give Ember a try.

Vue.js is a new library that offers reactive components for building user interfaces. It supports data binding, modular components and composition. It is similar to React, but doesn’t use a virtual DOM and works only in the browser. In the short time that it has existed, Vue has gathered a very active community around it and is establishing itself as a pragmatic tool for building web interfaces.

Learn one of these: Angular 2, React, Ember.js, Vue.js, Polymer, Web Components, Service Workers


frontend

Frontend

Bootstrap has become even more popular in the last year and is turning into a web development standard. Version 4 will come out in the next few months, which brings flexbox support and integrates SASS. It promises a smooth transition from V3 (unlike what we saw with v2 to v3 a couple of years ago), so you can feel confident that what you learn about Bootstrap 3 will be applicable to version 4.

Foundation is another frontend framework that is an alternative to Bootstrap. Version 6 was released earlier this year, which focuses on modularity so that you can include only the pieces that you need for a faster load time.

MDL is an official framework by Google for building material design web apps. It was released earlier this year and has a similar goal to Google’s other framework – Polymer, but is much easier to get started with. We have a wonderful overview which compares MDL with Bootstrap.

CSS preprocessors continue improving. Less and SASS are the two most popular at the moment, with mostly comparable feature sets. However, the news that Bootstrap 4 is migrating over to SASS gives it a slight edge over Less as the preprocessor to learn in 2016. Also, there is the newer PostCSS tool that is gaining mind share, but we recommend it only for devs which already have experience with preprocessors.

Learn one or more of these: Bootstrap, MDL, Foundation, SASS, LESS, PostCSS


backend

Backend

There has been a clear trend in web development over the last few years. More and more of our apps’ logic is shifted to the frontend, and the backend is only treated as an API. However there is still room for classic HTML-generating web apps, which is why we think that learning a classic full stack framework is still important.

Depending on which language you prefer, you have plenty of choice. For PHP you have Symfony, Zend, Laravel (and Lumen, its new lightweight alternative for APIs), Slim and more. For Python – Django and Flask. For Ruby – Rails and Sinatra. For Java – Play and Spark. For Node.js you have Express, Hapi and Sails.js, and for Go you have Revel.

AWS Lambda was released last year, but the concept is now established and ready for production. This is a service which eliminates backend servers entirely and is infinitely scaleable. You can define functions which are called on specific conditions or when routes of your API are visited. This means that you can have an entirely serverless backend which you don’t have to think about.

Another trend are static site generators like Jekyll and Octopress (see a complete list here). These tools take a number of source files like text and images, and create an entire website with prerendered HTML pages. Developers, who would normally set up a WordPress blog with a database and an admin area, now prefer to generate their HTML pages ahead of time and only upload a static version of their site. This has the benefits of increased security (no backend to hack and database to manage) and fantastic performance. Combined with CDNs like MaxCDN and CloudFlare clients can request a page of the website and receive it from a server nearby, greatly reducing latency.

Learn one of these: A full stack backend framework, AWS Lambda, A static site generator


cms

CMS

We’ve included two of the most popular CMS systems here. Both are written in PHP and are easy to deploy and get started with. They enjoy big speedups from the new PHP 7 release.

In recent years WordPress has become much more than a simple blogging platform. It is a fully fledged CMS/Framework with plugins that make it possible to run any kind of website. High quality WordPress themes are a big market, and lots of freelancers make their living by developing for WordPress. With projects like WP-API you can use WordPress as a REST API backend.

Drupal 8 was released this year. It is a full rewrite that focuses on modern development practices. It makes use of Symfony 2 components and Composer packages and the Twig templating engine. Millions of websites run Drupal, and it is a good choice for content heavy portals.


databases

Databases

This year the web development community lost some of its enthusiasm for NoSQL databases, and instead returned to relational databases like Postgres and MySQL. Notable exceptions to this trend are RethinkDB and Redis which gained mind share, and we recommend that you try them out in 2016.

Postgres is a popular relational database engine which sees a lot of development activity and is constantly improved with new features. Version 9.5 is expected soon. It will bring better support for JSONB columns for holding schema-less data (replacing any need for a separate NoSQL database) and the long awaited upsert operation, which simplifies INSERT-or-UPDATE queries. You might want to look into it, once it is released in 2016.

MySQL is the the most popular open source database system and is installed on most hosting providers out there. With version 5.7, MySQL also offers JSON columns for storing schema-less data. If you are just starting out with backend development, you will most likely be looking at connecting to a MySQL database that your hosting provider has set up for you. It is probably going to be an older version, so you might not be able to try out the JSON type. MySQL is included in popular packages like XAMPP and MAMP so it is easy to get started with.

Learn one of these: Redis, RethinkDB, MySQL/MariaDB, PostgreSQL


mobile-apps

Mobile Apps

Mobile platforms are always evolving and smartphone hardware now rivals low end laptops in performance. This is great news for hybrid mobile frameworks, as mobile apps built using web technologies can now offer a smooth, native-like experience.

We have a nice overview of hybrid mobile frameworks that you might want to check out. You have the popular Ionic framework and Meteor which recently had its 1.0 version and is also suitable for mobile app development. Facebook launched React Native, which runs React components in a background JavaScript thread and updates a native UI, allowing you to have mostly identical code for both iOS and Android.

Learn one of these: Ionic, React Native, Meteor


editors-and-tools

Editors and Tools

The Atom editor reached version 1.0 this year. It is a free and powerful code editor that is built using web technologies. It has lots of packages available for it and a large community. It offers smart autocompletion and integrates with plugins for code refactoring and linting. Not to mention that it has lots of beautiful themes to chose from, and you can customize it by writing CoffeeScript and CSS. Facebook has used this extensibility and launched the Nuclide editor.

Microsoft surprised everybody when they released their Visual Studio Code editor earlier this year. It is a lightweight IDE that supports a number of languages and runs on Windows, Linux and OS X. It offers the powerful IntelliSense code inspection feature and integrates a debugger for ASP.Net and Node.js.

NPM, the package manager of Node.js, has exploded in popularity and has become the packaging standard for frontend and node developers. This is the easiest way to manage the JavaScript dependencies for your project and getting started with it is easy.

Even for a solo developer Git is a necessity these days. Its serverless model allows you to turn any folder into a version controlled repository, which you can then push to Bitbucket or Github, and sync across computers. If you haven’t used Git yet, we recommend that you add it to your list of things to learn in 2016.

Learn one of these: Atom, Visual Studio Code, NPM, Git


making-things

Making Things

The Raspberry PI foundation delivered an early Christmas present this year, with the release of the Raspberry PI Zero – a $5 computer that is fast and power efficient. It runs Linux, so you can turn it into a server, a home automation device, a smart mirror, or to embed it into a dumb appliance and create that internet enabled coffee brewer you’ve been dreaming of. 2016 is the year to get a Raspberry.


Onto An Awesome 2016!

We’ve had a great 2015 and by the looks of it 2016 is going to be even more awesome. What’s on your list of things to learn in 2016?

Source:: Tutorialzine.com

Creating Your First Desktop App With HTML, JS and Electron

By Danny Markov

creating-your-first-desktop-app-with-electron

Web applications become more and more powerful every year, but there is still room for desktop apps with full access to the hardware of your computer. Today you can create desktop apps using the already familiar HTML, JS and Node.js, then package it into an executable file and distribute it accordingly across Windows, OS X and Linux.

There are two popular open source projects which make this possible. These are NW.js, which we covered a few months ago, and the newer Electron, which we are going to use today (see the differences between them here). We are going to rewrite the older NW.js version to use Electron, so you can easily compare them.

Getting Started With Electron

Apps built with Electron are just web sites which are opened in an embedded Chromium web browser. In addition to the regular HTML5 APIs, these websites can use the full suite of Node.js modules and special Electron modules which give access to the operating system.

For the sake of this tutorial, we will be building a simple app that fetches the most recent Tutorialzine articles via our RSS feed and displays them in a cool looking carousel. All the files needed for the app to work are available in an archive which you can get from the Download button near the top of the page.

Extract its contents in a directory of your choice. Judging by the file structure, you would never guess this is a desktop application and not just a simple website.

Directory Structure

We will take a closer look at the more interesting files and how it all works in a minute, but first, let’s take the app for a spin.

Running the App

Since an Electron app is just a fancy Node.js app, you will need to have npm installed. You can learn how to do it here, it’s pretty straightforward.

Once you’ve got that covered, open a new cmd or terminal in the directory with the extracted files and run this command:

npm install

This will create a node_modules folder containing all the Node.js dependencies required for the app to work. Everything should be good to go now, in the same terminal as before enter the following:

npm start

The app should open up in it’s own window. Notice it has a top menu bar and everything!

Electron App In Action

Electron App In Action

You’ve probably noticed that starting the app isn’t too user friendly. However, this is just the developer’s way of running an Electron app. When packaged for the public, the it will be installed like a normal program and opened like one, just by double clicking on its icon.

How it’s made

Here, we will talk about the most essential files in any electron app. Let’s start with package.json, which holds various information about the project, such as the version, npm dependencies and other important settings.

package.json

{
  "name": "electron-app",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "dependencies": {
    "pretty-bytes": "^2.0.1"
  },
  "devDependencies": {
    "electron-prebuilt": "^0.35.2"
  },
  "scripts": {
    "start": "electron main.js"
  },
  "author": "",
  "license": "ISC"
}

If you’ve worked with node.js before, you already know how this works. The most significant thing to note here is the scripts property, where we’ve defined the npm start command, allowing us to run the app like we did earlier. When we call it, we ask electron to run the main.js file. This JS file contains a short script that opens the app window, and defines some options and event handlers.

main.js

var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window');  // Module to create native browser window.

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform != 'darwin') {
        app.quit();
    }
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
    // Create the browser window.
    mainWindow = new BrowserWindow({width: 900, height: 600});

    // and load the index.html of the app.
    mainWindow.loadURL('file://' + __dirname + '/index.html');

    // Emitted when the window is closed.
    mainWindow.on('closed', function() {
        // Dereference the window object, usually you would store windows
        // in an array if your app supports multi windows, this is the time
        // when you should delete the corresponding element.
        mainWindow = null;
    });
});

Take a look at what we do in the ‘ready’ method. First we define a browser window and set it’s initial size. Then, we load the index.html file in it, which works similarly to opening a HTML file in your browser.

As you will see, the HTML file itself is nothing special – a container for the carousel and a paragraph were CPU and RAM stats are displayed.

index.html

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Tutorialzine Electron Experiment</title>

    <link rel="stylesheet" href="./css/jquery.flipster.min.css">
    <link rel="stylesheet" href="./css/styles.css">

</head>
<body>

<div class="flipster">
    <ul>
    </ul>
</div>

<p class="stats"></p>

<!-->In Electron, this is the correct way to include jQuery<-->
<script>window.$ = window.jQuery = require('./js/jquery.min.js');</script>
<script src="./js/jquery.flipster.min.js"></script>
<script src="./js/script.js"></script>
</body>
</html>

The HTML also links to the needed stylesheets, JS libraries and scripts. Notice that jQuery is included in a weird way. See this issue for more information about that.

Finally, here is the actual JavaScript for the app. In it we access Tutorialzine’s RSS feed, fetch recent articles and display them. If we try to do this in a browser environment, it won’t work, because the RSS feed is located on a different domain and fetching from it is forbidden. In Electron, however, this limitation doesn’t apply and we can simply get the needed information with an AJAX request.

$(function(){

    // Display some statistics about this computer, using node's os module.

    var os = require('os');
    var prettyBytes = require('pretty-bytes');

    $('.stats').append('Number of cpu cores: <span>' + os.cpus().length + '</span>');
    $('.stats').append('Free memory: <span>' + prettyBytes(os.freemem())+ '</span>');

    // Electron's UI library. We will need it for later.

    var shell = require('shell');


    // Fetch the recent posts on Tutorialzine.

    var ul = $('.flipster ul');

    // The same-origin security policy doesn't apply to electron, so we can
    // send ajax request to other sites. Let's fetch Tutorialzine's rss feed:

    $.get('http://feeds.feedburner.com/Tutorialzine', function(response){

        var rss = $(response);

        // Find all articles in the RSS feed:

        rss.find('item').each(function(){
            var item = $(this);

            var content = item.find('encoded').html().split('</a></div>')[0]+'</a></div>';
            var urlRegex = /(http|ftp|https)://[w-_]+(.[w-_]+)+([w-.,@?^=%&amp;:/~+#]*[w-@?^=%&amp;/~+#])?/g;

            // Fetch the first image of the article.
            var imageSource = content.match(urlRegex)[1];


            // Create a li item for every article, and append it to the unordered list.

            var li = $('<li><img /><a target="_blank"></a></li>');

            li.find('a')
                .attr('href', item.find('link').text())
                .text(item.find("title").text());

            li.find('img').attr('src', imageSource);

            li.appendTo(ul);

        });

        // Initialize the flipster plugin.

        $('.flipster').flipster({
            style: 'carousel'
        });

        // When an article is clicked, open the page in the system default browser.
        // Otherwise it would open it in the electron window which is not what we want.

        $('.flipster').on('click', 'a', function (e) {

            e.preventDefault();

            // Open URL with default browser.

            shell.openExternal(e.target.href);

        });

    });

});

A cool thing about the above code, is that in one file we simultaneously use:

  • JavaScript libraries – jQuery and jQuery Flipster to make the carousel.
  • Electron native modules – Shell which provides APIs for desktop related tasks, in our case opening a URL in the default web browser.
  • Node.js modules – OS for accessing system memory information, Pretty Bytes for formatting.

And with this our app is ready!

Packaging and Distribution

There is one other important thing to do to make your app ready for end users. You need to package it into an executable that can be started with a double click on users’ machines. Since Electron apps can work on multiple operating systems and every OS is different, there need to be separate distributions for Windows, for OS X and for Linux. Tools such as this npm module are a good place to start – Electron Packager.

Take into consideration that the packaging takes all your assets, all the required node.js modules, plus a minified WebKit browser and places them together in a single executable file. All these things sum up and the final result is an app that is roughly 50mb in size. This is quite a lot and isn’t practical for a simple app like our example here, but this becomes irrelevant when we work with big, complex applications.

Conclusion

The only major difference with NW.js that you will see in our example is that NW.js opens an HTML page directly, whereas Electron starts up by executing a JavaScript file and you create an application window through code. Electron’s way gives you more control, as you can easily build multi-window applications and organize the communication between them.

Overall Electron is an exciting way to build desktop web applications using web technologies. Here is what you should read next:

Source:: Tutorialzine.com

Freebie: 12 Ready To Use Templates For List Pages

By Danny Markov

12-ready-to-use-templates

Here we have for you a collection of 12 lovely free templates for displaying various item lists! We’ve created them without relying on any frameworks or libraries, only vanilla HTML and CSS have been used. Because of this, they are very easy to implement and can pair well with all kinds of websites, apps and blogs.

The Templates

The templates are separated in 4 different groups. Here’s what we have:

  • 3 Product lists, perfect for online shops and catalogs.
  • 4 Article lists for presenting blog posts with thumbnails, titles and descriptions.
  • 2 Image lists for displaying galleries and photo albums.
  • 3 User profile lists showing quick information about a person and their avatar.

You can download the entire pack from the Download button near the top of the page.

Using the Templates

After you’ve downloaded them, placing any of the templates in you projects is pretty straightforward. Just follow these easy steps:

  1. Choose the template you like best.
  2. Open it’s example, copy the HTML inside the tag and paste it wherever you want the list in your page.
  3. Get the corresponding CSS file for this particular template and link it to your project (the stylesheets are located in /assets/css). Our CSS is self contained and won’t interfere with the rest of your styles.
  4. Replace our placeholder content with your text and images.
  5. Done!

User Profiles Small

Free for Commercial Use

All 12 templates are completely free of charge and don’t require any form of attribution. You have all rights to customize them and use them however you want, in both personal and commercial projects (our license page). Enjoy!

Source:: Tutorialzine.com

15 Interesting JavaScript and CSS Libraries for January 2016

By Dimo Raichev

interesting-resources-january

Now is a fantastic time to be a web developer. The community creates lots of new and exciting JavaScript and CSS libraries, so there is always something new to learn and see. Here are some of our favorites, which we think that you should check out in January 2016.


Datedropper

Datedropper is a jQuery plugin which helps you create an interesting way for presenting date fields. It supports 16 languages and all date formats. It has a lot of useful options and eye-catching animation. It is very easy to use – just embed the JavaScript file in your page and initialize the date field with the dateDropper() method.


Drop.js

Drop.js

Drop.js is a useful JavaScript and CSS library for creating dropdowns and floating displays. It’s animated smoothly with CSS and you can embed whatever HTML code you wish in the dropdown.


Vorlon.js

Vorlon.js

Vorlon.js is a cross platform tool, developed by Microsoft, that helps you remotely debug and test your JavaScript. It gives you the ability to remotely connect up to 50 devices and easily test your code on all of them simultaneously. There is also a desktop application, built using Electron, which helps you run your tests from an easy to use graphical app.


Hammer

Hammer

Hammer is an open-source library that recognizes gestures made by touch, mouse and pointer events. It supports complex multi-touch gestures like rotate, pinch and swipe, which makes it possible to develop web apps that can rival the experience that native applications provide.


Vivus

Vivus

Vivus is a JavaScript class that helps you bring your SVGs to life, giving them the appearance of being drawn. It is standalone and has no dependencies. It supports a lot of animation types and timing options, as well as option to script your own animations with JavaScript.


Popmotion

Popmotion

Popmotion is JavaScript motion engine, with physics and input tracking. It gives you a great deal of control over every aspect of your animations. You can define custom easing transitions, pause, reverse and seek animations and more. It supports CSS and SVG animations which work smoothly on any browser.


Animateplus

Animateplus

Animateplus is a CSS and SVG animation library. It works very well on mobile devices, and is perfect for smooth landing pages. You can configure the duration, easing and delay before the animation starts.


Dinamics.js

Dinamics.js

Dinamics.js is JavaScript library that helps you create physics-based animations. It has a lot of useful options like friction, bounciness and elasticity. You can animate all your menus, load elements and buttons. Their website has lots of pretty examples which you can start with.


Gradient Animator

Gradient Animator

Gradient animator is an online tool that helps you generate animated CSS gradients. After you choose options like colors speed and angles, just copy the code that the website gives you and paste it into your stylesheet.


Notie.js

Notie.js

Notie Is clean and simple notification library for JavaScript. It supports many types of notifications including alternatives for the confirm and prompt browser dialogs. The library gives you an easy way to override the way noties look and feel, so you can customize everything to match your design.


OhSnap!.js

OhSnap!.js

OhSnap! Is a simple notification library for jQuery/Zepto. It is designed to work well in both desktop and mobile browsers. It is very easy to integrate into an existing website. To customize it you only need to edit a single .css file.


PurifyCSS

PurifyCSS

Purify is a utility which cleans up your CSS. It has the ability to detect the dynamically-loaded CSS selectors in your JavaScript. It works with single-page as well as multi-page apps.


Wheelnav.js

Wheelnav.js

Wheelnav is JavaScript library, built on SVG, for tab navigation and wheel menus. It has the option to create collapsible pie menus with optional sub menus. Despite that the default appearance is a wheel you can modify your menu easily.


spaceBase

spaceBase

SpaceBase is a Sass-based framework that combines the best responsive practices into ready-to-use boilerplate project. It contains must-haves like a mobile-friendly grid, common ui components like buttons and lists, help classes and mixins and more.


Egg.js

Egg.js

Egg.js is a simple library that helps you add a web easter egg by watching the user’s key strokes. You can add a hook that will run after any egg code is triggered. You can use this to send out a tweet that someone found your easter egg.

Source:: Tutorialzine.com

15 Interesting JavaScript and CSS Libraries for January 2016

By Dimo Raichev

interesting-resources-january

Now is a fantastic time to be a web developer. The community creates lots of new and exciting JavaScript and CSS libraries, so there is always something new to learn and see. Here are some of our favorites, which we think that you should check out in January 2016.


Datedropper

Datedropper is a jQuery plugin which helps you create an interesting way for presenting date fields. It supports 16 languages and all date formats. It has a lot of useful options and eye-catching animation. It is very easy to use – just embed the JavaScript file in your page and initialize the date field with the dateDropper() method.


Drop.js

Drop.js

Drop.js is a useful JavaScript and CSS library for creating dropdowns and floating displays. It’s animated smoothly with CSS and you can embed whatever HTML code you wish in the dropdown.


Vorlon.js

Vorlon.js

Vorlon.js is a cross platform tool, developed by Microsoft, that helps you remotely debug and test your JavaScript. It gives you the ability to remotely connect up to 50 devices and easily test your code on all of them simultaneously. There is also a desktop application, built using Electron, which helps you run your tests from an easy to use graphical app.


Hammer

Hammer

Hammer is an open-source library that recognizes gestures made by touch, mouse and pointer events. It supports complex multi-touch gestures like rotate, pinch and swipe, which makes it possible to develop web apps that can rival the experience that native applications provide.


Vivus

Vivus

Vivus is a JavaScript class that helps you bring your SVGs to life, giving them the appearance of being drawn. It is standalone and has no dependencies. It supports a lot of animation types and timing options, as well as option to script your own animations with JavaScript.


Popmotion

Popmotion

Popmotion is JavaScript motion engine, with physics and input tracking. It gives you a great deal of control over every aspect of your animations. You can define custom easing transitions, pause, reverse and seek animations and more. It supports CSS and SVG animations which work smoothly on any browser.


Animateplus

Animateplus

Animateplus is a CSS and SVG animation library. It works very well on mobile devices, and is perfect for smooth landing pages. You can configure the duration, easing and delay before the animation starts.


Dinamics.js

Dinamics.js

Dinamics.js is JavaScript library that helps you create physics-based animations. It has a lot of useful options like friction, bounciness and elasticity. You can animate all your menus, load elements and buttons. Their website has lots of pretty examples which you can start with.


Gradient Animator

Gradient Animator

Gradient animator is an online tool that helps you generate animated CSS gradients. After you choose options like colors speed and angles, just copy the code that the website gives you and paste it into your stylesheet.


Notie.js

Notie.js

Notie Is clean and simple notification library for JavaScript. It supports many types of notifications including alternatives for the confirm and prompt browser dialogs. The library gives you an easy way to override the way noties look and feel, so you can customize everything to match your design.


OhSnap!.js

OhSnap!.js

OhSnap! Is a simple notification library for jQuery/Zepto. It is designed to work well in both desktop and mobile browsers. It is very easy to integrate into an existing website. To customize it you only need to edit a single .css file.


PurifyCSS

PurifyCSS

Purify is a utility which cleans up your CSS. It has the ability to detect the dynamically-loaded CSS selectors in your JavaScript. It works with single-page as well as multi-page apps.


Wheelnav.js

Wheelnav.js

Wheelnav is JavaScript library, built on SVG, for tab navigation and wheel menus. It has the option to create collapsible pie menus with optional sub menus. Despite that the default appearance is a wheel you can modify your menu easily.


spaceBase

spaceBase

SpaceBase is a Sass-based framework that combines the best responsive practices into ready-to-use boilerplate project. It contains must-haves like a mobile-friendly grid, common ui components like buttons and lists, help classes and mixins and more.


Egg.js

Egg.js

Egg.js is a simple library that helps you add a web easter egg by watching the user’s key strokes. You can add a hook that will run after any egg code is triggered. You can use this to send out a tweet that someone found your easter egg.

Source:: Tutorialzine.com

classes-inner-names

By Axel Rauschmayer

This blog post explains that classes have lexical inner names, just like named function expressions.

The inner names of function expressions

You may know that function expressions have lexical inner names:

    const fac = function me(n) {
        if (n > 0) {
            // Use inner name `me` to
            // refer to the function
            return n * me(n-1);
        } else {
            return 1;
        }
    };
    console.log(fac(3)); // 6

The name me of the named function expression becomes a lexically bound variable that is unaffected by which variable currently holds the function.

The inner names of classes

Interestingly, ES6 classes also have lexical inner names that you can use in methods (constructor methods and regular methods):

    class C {
        constructor() {
            // Use inner name C to refer to class
            console.log(`constructor: ${C.prop}`);
        }
        logProp() {
            // Use inner name C to refer to class
            console.log(`logProp: ${C.prop}`);
        }
    }
    C.prop = 'Hi!';
    
    const D = C;
    C = null;
    
    // C is not a class, anymore:
    new C().logProp();
        // TypeError: C is not a function
    
    // But inside the class, the identifier C
    // still works
    new D().logProp();
        // constructor: Hi!
        // logProp: Hi!

(In the ES6 spec the inner name is set up by the dynamic semantics of ClassDefinitionEvaluation.)

Acknowledgement: Thanks to Michael Ficarra for pointing out that classes have inner names.

Source:: 2ality

Running locally installed npm executables

By Axel Rauschmayer

One nice npm feature is that you can install packages with executables locally. This blog post explains how to run locally installed executables.

Running executables from a nearby node_modules

(An aside, on the topic of packages versus modules: npm packages may or may not contain Node.js modules.)

If you require a module, Node.js looks for it by going through all node_modules/ directories in ancestor directories (./node_modules/, ../node_modules/, ../../node_modules/, etc.). The first appropriate module that is found is used.

Whenever you are somewhere in the file system, npm root tells you where it would install packages if you used npm install. That directory node_modules/ may or may not exist, already; in the following example, directory /tmp/ is empty.

    $ cd /tmp/
    $ npm root
    /tmp/node_modules

When executables are installed via npm packages, npm links to them:

  • In local installs, they are linked to from a node_modules/.bin/ directory.
  • In global installs, they are linked to from a global bin/ directory (e.g. /usr/local/bin).

The command npm bin lets you find out where the closest executables are:

    $ npm bin
    /tmp/node_modules/.bin

If your shell is bash then you can define the following command for running executables from that directory:

    function npm-do { (PATH=$(npm bin):$PATH; eval $@;) }

Let’s try out that shell command: We install package figlet-cli that comes with an executable. npm puts multiple packages into the closest node_modules/ and links to the executable figlet from node_modules/.bin/:

    $ npm install figlet-cli
    $ ls -1 /tmp/node_modules/
    figlet
    figlet-cli
    minimist
    optimist
    wordwrap
    $ ls -1 /tmp/node_modules/.bin
    figlet

If we run figlet as a normal shell command, it fails, because we haven’t installed the package (and thus the executable) globally. However, npm-do allows us to run figlet.

    $ figlet hi
    -bash: figlet: command not found
    $ npm-do figlet hi
      _     _
     | |__ (_)
     | '_ | |
     | | | | |
     |_| |_|_|

Inside an npm package

I’m using the repo npm-bin-demo to demonstrate running executables from inside an npm package. This repo is installed as follows (feel free to read on without doing that):

    git clone https://github.com/rauschma/npm-bin-demo.git
    cd npm-bin-demo/
    npm install

That package has the following package.json:

    {
      "bin": {
        "hello": "./hello.js"
      },
      "scripts": {
        "fig": "figlet",
        "hello": "./hello.js"
      },
      "dependencies": {
        "figlet-cli": "^0.1.0"
      }
    }
  • bin: lists the executables provided by this package. It only matters if this package is installed via npm and then affects the node_modules/ of an ancestor directory.

  • scripts: defines commands that you can execute via npm run if the current package.json is the one that is closest to your current working directory. Note that we can use figlet as if it were a globally installed shell command. That’s because npm adds local .bin/ directories to the shell path before it executes scripts.

  • dependencies: lists packages that are installed by npm install, into npm-bin-demo/node_modules/. As you can see, we have installed figlet-cli.

Let’s examine our surroundings (remember that we are still inside the directory npm-bin-demo/):

    $ npm root
    /tmp/npm-bin-demo/node_modules
    $ ls -1 node_modules/
    figlet
    figlet-cli
    minimist
    optimist
    wordwrap
    
    $ npm bin
    /tmp/npm-bin-demo/node_modules/.bin
    $ ls -1 node_modules/.bin/
    figlet

As expected, there is no shell command figlet, but we can run figlet via npm-do:

    $ figlet hi
    -bash: figlet: command not found
    $ npm-do figlet hi
      _     _
     | |__ (_)
     | '_ | |
     | | | | |
     |_| |_|_|

We can also execute figlet via npm run:

    $ npm run fig hi
    
    > @ fig /Users/rauschma/tmp/npm-bin-demo
    > figlet "hi"
    
      _     _
     | |__ (_)
     | '_ | |
     | | | | |
     |_| |_|_|

As explained previously, the entries in bin have no effect inside a package, which is why we can’t run hello via npm-do:

    $ npm-do hello
    -bash: hello: command not found

We can, however, run the script whose name is hello:

    $ npm run hello
    
    > @ hello /tmp/npm-bin-demo
    > ./hello.js
    
    Hello everyone!

Further reading

For more information on the topic of local npm installs, consult Sect. “npm and local installs” in “Setting up ES6”.

Source:: 2ality

Freebie: 12 Ready To Use Templates For List Pages

By Danny Markov

12-ready-to-use-templates

Here we have for you a collection of 12 lovely free templates for displaying various item lists! We’ve created them without relying on any frameworks or libraries, only vanilla HTML and CSS have been used. Because of this, they are very easy to implement and can pair well with all kinds of websites, apps and blogs.

The Templates

The templates are separated in 4 different groups. Here’s what we have:

  • 3 Product lists, perfect for online shops and catalogs.
  • 4 Article lists for presenting blog posts with thumbnails, titles and descriptions.
  • 2 Image lists for displaying galleries and photo albums.
  • 3 User profile lists showing quick information about a person and their avatar.

You can download the entire pack from the Download button near the top of the page.

Using the Templates

After you’ve downloaded them, placing any of the templates in you projects is pretty straightforward. Just follow these easy steps:

  1. Choose the template you like best.
  2. Open it’s example, copy the HTML inside the tag and paste it wherever you want the list in your page.
  3. Get the corresponding CSS file for this particular template and link it to your project (the stylesheets are located in /assets/css). Our CSS is self contained and won’t interfere with the rest of your styles.
  4. Replace our placeholder content with your text and images.
  5. Done!

User Profiles Small

Free for Commercial Use

All 12 templates are completely free of charge and don’t require any form of attribution. You have all rights to customize them and use them however you want, in both personal and commercial projects (our license page). Enjoy!

Source:: Tutorialzine.com

private-data-classes

By Axel Rauschmayer

This blog post explains four approaches for managing private data for ES6 classes:

  1. Keeping private data in the environment of a class constructor
  2. Marking private properties via a naming convention (e.g. a prefixed underscore)
  3. Keeping private data in WeakMaps
  4. Using symbols as keys for private properties

Approaches #1 and #2 were already common in ES5, for constructors. Approaches #3 and #4 are new in ES6. Let’s implement the same example four times, via each of the approaches.

Keeping private data in the environment of a class constructor

Our running example is a class Countdown that invokes a callback action once a counter (whose initial value is counter) reaches zero. The two parameters action and counter should be stored as private data.

In the first implementation, we store action and counter in the environment of the class constructor. An environment is the internal data structure, in which a JavaScript engine stores the parameters and local variables that come into existence whenever a new scope is entered (e.g. via a function call or a constructor call). This is the code:

    class Countdown {
        constructor(counter, action) {
            Object.assign(this, {
                dec() {
                    if (counter < 1) return;
                    counter--;
                    if (counter === 0) {
                        action();
                    }
                }
            });
        }
    }

Using Countdown looks like this:

    > let c = new Countdown(2, () => console.log('DONE'));
    > c.dec();
    > c.dec();
    DONE

Pro:

  • The private data is completely safe
  • The names of private properties won’t clash with the names of other private properties (of superclasses or subclasses).

Cons:

  • The code becomes less elegant, because you need to add all methods to the instance, inside the constructor (at least those methods that need access to the private data).
  • Due to the instance methods, the code wastes memory. If the methods were prototype methods, they would be shared.

More information on this technique: Sect. “Private Data in the Environment of a Constructor (Crockford Privacy Pattern)” in “Speaking JavaScript”.

Marking private properties via a naming convention

The following code keeps private data in properties whose names a marked via a prefixed underscore:

    class Countdown {
        constructor(counter, action) {
            this._counter = counter;
            this._action = action;
        }
        dec() {
            if (this._counter < 1) return;
            this._counter--;
            if (this._counter === 0) {
                this._action();
            }
        }
    }

Pros:

  • Code looks nice.
  • We can use prototype methods.

Cons:

  • Not safe, only a guideline for client code.
  • The names of private properties can clash.

Keeping private data in WeakMaps

There is a neat technique involving WeakMaps that combines the advantage of the first approach (being able to use prototype methods) with the advantage of the second approach (complete safety). That technique is demonstrated in the following code: it uses the WeakMaps _counter and _action to store private data.

    let _counter = new WeakMap();
    let _action = new WeakMap();
    class Countdown {
        constructor(counter, action) {
            _counter.set(this, counter);
            _action.set(this, action);
        }
        dec() {
            let counter = _counter.get(this);
            if (counter < 1) return;
            counter--;
            _counter.set(this, counter);
            if (counter === 0) {
                _action.get(this)();
            }
        }
    }

Each of the two WeakMaps _counter and _action maps objects to their private data. Due to how WeakMaps work that won’t prevent objects from being garbage-collected. As long as you keep the WeakMaps hidden from the outside world, the private data is safe. If you want to be even safer, you can store WeakMap.prototype.get and WeakMap.prototype.set in temporary variables and invoke those (instead of the methods, dynamically). Then our code wouldn’t be affected if malicious code replaced those methods with ones that snoop on our private data. However, we are only protected against code that runs after our code. There is nothing we can do if it runs before ours.

Pros:

  • We can use prototype methods.
  • Safer than a naming convention for property keys.
  • The names of private properties can’t clash.

Con:

  • Code is not as elegant as a naming convention.

Using symbols as keys for private properties

Another storage location for private data are properties whose keys are symbols:

    const _counter = Symbol('counter');
    const _action = Symbol('action');
    
    class Countdown {
        constructor(counter, action) {
            this[_counter] = counter;
            this[_action] = action;
        }
        dec() {
            if (this[_counter] < 1) return;
            this[_counter]--;
            if (this[_counter] === 0) {
                this[_action]();
            }
        }
    }

Each symbol is unique, which is why a symbol-valued property key will never clash with any other property key. Additionally, symbols are somewhat hidden from the outside world, but not completely:

    let c = new Countdown(2, () => console.log('DONE'));
    
    console.log(Object.keys(c));
        // []
    console.log(Reflect.ownKeys(c));
        // [ Symbol(counter), Symbol(action) ]

Pros:

  • We can use prototype methods.
  • The names of private properties can’t clash.

Cons:

  • Code is not as elegant as a naming convention.
  • Not safe: you can list all property keys (including symbols!) of an object via Reflect.ownKeys().

Further reading

  • Sect. “Keeping Data Private” in “Speaking JavaScript” (covers ES5 techniques)
  • Chap. “Classes” in “Exploring ES6”
  • Chap. “Symbols” in “Exploring ES6”

Source:: 2ality