The document discusses new features in ES.next (ECMAScript 2015) that improve on existing JavaScript capabilities. It describes how proxies can be used to intercept operations on objects, allowing properties to be returned dynamically or exceptions thrown. It also covers other new features like maps, destructuring, arrow functions, and let/const that address issues with older variable scoping and iteration behaviors. Overall it presents ES.next as providing solutions for things that used to require frameworks as well as enabling new functionality not previously possible in JavaScript.
This document summarizes magic methods in PHP that allow for custom object behavior. It discusses methods for stringification (__toString()), object lifecycle (__construct(), __destruct()), property overloading (__get(), __set(), etc.), method overloading (__call(), __callStatic()), serialization (__sleep(), __wakeup()), cloning (__clone(), __set_state()), and object invocation (__invoke()). Examples are provided for each method. Performance benchmarks at the end show that magic methods have negligible overhead compared to normal method calls.
The document provides an overview of new features introduced in C# 6.0, including static using, string interpolation, dictionary initializers, auto-property initializers, nameof expression, await in catch/finally blocks, null conditional operator, expression-bodied members, and extension methods used with static using. Code examples are provided to demonstrate the usage of each new feature.
This document summarizes PHP's magic methods. It discusses the purpose and usage of various magic methods like __construct(), __destruct(), __toString(), __get(), __set(), __isset(), __unset(), __call(), __clone(), __set_state(), __callStatic(), __sleep(), __wakeup(), __invoke(), and __autoload(). It provides examples of how each magic method works and when they are called. The document is intended to introduce developers to PHP's magic methods in about an hour and covers their basics.
The document describes a new tool called Sifu that aims to simplify programming by allowing developers to write specifications for applications in a domain-specific language (DSL) called SifuDSL. The SifuCompiler checks these specifications for errors and applies best practices, and the SifuLinker transforms the specifications into maintainable code in the developer's choice of technology stack. The generated code can be freely changed and extended by developers and looks like code written by an experienced developer. Sifu specifications also serve as documentation that is always up to date. The tool claims developers can generate up to 90% of an application's codebase using Sifu alone.
This document describes a Selenium WebDriver data driven framework. It uses external files to store test data and object identifiers to make the framework more flexible and maintainable. The framework includes Java classes for reading test data from Excel files, retrieving object identifiers from property files, and implementing common test functions. Tests are implemented as Java classes that utilize the framework classes to login to a test application, retrieve test data, and verify application behavior.
This document provides an overview of Hibernate Envers, a Hibernate module that enables easy auditing of persistent classes. It discusses how to activate Envers for an entity class, the different annotations used to configure the audit process, and how to query the audit information stored in revision tables. Envers allows tracking changes to entities and retrieving past versions through an AuditReader interface, with support for filtering, ordering and paging results. It provides an out-of-the-box solution for auditing entity data with Hibernate.
This document discusses using the F# programming language for unit testing. It provides examples of writing unit tests in F# using different testing frameworks like NUnit, FsUnit, and Unquote. It also shows how to mock objects and set up expected behavior using mocking libraries in F# like Moq, FakeItEasy, and Foq. Foq is a mocking library for F# that allows mocking using code quotations or a fluent interface. The document compares the lines of code of different mocking libraries and versions of Foq. It promotes F# as an effective testing language.
Indexing and Query Optimizer (Aaron Staple)MongoSF
This document discusses MongoDB indexing and query optimization. It defines what indexes are, how they are stored and used to improve query performance. It provides examples of different types of queries and whether they can utilize indexes, including compound, geospatial and regular expression indexes. It also covers index creation, maintenance and limitations.
The document discusses configuring Tomcat connection pools. It describes preparing Tomcat by adding jar files, configuring the server.xml file and context.xml files, and testing connection pools using JSP. It also covers how Tomcat 6 supports connection pools using dbcp and how JdbcRowSet can use connection pools.
Internationalizing CakePHP ApplicationsPierre MARTIN
The document discusses internationalization in CakePHP, including:
- Using methods like __() and __n() to translate text strings, and Configure::write() to set the application language.
- The Translate behavior, which allows translating database records into multiple languages and automatically filtering by the current language.
- Generating translation files using the i18n extractor, editing them with POEDIT, and caching translated elements.
Practical JavaScript Programming - Session 1/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
Practical JavaScript Programming - Session 7/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
This document describes a scalable, versioned document store built within PostgreSQL. It discusses the motivation for moving from multiple data stores and repositories to a single PostgreSQL database. It then covers the design of storing immutable content as Merkle DAG nodes linked by cryptographic hashes, with references and tags allowing different versions. It also explains how the system was implemented using PostgreSQL functions to generate hashes, insert nodes, and handle migrations from the original data model.
Specs2 is a Scala library for writing acceptance and unit tests. It uses a domain specific language (DSL) approach based on behavior-driven development (BDD). Specs2 specifications are structured, immutable, and control dependencies. Unit specs extend Specification and are mutable, while acceptance specs extend Specification and are functional. Specs2 provides matchers, mock objects, and forms to make assertions in tests. Tests can be run with JUnit or from SBT with different output formats.
The document describes steps to customize the GMF drag-and-drop framework. It involves contributing a custom edit policy provider, attaching a custom edit policy and drop target listener to edit parts, preparing dropped objects, finding a target edit part, returning commands from edit parts, and executing drag-and-drop commands to create concepts through generators.
This document discusses various optimizations and improvements made to Java streams in recent versions. It provides examples of counting large streams, converting streams to arrays, collecting to lists, sorting, skipping elements, and using streams in parallel pipelines. It also covers characteristics of streams like SIZED, ORDERED, DISTINCT, and how operations like distinct(), skip(), and concat() perform in parallel scenarios. Overall it analyzes the performance of core stream operations and how their implementations have evolved.
Practical JavaScript Programming - Session 5/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
Practical JavaScript Programming - Session 6/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
The document contains code for a C# program that merges employee wage and tip data from multiple text files into a single output file. It reads configuration settings from an XML file to determine the input and output file paths. It then reads the input files, merges the data based on employee identifiers, handles null values, and writes the results to the output file. It also writes log information to another output file. The key steps are: 1) reading the configuration, 2) reading and parsing the input files, 3) merging and formatting the data, and 4) writing the merged data and log to output files.
This document provides examples of refactoring Java code to use Guava libraries and utilities. It shows code snippets before and after refactoring to use Guava's Objects, Preconditions, Collections, Splitter, Joiner, Ranges and other utilities to clean up code and make it more readable and robust. Refactoring includes using Guava to validate arguments, create immutable collections, handle nulls safely, join/split strings, and represent ranges.
This is the support of a course to teach mainly Redux, and Redux with React for Java and C# programmers. It is the third part of the course to recycle programmers from desktop app programming to web app programming. This course covers from history of Redux, its origin, step by step what is a reducer, and later concepts like reducer splitting, action handling, async and many more.
You also can use repositories:
- https://github.com/drpicox/learn-redux-bytesting
- https://github.com/drpicox/learn-redux-zoo-bytesting
To improve your skills.
This document discusses Java Database Connectivity (JDBC) and provides examples of connecting to and querying databases using JDBC. It covers the basic steps to connect to a database which include loading the driver, creating a connection, creating statements, and executing queries. Examples are given for connecting to MySQL and retrieving and updating data. Additional topics covered include prepared statements, mapping Java types to SQL types, and using JavaBeans and Data Access Objects for database operations.
This document contains code for a Java GUI application called EasyGUI that allows users to generate automation results for order processing. It contains classes like EasyGUI, EasyButton, and BatchEngine that create a GUI, handle button clicks, and execute automation batches. When the submit button is clicked, it validates the order ID, runs batches to get conversation IDs, account numbers, and CSIXML files, and displays the results. It uses GridBagLayout to arrange components on the main panel and stores selection values in variables like orderID and accountNumber to pass to batch processing methods.
This document provides an overview and examples of using Google Guava, an open-source Java library that includes common libraries useful for writing Java code. It highlights some key classes and methods in Guava, including annotations, strings, collections, I/O, and more. Code samples demonstrate using Guava features like predicates, sets, files, and InetAddress utilities.
This document provides code examples for performing common HBase operations like creating and managing tables, inserting and retrieving records, and scanning data. It includes methods for creating tables, adding and dropping column families, inserting and deleting records, getting single records and scanning multiple records. Filtering scans by column values is also demonstrated through the use of a custom filter class.
REX about JavaFX8 used in SlideshowFX. This presentation covers concept from JavaFX as well as technologies like OSGi, Vert.x, LeapMotion, nashorn and friends in order to make them communicate inside one application developed in JavaFX.
This presentation was made at the ElsassJUG
This document provides an overview of arrays, generics, wildcards, and lambda expressions in Java. It discusses array initialization and multi-dimensional arrays. It explains generics and how they avoid type casting. It covers wildcard types, subclass/superclass constraints, and limitations of generics. The document also demonstrates lambda expressions and functional interfaces like Comparator. It provides examples of common data structures in Java like List, Set, and Map as well as streams and iterators.
The document discusses Firefox OS and web APIs for building mobile apps. It highlights that a Firefox OS app is essentially a website plus proposed phone APIs. It provides examples of common APIs for things like vibration, geolocation, push notifications, and more. It also discusses topics like offline support, storing data via IndexedDB or local storage, and the importance of the app manifest file. The overall message is that the web is a powerful platform for building mobile apps and Firefox OS aims to unleash this potential through proposed web APIs and a simplified development model.
Firefox OS and the Internet of Things - NDC London 2014Jan Jongboom
This document discusses the potential for using Firefox OS and the JanOS operating system to power Internet of Things devices by accessing device sensors and features through HTML, CSS, and JavaScript. It provides examples of projects like a home security camera, Bluetooth doorbell, and tracking device that are made possible by the open web technologies of Firefox OS and JanOS. The document encourages developers to get their own rootable Firefox OS phones and create their own Internet of Things scripts and projects.
The document discusses configuring Tomcat connection pools. It describes preparing Tomcat by adding jar files, configuring the server.xml file and context.xml files, and testing connection pools using JSP. It also covers how Tomcat 6 supports connection pools using dbcp and how JdbcRowSet can use connection pools.
Internationalizing CakePHP ApplicationsPierre MARTIN
The document discusses internationalization in CakePHP, including:
- Using methods like __() and __n() to translate text strings, and Configure::write() to set the application language.
- The Translate behavior, which allows translating database records into multiple languages and automatically filtering by the current language.
- Generating translation files using the i18n extractor, editing them with POEDIT, and caching translated elements.
Practical JavaScript Programming - Session 1/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
Practical JavaScript Programming - Session 7/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
This document describes a scalable, versioned document store built within PostgreSQL. It discusses the motivation for moving from multiple data stores and repositories to a single PostgreSQL database. It then covers the design of storing immutable content as Merkle DAG nodes linked by cryptographic hashes, with references and tags allowing different versions. It also explains how the system was implemented using PostgreSQL functions to generate hashes, insert nodes, and handle migrations from the original data model.
Specs2 is a Scala library for writing acceptance and unit tests. It uses a domain specific language (DSL) approach based on behavior-driven development (BDD). Specs2 specifications are structured, immutable, and control dependencies. Unit specs extend Specification and are mutable, while acceptance specs extend Specification and are functional. Specs2 provides matchers, mock objects, and forms to make assertions in tests. Tests can be run with JUnit or from SBT with different output formats.
The document describes steps to customize the GMF drag-and-drop framework. It involves contributing a custom edit policy provider, attaching a custom edit policy and drop target listener to edit parts, preparing dropped objects, finding a target edit part, returning commands from edit parts, and executing drag-and-drop commands to create concepts through generators.
This document discusses various optimizations and improvements made to Java streams in recent versions. It provides examples of counting large streams, converting streams to arrays, collecting to lists, sorting, skipping elements, and using streams in parallel pipelines. It also covers characteristics of streams like SIZED, ORDERED, DISTINCT, and how operations like distinct(), skip(), and concat() perform in parallel scenarios. Overall it analyzes the performance of core stream operations and how their implementations have evolved.
Practical JavaScript Programming - Session 5/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
Practical JavaScript Programming - Session 6/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
The document contains code for a C# program that merges employee wage and tip data from multiple text files into a single output file. It reads configuration settings from an XML file to determine the input and output file paths. It then reads the input files, merges the data based on employee identifiers, handles null values, and writes the results to the output file. It also writes log information to another output file. The key steps are: 1) reading the configuration, 2) reading and parsing the input files, 3) merging and formatting the data, and 4) writing the merged data and log to output files.
This document provides examples of refactoring Java code to use Guava libraries and utilities. It shows code snippets before and after refactoring to use Guava's Objects, Preconditions, Collections, Splitter, Joiner, Ranges and other utilities to clean up code and make it more readable and robust. Refactoring includes using Guava to validate arguments, create immutable collections, handle nulls safely, join/split strings, and represent ranges.
This is the support of a course to teach mainly Redux, and Redux with React for Java and C# programmers. It is the third part of the course to recycle programmers from desktop app programming to web app programming. This course covers from history of Redux, its origin, step by step what is a reducer, and later concepts like reducer splitting, action handling, async and many more.
You also can use repositories:
- https://github.com/drpicox/learn-redux-bytesting
- https://github.com/drpicox/learn-redux-zoo-bytesting
To improve your skills.
This document discusses Java Database Connectivity (JDBC) and provides examples of connecting to and querying databases using JDBC. It covers the basic steps to connect to a database which include loading the driver, creating a connection, creating statements, and executing queries. Examples are given for connecting to MySQL and retrieving and updating data. Additional topics covered include prepared statements, mapping Java types to SQL types, and using JavaBeans and Data Access Objects for database operations.
This document contains code for a Java GUI application called EasyGUI that allows users to generate automation results for order processing. It contains classes like EasyGUI, EasyButton, and BatchEngine that create a GUI, handle button clicks, and execute automation batches. When the submit button is clicked, it validates the order ID, runs batches to get conversation IDs, account numbers, and CSIXML files, and displays the results. It uses GridBagLayout to arrange components on the main panel and stores selection values in variables like orderID and accountNumber to pass to batch processing methods.
This document provides an overview and examples of using Google Guava, an open-source Java library that includes common libraries useful for writing Java code. It highlights some key classes and methods in Guava, including annotations, strings, collections, I/O, and more. Code samples demonstrate using Guava features like predicates, sets, files, and InetAddress utilities.
This document provides code examples for performing common HBase operations like creating and managing tables, inserting and retrieving records, and scanning data. It includes methods for creating tables, adding and dropping column families, inserting and deleting records, getting single records and scanning multiple records. Filtering scans by column values is also demonstrated through the use of a custom filter class.
REX about JavaFX8 used in SlideshowFX. This presentation covers concept from JavaFX as well as technologies like OSGi, Vert.x, LeapMotion, nashorn and friends in order to make them communicate inside one application developed in JavaFX.
This presentation was made at the ElsassJUG
This document provides an overview of arrays, generics, wildcards, and lambda expressions in Java. It discusses array initialization and multi-dimensional arrays. It explains generics and how they avoid type casting. It covers wildcard types, subclass/superclass constraints, and limitations of generics. The document also demonstrates lambda expressions and functional interfaces like Comparator. It provides examples of common data structures in Java like List, Set, and Map as well as streams and iterators.
The document discusses Firefox OS and web APIs for building mobile apps. It highlights that a Firefox OS app is essentially a website plus proposed phone APIs. It provides examples of common APIs for things like vibration, geolocation, push notifications, and more. It also discusses topics like offline support, storing data via IndexedDB or local storage, and the importance of the app manifest file. The overall message is that the web is a powerful platform for building mobile apps and Firefox OS aims to unleash this potential through proposed web APIs and a simplified development model.
Firefox OS and the Internet of Things - NDC London 2014Jan Jongboom
This document discusses the potential for using Firefox OS and the JanOS operating system to power Internet of Things devices by accessing device sensors and features through HTML, CSS, and JavaScript. It provides examples of projects like a home security camera, Bluetooth doorbell, and tracking device that are made possible by the open web technologies of Firefox OS and JanOS. The document encourages developers to get their own rootable Firefox OS phones and create their own Internet of Things scripts and projects.
This document provides an overview of tools and techniques for developing Node.js applications. It discusses platforms for creating, deploying, running, debugging, and collaborating on Node.js apps such as Cloud Foundry, Heroku, Git, and Cloud Azure. It also mentions languages tools for Node.js like JavaScript bindings to LibUV, standard libraries, and the V8 JavaScript engine. The document discusses challenges like asynchronous programming and provides solutions like workers and static program analysis. It emphasizes that tooling is especially important for JavaScript and recommends resources like treehugger.js for issues like callback hell.
Run your JavaScript app for years on a coin cell - JSConf.asia 2016Jan Jongboom
Jan Jongboom - Run your JS app for years on a coin cell. Presentation given during JSConf.asia 2016 in Singapore about mbed, JerryScript, IoT, Johnny Five and JavaScript.
This document provides an overview of JavaScript for PHP developers. It compares the syntax and core concepts between the two languages. Some of the key points covered include: variables and data types are similar, functions are objects in JavaScript, JavaScript uses prototypes instead of classes, and functions provide scope. The document also summarizes the built-in global functions and properties, common methods for objects like Array and String, and emphasizes that constructor functions are often not needed in JavaScript.
This document discusses proven JavaScript best practices for writing better code. It covers topics like always using var to declare variables, avoiding eval(), using object literals instead of the Object constructor, preferring === over ==, ending statements with semicolons, and turning on strict mode. Each topic is demonstrated with examples of bad code and how to fix it. The document aims to help programmers structure their code properly and avoid common pitfalls in JavaScript.
Ten useful JavaScript tips & best practicesAnkit Rastogi
In this presentation there are ten useful JavaScript techniques which can be included in your application easily with less friction along with some AngularJs tips and best practices as a bonus. These tips and best practices are accompanied by examples & will cover script loading, design pattern, performance optimization and other areas.
Since best practices are very subjective topics, proper benchmarking needs to be done.
This document provides a history of Node.js, beginning in 1987 and continuing through 2009 when Node.js was created. It discusses key events like the creation of JavaScript in 1995 and AJAX in 2005 that led to Node.js being developed. The document also covers Node.js fundamentals like its single-threaded event loop architecture, modules, require(), and streams.
Ember.js is a JavaScript framework for building web applications. It provides conventions and architecture to make applications more organized and testable. Key aspects of Ember.js include Ember objects, computed properties, templates powered by Handlebars, routes for navigation, and a data modeling layer using Ember Data. Components are also used to build reusable isolated views. Ember follows a "data down, actions up" pattern where data flows from parent to child components and user actions bubble up through the components.
Here are the slides that I gave for The Arizona Software Community meetup.
http://www.meetup.com/azsoftcom/events/222936544/
This was a gentle introduction to some of the features in EcmaScript 2015 and how and why you may use them.
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfmallik3000
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD
OR REMOVE NAME. DO NOT HARD CODE NAME. AGAIN MAKE SURE THE
PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR REMOVE NAME. PLEASE
MAKE SURE THE CODE RUNS WITHOUT ANY ERRORS.
Write a class that maintains the scores for a game application. Implement the addition and
removal function to update the database. The gamescore.txt contains player’ name and score data
record fields separated by comma. For Removal function, uses the name field to select record to
remove the game score record.
Use the List.java, LList.java, Dlink.java, GameEntry.java and gamescore.txt found below
Read gamescore.txt to initialize the Linked list in sorted order by score.
Ask the user to add or remove users to update the sorted linked list.
Display “Name exist” when add an exist name to the list.
Display “Name does not exist” when remove a name not on the list.
List.java File:
/** Source code example for \"A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)\"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
/** List ADT */
public interface List
{
/**
* Remove all contents from the list, so it is once again empty. Client is
* responsible for reclaiming storage used by the list elements.
*/
public void clear();
/**
* Insert an element at the current location. The client must ensure that
* the list\'s capacity is not exceeded.
*
* @param item
* The element to be inserted.
*/
public void insert(E item);
/**
* Append an element at the end of the list. The client must ensure that
* the list\'s capacity is not exceeded.
*
* @param item
* The element to be appended.
*/
public void append(E item);
/**
* Remove and return the current element.
*
* @return The element that was removed.
*/
public E remove();
/** Set the current position to the start of the list */
public void moveToStart();
/** Set the current position to the end of the list */
public void moveToEnd();
/**
* Move the current position one step left. No change if already at
* beginning.
*/
public void prev();
/**
* Move the current position one step right. No change if already at end.
*/
public void next();
/** @return The number of elements in the list. */
public int length();
/** @return The position of the current element. */
public int currPos();
/**
* Set current position.
*
* @param pos
* The position to make current.
*/
public void moveToPos(int pos);
/** @return The current element. */
public E getValue();
}
LList.java File:
/**
* Source code example for \"A Practical Introduction to Data Structures and
* Algorithm Analysis, 3rd Edition (Java)\" by Clifford A. Shaffer Copyright
* 2008-2011 by Clifford A. Shaffer
*/
// Doubly linked list implementation
class LList implements List
{
private DLink head; // Pointer to list header
private DLink tail; // Pointer to last element in list
protected DLink curr; // Pointer ahead of current element
int cnt; // Size of list
// Constructors
LList(int size)
{
th.
The document provides an overview of JavaScript for PHP developers. It discusses similarities and differences between JavaScript and PHP syntax, including variables, arrays, conditionals, loops, functions, objects, prototypes, and more. It also summarizes the built-in JavaScript API, including global functions, constructors, and properties and methods of objects like Object, Array, Function, String, Number, Math, Date, and Error.
This document discusses JavaScript best practices for naming variables and functions, code formatting and style, scopes and closures, and class-like structures. It provides examples of how to use descriptive names, consistent formatting, closures to manage variable scopes, immediately invoked function expressions (IIFEs), and dataclass structures in Wakanda to define classes. Following these practices can improve code readability, maintainability and reduce bugs.
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays
Общий обзор новых возможностей ES6, сравнение с более ранними стандартами. Почему стоит использовать ES6 уже сейчас? Поговорим о таких нововведениях как: поддержка классов, шаблоны строк, модули, стрелочные функции, генераторы и о многом другом.
The document provides an agenda for a talk on modeling a Rubik's Cube in JavaScript. It begins with an introduction to scripting languages and ECMAScript. It then discusses modeling a Rubik's Cube by first walking through the code, then modeling the cube and finding moves to solve it. The document covers topics like scripting languages, ECMAScript, object-oriented programming concepts in JavaScript, and modeling a Rubik's Cube to be manipulated programmatically.
The document contains details of 9 practical assignments for an Advance Java course. Each practical assignment involves developing a Java program or application to demonstrate a concept. For example, Practical 01 involves creating a program to select stationary products and display prices; Practical 02 creates an editable employee table; Practical 03 uses a split pane to display planet images; and so on. The final practical involves developing a room reservation system using Enterprise Java Beans.
This document provides an overview of an ES6 hackathon focusing on new features in ES6 including block scope, modules, destructuring, arrow functions, classes, template literals, internationalization, spread syntax, generators, sets, promises and more. Attendees will have 30 minutes to work on code challenges exploring these new ES6 features using resources like JSFiddle and TypeScript. The challenges involve updating functions to use new syntax like arrow functions, default parameters and object shorthand, satisfying class assertions, and improving outputs using template strings and internationalization.
Sequelize is a promise-based ORM for Node.js that allows for modeling of database tables, querying, and synchronization between models and tables. It supports PostgreSQL, MySQL, MariaDB, SQLite, and MSSQL. Sequelize provides advantages like saving time and effort for developers by handling basic tasks and allowing a focus on business logic. Models can be defined and queried, validated, associated with other models, and synchronized with database tables. Raw SQL queries can also be executed through Sequelize.
The document discusses object-oriented programming concepts in JavaScript. It begins with an overview of how everything in JavaScript is an object, even functions, and how objects have prototypes. It then provides examples of using constructor functions, prototype inheritance, and the extend method to create base classes and subclasses. Config objects and model-view design patterns are also demonstrated. The examples show how to build classes for containers, limited containers, query controllers, and adding map and view capabilities to queries. Resources for further learning are provided at the end.
Object-Oriented JavaScript presentation given at the 2010 ESRI Developer Summit. Code and slides are also available at http://github.com/kvangork/OOJS-Presentation
Find me on twitter @kvangork
or my blog http://prng.vangorkom.org
The document provides tips for writing simple, readable code that is easy to maintain and adapt to changes over time. It emphasizes keeping code well-structured with small, single-purpose functions and classes, using good naming conventions, testing code, and designing for flexibility through techniques like dependency injection and interfaces. The document also encourages practicing code through katas and code reviews to improve coding skills.
This document provides an introduction to TinyML and machine learning for embedded devices. It discusses extracting meaningful features from sensor data, developing machine learning models, and deploying models on microcontrollers with limited resources. The goal is to enable on-device intelligence using TinyML to analyze sensor data without sending raw data to the cloud.
Intelligent Edge - Getting started with TinyML for industrial applicationsJan Jongboom
This document discusses using machine learning for industrial applications with tiny machine learning (TinyML). It notes that 99% of sensor data from industrial sensors is discarded due to constraints. On-device intelligence using TinyML can help find patterns in this data. The document outlines steps for developing TinyML models, including collecting raw sensor data, extracting meaningful features from it, and training and deploying neural network models on edge devices. It provides examples of using TinyML for predictive maintenance, audible monitoring, and lone worker monitoring.
Teaching your sensors new tricks with Machine Learning - Eta Compute webinarJan Jongboom
The document discusses using machine learning for industrial sensors to enable on-device intelligence by recognizing patterns in sensor data. It provides an example of a typical industrial sensor that collects large amounts of high-frequency data but discards 99% of it due to constraints. On-device machine learning can analyze the full sensor data to detect abnormal vibrations, temperatures, or patterns that could indicate faults. The document also outlines the steps to develop machine learning models from raw sensor data collected on edge devices.
Get started with TinyML - Embedded online conferenceJan Jongboom
The document discusses the potential of using machine learning for industrial sensors to enable on-device intelligence by recognizing patterns in high-resolution sensor data and extracting meaningful features. It notes that typical sensors currently discard 99% of data due to constraints but machine learning could help detect abnormal vibrations, sounds, or biosignals. The document outlines the process of developing a machine learning model for sensors from getting raw data to building and deploying a model on edge devices to enable new use cases like sensor fusion.
Adding intelligence to your LoRaWAN deployment - The Things Virtual ConferenceJan Jongboom
LoRaWAN devices are typically simple, they grab some sensor data and deliver it back to the network. By adding some embedded machine learning we can make them a lot more intelligent!
Tiny intelligent computers and sensors - Open Hardware Event 2020Jan Jongboom
The document discusses using machine learning and on-device intelligence to analyze sensor data. It notes that currently 99% of sensor data is discarded due to constraints, but drawing conclusions directly on sensors can vastly increase their usefulness. On-device ML is needed to detect patterns in real-time sensor streams and identify anomalies. The speaker presents an example of classifying sheep activity with a neural network model deployed on an edge device. Edge Impulse is introduced as a service that helps collect sensor data, extract features, train models, and deploy them to edge devices for efficient real-time analysis using limited resources.
Teaching your sensors new tricks with Machine Learning - CENSIS Tech Summit 2019Jan Jongboom
We collect more sensor data than ever, but throw most of it away due to cost, bandwidth or power constraints. In this presentation we'll look at embedded machine learning, pushing intelligence directly to the sensor edge. Given during the CENSIS Tech Summit 2019 in Glasgow, Scotland.
Adding intelligence to your LoRaWAN devices - The Things Conference on tourJan Jongboom
The document discusses adding intelligence to LoRaWAN devices by extracting meaningful features from raw sensor data on the device. It notes that currently, 99% of sensor data is discarded due to constraints, but extracting features could enable anomaly detection, classification, and forecasting on the device. It proposes a two-step process: 1) collecting high-resolution raw data from sensors, and 2) extracting features from the raw data on the device to perform intelligent analysis without transmitting all the raw data.
Machine learning on 1 square centimeter - Emerce Next 2019Jan Jongboom
This document discusses machine learning on microcontrollers. It notes that microcontrollers are small, cheap, efficient but slow with limited memory. Reinforcement learning is proposed to enable machine learning applications on microcontrollers using techniques like keyword spotting and object detection that can run inferences in real-time. Examples are provided of neural networks trained on microcontrollers achieving applications like facial recognition with battery life of over a year on a coin cell.
Fundamentals of IoT - Data Science Africa 2019Jan Jongboom
As data scientists your job is to create order in the data chaos. But where does this data come from? Real-world data does not magically appear cleanly in your Matlab scripts. This is a talk about the fundamentals of IoT, and how to retrieve data from the real world using sensors and devices. Given during Data Science Africa 2019 in Addis Ababa.
Recording: https://www.youtube.com/watch?v=DxTetwYsXvo&index=1&list=PLiVCejcvpsevQ_I9oDIK6eIgau45fWje2
The Mbed Simulator allows you to cross-compile Mbed OS 5 applications and run them on your computer.
Efficient IoT solutions based on LoRaWAN, The Things Network and Mbed OSJan Jongboom
This document summarizes a presentation about efficient IoT solutions using LoRaWAN, The Things Network, and Mbed OS. It discusses the benefits of LoRa for long range communication with low power consumption. It provides an overview of LoRaWAN functionality and classes. It also describes the offerings from Arm and The Things Network to simplify IoT development, including Mbed OS as an open source platform and The Things Network for connectivity.
Machine learning on 1 cm2 - Tweakers Dev SummitJan Jongboom
This document discusses machine learning on microcontrollers. It notes that microcontrollers are small, cheap, efficient but slow with limited memory. It then covers reinforcement learning using a board game as an example. It discusses how machine learning can be done efficiently on microcontrollers through techniques like classification rather than training. Examples shown include keyword spotting and object detection on video, achieving inferences per second while using limited RAM and battery life over a year. The document encourages people to get started with machine learning on microcontrollers by running tutorials and examples on development boards.
LoRaWAN is great, but it requires so much hardware. As I live on a plane I want something better. Presentation about simulating LoRaWAN devices. Here's a video of the simulator: https://www.youtube.com/watch?v=C1S8knMlX7w
Develop with Mbed OS - The Things Conference 2019Jan Jongboom
The document discusses Mbed OS, an open source platform OS for IoT devices using Arm Cortex-M microcontrollers. Mbed OS includes integrated security, connectivity options like LoRaWAN, and device management tools. The LoRaWAN stack for Mbed OS supports LoRaWAN versions 1.0.2, 1.0.3 and 1.1, and is optimized for low power usage. Examples are provided to help developers get started with Mbed OS and LoRaWAN.
Firmware Updates over LoRaWAN - The Things Conference 2019Jan Jongboom
IoT deployments last for ten years, but that's a long time. Requirements change, vulnerabilities are found, and standards evolve. You'll need a firmware update solution.
Talk during The Things Conference 2019.
Faster Device Development - GSMA @ CES 2019Jan Jongboom
Presentation about interesting open source developments that can be used in conjunction with LTE Cat-M1 and NB-IoT. Presentation from the GSMA IoT workshop at CES 2019.
Mbed LoRaWAN stack: a case study - LoRa Alliance AMM TokyoJan Jongboom
The document discusses the Mbed LoRaWAN stack, which provides a secure and modular open source LoRaWAN networking stack for IoT devices. It requires minimal memory and is highly configurable. Testing includes certification tests and a simulator. Firmware updates are now standardized and supported in the stack. The stack helps developers quickly build secure LoRaWAN devices and get to market faster.
cyber hacking and cyber fraud by internet online moneyVEENAKSHI PATHAK
Cyber fraud is a blanket term to describe crimes committed by cyberattacks via the internet. These crimes are committed with the intent to illegally acquire and leverage an individual's or business’s sensitive information for monetary gain
Learn the key differences between the Internet and WAN. Understand how high Internet plans and private networks can serve different purposes for businesses.
10 Critical Skills Kids Need in the AI EraRachelDines1
What skills do the next generation need to thrive in the age of AI? Exploring the benefits of AI and the potential risks when it comes to the next generation.
JACKPOT TANGKI4D BERMAIN MENGGUNAKAN ID PRO 2025 TEPERCAYA LISENSI STAR GAMIN...TANGKI4D
MODAL 50RIBU JACKPOT 10JUTA
BERMAIN DI STARLIGHT PRINCESS
TUNGGU APA LAGI MAIN KAN SEKARANG
GUNAKAN POLA BERMAIN REKOMENDASI KAMI
3x MANUAL SPIN ❎❎✅ DC ON-OFF
10x TURBO Spin ✅❎ ✅ DC OFF
2x MANUAL Spin ✅❎✅ DC ON-OFF
20x CEPAT Spin ❎✅✅ DC OFF
COMBO DENGAN BUY FITURE SPIN
#Tangki4dexclusive #tangki4dlink #tangki4dvip #bandarsbobet #idpro2025 #stargamingasia #situsjitu #jppragmaticplay
Building a Multiplatform SDKMAN in JavaFX.pdfJago de Vreede
SDKMAN is one of the most popular ways to install/upgrade Java or other build tooling on your system. It works great from the command line, but what if you could bring its power to a graphical interface? And what if it worked seamlessly on Windows too? In this talk, we will use SDKMAN as an example of how to build a multiplatform native application using JavaFX for the UI and GraalVM to compile native images. We will dive into the process of creating native apps with GraalVM, distributing them with GitHub, and identifying some limitations of native Java applications. Plus, we’ll explore alternative methods for shipping native apps across platforms. By the end of this session, you will have practical insights on how to build and distribute native apps with or without JavaFX.
Shopify API Integration for Custom Analytics_ Advanced Metrics & Reporting Gu...CartCoders
CartCoders offers specialized Shopify integration services to enhance your eCommerce store's functionality and user experience. Connect your Shopify store seamlessly with essential software and applications. Perfect for businesses aiming to streamline operations and boost efficiency.
RIRs and the Next Chapter of Internet Growth - from IPv4 to IPv6APNIC
Subha Shamarukh, Internet Resource Analyst at APNIC, presented on 'RIRs and the Next Chapter of Internet Growth - from IPv4 to IPv6' at the Bangladesh Internet Governance Forum held in Dhaka on 29 January 2025.
11. Things you can already do
alt: S*#t that annoys Jan in JavaScript
12. NodeList is not an array
1 document.querySelectorAll('li')
2 .filter(function(li) {
3 /* do something */
4 });
5
ERROR: document.querySelectorAll(...).filter
is not a function
13. NodeList is not an array
1 Array.prototype.slice.call(
2 document.querySelectorAll('li')
3 )
14. NodeList is not an array
1 Array.prototype.slice.call(
2 document.querySelectorAll('li')
3 )
1 Array.from(
2 document.querySelectorAll('li')
3 )
15. Variable scoping
1 var a = 7;
2
3 if (something) {
4 var a = 9;
5 doSomethingElse(a);
6 }
7
8 console.log(a);
16. Variable scoping
1 var a = 7;
2
3 if (something) {
4 var a = 9;
5 doSomethingElse(a);
6 }
7
8 console.log(a);
// can be 7 or 9 depending on 'something'
17. Variable scoping
1 var a = 7;
2
3 if (something) {
4 var a = 9;
5 doSomethingElse(a);
6 }
7
8 console.log(a);
// can be 7 or 9 depending on 'something'
18. Variable scoping
1 var a = 7;
2
3 if (something) {
4 var a = 9;
5 doSomethingElse(a);
6 }
7
8 console.log(a);
// can be 7 or 9 depending on 'something'
19. Variable scoping
1 let a = 7;
2
3 if (something) {
4 let a = 9;
5 doSomethingElse(a);
6 }
7
8 console.log(a);
// always 7
‘let’ to the rescue
20. Variable scoping
1 let a = 7;
2
3 if (something) {
4 let a = 9;
5 doSomethingElse(a);
6 }
7
8 console.log(a);
// always 7
‘let’ to the rescue
87. Normal function
1 function normal() {
2 console.log('Hi there!');
3
4 var a = 5 + 6;
5 console.log('I think it's', a);
6
7 console.log('kthxbye');
8
9 return 3;
10 }
88. Generators are lazy
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 turingWinners();
89. Generators are lazy
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 turingWinners();
90. Generators are lazy
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 turingWinners();
91. Generators are lazy
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 turingWinners();
92. Generators are lazy
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 turingWinners();
$ node --harmony test.js
$
93. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
94. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
95. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
96. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
$ node --harmony test.js
Hello from our function
{ value: 'Alan J. Perlis', done: false }
97. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
98. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
99. Call next() to start
1 function* turingWinners () {
2 console.log('Hello from our function');
3 yield "Alan J. Perlis";
4 console.log('I returned the first one');
5 yield "Maurice Wilkes";
6 yield "Richard Hamming";
7 yield "Marvin Minsky";
8 }
9
10 var iterator = turingWinners();
11
12 console.log(iterator.next());
13 console.log(iterator.next());
$ node --harmony test.js
Hello from our function
{ value: 'Alan J. Perlis', done: false }
I returned the first one
{ value: 'Maurice Wilkes', done: false }
100. Inef!cient thing in JS
1 var nice = [1,2,3,4,5,6,7,8,9,10,11,12]
2 .filter(function(v) {
3 return v % 2 === 0;
4 })
5 .map(function(v) {
6 return v * v;
7 })
8 .slice(0, 3);
9
10 console.log(nice);
101. Inef!cient thing in JS
1 var nice = [1,2,3,4,5,6,7,8,9,10,11,12]
2 .filter(function(v) {
3 return v % 2 === 0;
4 })
5 .map(function(v) {
6 return v * v;
7 })
8 .slice(0, 3);
9
10 console.log(nice);
102. Inef!cient thing in JS
1 var nice = [1,2,3,4,5,6,7,8,9,10,11,12]
2 .filter(function(v) {
3 return v % 2 === 0;
4 })
5 .map(function(v) {
6 return v * v;
7 })
8 .slice(0, 3);
9
10 console.log(nice);
103. Inef!cient thing in JS
1 var nice = [1,2,3,4,5,6,7,8,9,10,11,12]
2 .filter(function(v) {
3 return v % 2 === 0;
4 })
5 .map(function(v) {
6 return v * v;
7 })
8 .slice(0, 3);
9
10 console.log(nice);
104. Inef!cient thing in JS
1 var nice = [1,2,3,4,5,6,7,8,9,10,11,12]
2 .filter(function(v) {
3 return v % 2 === 0;
4 })
5 .map(function(v) {
6 return v * v;
7 })
8 .slice(0, 3);
9
10 console.log(nice);
105. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
106. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
107. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
1,2,3,4,5,6
108. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
1,2,3,4,5,6
109. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
1,2,3,4,5,6
n%2 == 0
2,4,6
110. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
1,2,3,4,5,6
n%2 == 0
2,4,6
111. 1 function* generateNumber() {
2 var i = 0;
3 while (true)
4 yield ++i;
5 }
6
7 function* filter(it) {
8 for (var n of it)
9 if (n % 2 == 0) yield curr;
10 }
11
12 function* map(it) {
13 for (var n of it)
14 yield n * n;
15 }
1,2,3,4,5,6
n%2 == 0
2,4,6
n * n
4,16,36
112. Using the generators
1 var nice = generateNumber();
2 nice = filter(nice);
3 nice = map(nice);
4
5 for (var i = 0; i < 3; i++) {
6 console.log(i, nice.next().value);
7 }
113. Using the generators
1 var nice = generateNumber();
2 nice = filter(nice);
3 nice = map(nice);
4
5 for (var i = 0; i < 3; i++) {
6 console.log(i, nice.next().value);
7 }
115. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
116. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
117. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
118. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
119. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
120. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
121. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
$ node --harmony test.js
It: Whats your name?
122. Two way interaction
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
5
6 var iterator = printName();
7 console.log('It:', iterator.next().value);
8
9 setTimeout(function() {
10 var ret = iterator.next('Jan Jongboom');
11 console.log(ret);
12 }, 1000);
$ node --harmony test.js
It: Whats your name?
$ node --harmony test.js
It: Whats your name?
Hello Jan Jongboom
{ value: undefined, done: true }
123. Yield and deferred values
• Wrote sync code
• But yield waits until new value comes in...
• So it’s actually async with sync syntax
• We need to abuse this!
1 function* printName() {
2 var name = yield 'Whats your name?';
3 console.log('Hello', name);
4 }
124. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
125. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
126. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
127. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
128. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
129. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
130. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
131. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });
132. 1 function* run() {
2 yield sleep(2000);
3 console.log('It has been 2 seconds');
4 }
5
6 function sleep(ms) {
7 return new Promise((res, rej) => {
8 setTimeout(res, ms);
9 });
10 }
11
12 var it = run();
13 var ret = it.next().value;
14
15 ret.then(function() {
16 it.next();
17 });