Tutorial by Examples

Scenario: You need to resolve a dependency when a method is called, not in the constructor. Solution: Inject an abstract factory into the constructor. When the method is called, it requests the dependency from the abstract factory, which in turn resolves it from the container. (Your class depends o...
const Promise = require('bluebird'), fs = require('fs') Promise.promisifyAll(fs) // now you can use promise based methods on 'fs' with the Async suffix fs.readFileAsync('file.txt').then(contents => { console.log(contents) }).catch(err => { console.error('error reading', er...
Example of map: Promise.resolve([ 1, 2, 3 ]).map(el => { return Promise.resolve(el * el) // return some async operation in real world }) Example of filter: Promise.resolve([ 1, 2, 3 ]).filter(el => { return Promise.resolve(el % 2 === 0) // return some async operation in real world...
This example shows the simplest usage of the Image component to display an image. The Image source property is a url type that can be either a file with an absolute or relative path, an internet URL (http://) or a Qt resource (qrc:/) import QtQuick 2.3 Rectangle { width: 640 height: 4...
const promiseReturningFunction = Promise.coroutine(function* (file) { const data = yield fs.readFileAsync(file) // this returns a Promise and resolves to the file contents return data.toString().toUpperCase() }) promiseReturningFunction('file.txt').then(console.log)
function somethingThatReturnsADisposableResource() { return getSomeResourceAsync(...).disposer(resource => { resource.dispose() }) } Promise.using(somethingThatReturnsADisposableResource(), resource => { // use the resource here, the disposer will automatically close it when ...
Promise.resolve([1, 2, 3]) .mapSeries(el => Promise.resolve(el * el)) // in real world, use Promise returning async function .then(console.log)
const Koa = require('koa') const app = new Koa() app.use(async ctx => { ctx.body = 'Hello World' }) app.listen(8080)
app.use(async (ctx, next) => { try { await next() // attempt to invoke the next middleware downstream } catch (err) { handleError(err, ctx) // define your own error handling function } })
describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', function() { expect([ 1, 2, 3 ].length).to.be.equal(3) }) }) })
var expect = require("chai").expect; describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', function(done) { testSomething(err => { expect(err).to.not.be.equal(null) done() }) }) }) }) ...
describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', function() { return doSomething().then(result => { expect(result).to.be.equal('hello world') }) }) }) })
Unlike var, const/let are bound to lexical scope rather than function scope. { var x = 1 // will escape the scope let y = 2 // bound to lexical scope const z = 3 // bound to lexical scope, constant } console.log(x) // 1 console.log(y) // ReferenceError: y is not defined console.log(z...
Arrow functions automatically bind to the 'this' lexical scope of the surrounding code. performSomething(result => { this.someVariable = result }) vs performSomething(function(result) { this.someVariable = result }.bind(this))
Before starting work with scrapy you have to start a project where you want to store your code. Enter the directory and run this code scrapy startproject helloProject The third part of this code is project name. This code will create a "helloProject" directory with the following conten...
You can qualify a whole folder folder for a specific device type, its files will override the ones outside it on that device: / DeviceFamily-Mobile PageOfEden.xaml MainPage.xaml MainPage.xaml MainPage.xaml.cs PageOfEden.xaml PageOfEden.xaml.cs Files inside the qualifying folder won...
If you browse your app's Assets folder you will notice that all resources are qualified by their scales (As you are required to put seperate files for each scaling in the package manifest). SplashScreen.scale-100.png SplashScreen.scale-125.png SplashScreen.scale-150.png SplashScreen.scale-200.pn...
Let's assume we have an Image element using a square image named Picture.png. We can use different files for each dimension set for the element. Picture.TargetSize-16.png Picture.TargetSize-32.png Picture.TargetSize-128.png Now if we set the Height or Width of our Image to 16px, it will use P...
Multidimensional arrays follow the same rules as single-dimensional arrays when passing them to a function. However the combination of decay-to-pointer, operator precedence, and the two different ways to declare a multidimensional array (array of arrays vs array of pointers) may make the declaratio...
This ability was added to the Bind markup extension after v1607 (Redstone 1). You can specify a function path, as well as arg paths and constant args. Let's assume we have a function defined in our backcode: public string Translate(string text, string from, string to) Now we can use bind to eva...

Page 916 of 1336