Tutorial by Examples

package { import flash.display.Sprite; import flash.events.Event; public class Viewport extends Sprite { /** Constructor */ public function Viewport() { super(); // Listen for added to stage event addEventListener(Event.ADDED_TO_STAGE, addedToStageHandle...
The factorial function is a Haskell "Hello World!" (and for functional programming generally) in the sense that it succinctly demonstrates basic principles of the language. Variation 1 fac :: (Integral a) => a -> a fac n = product [1..n] Live demo Integral is the class of in...
The web.config system.web.httpRuntime must target 4.5 to ensure the thread will renter the request context before resuming your async method. <httpRuntime targetFramework="4.5" /> Async and await have undefined behavior on ASP.NET prior to 4.5. Async / await will resume on an arb...
It is possible to await multiple calls concurrently by first invoking the awaitable tasks and then awaiting them. public async Task RunConcurrentTasks() { var firstTask = DoSomethingAsync(); var secondTask = DoSomethingElseAsync(); await firstTask; await secondTask; } Alt...
With a two-way filter, we are able to assign a read and write operation for a single filter that changes the value of the same data between the view and model. //JS Vue.filter('uppercase', { //read : model -> view read: function(value) { return value.toUpperCase(); }, ...
Custom filters in Vue.js can be created easily in a single function call to Vue.filter. //JS Vue.filter('reverse', function(value) { return value.split('').reverse().join(''); }); //HTML <span>{{ msg | reverse }}</span> //'This is fun!' => '!nuf si sihT' It is good prac...
Matplotlib axes are two-dimensional by default. In order to create three-dimensional plots, we need to import the Axes3D class from the mplot3d toolkit, that will enable a new kind of projection for an axes, namely '3d': import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fi...
If you want two or more arguments to be mutually exclusive. You can use the function argparse.ArgumentParser.add_mutually_exclusive_group(). In the example below, either foo or bar can exist but not both at the same time. import argparse parser = argparse.ArgumentParser() group = parser.add_mut...
Create a DataFrame from multiple lists by passing a dict whose values lists. The keys of the dictionary are used as column labels. The lists can also be ndarrays. The lists/ndarrays must all be the same length. import pandas as pd # Create DF from dict of lists/ndarrays df = pd.DataFrame({'...
Only when the foreach statement moves to the next item does the iterator block evaluate up to the next yield statement. Consider the following example: private IEnumerable<int> Integers() { var i = 0; while(true) { Console.WriteLine("Inside iterator: " + i...
If an iterator method has a yield inside a try...finally, then the returned IEnumerator will execute the finally statement when Dispose is called on it, as long as the current point of evaluation is inside the try block. Given the function: private IEnumerable<int> Numbers() { yield re...
To modify an existing column in Rails with a migration, run the following command: rails g migration change_column_in_table This will create a new migration file in db/migration directory (if it doesn’t exist already), which will contain the file prefixed with timestamp and migration file name w...
The robots attribute, supported by several major search engines, controls whether search engine spiders are allowed to index a page or not and whether they should follow links from a page or not. <meta name="robots" content="noindex"> This example instructs all search e...
In Python 3 the cmp built-in function was removed, together with the __cmp__ special method. From the documentation: The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported. Use __lt__() for sorting, __eq__() with __hash__(), and other rich compariso...
Function level annotations help IDEs identify return values or potentially dangerous code /** * Adds two numbers together. * * @param Int $a First parameter to add * @param Int $b Second parameter to add * @return Int */ function sum($a, $b) { return (int) $a + $b; } /** * ...
File level metadata applies to all the code within the file and should be placed at the top of the file: <?php /** * @author John Doe ([email protected]) * @copyright MIT */
If a class extends another class and would use the same metadata, providing it @inheritDoc is a simple way for use the same documentation. If multiple classes inherit from a base, only the base would need to be changed for the children to be affected. abstract class FooBase { /** * @par...
Select Now(); Shows the current server date and time. Update `footable` set mydatefield = Now(); This will update the field mydatefield with current server date and time in server's configured timezone, e.g. '2016-07-21 12:00:00'
Maybe is used to represent possibly empty values - similar to null in other languages. Usually it is used as the output type of functions that can fail in some way. Consider the following function: halve :: Int -> Maybe Int halve x | even x = Just (x `div` 2) | odd x = Nothing Think ...
Let's say you need to implement an automatic search box, but the search operation is somewhat costly, like sending a web request or hitting up a database. You may want to limit the amount of search being done. For example, the user is typing "C# Reactive Extensions" in the search box : I...

Page 230 of 1336