Tutorial by Examples

A JSON Array is an ordered collection of values. It is surrounded by square braces i.e [], and values are comma-delimited: { "colors" : [ "red", "green", "blue" ] } JSON Arrays can also contain any valid JSON element, including objects, as in this example ...
This way may seem to be uselss becuase you are using anonymous function to acomplish something that you can do it with join(); But if you need to make something to the strings while you are converting the Array to String, this can be useful. var arr = ['a', 'á', 'b', 'c'] function upper_lower (...
This example shows how to use two audio sources, and alter one of them based on the other. In this case we create an audio Ducker, that will lower the volume of the primary track if the secondary track produces sound. The ScriptProcessorNode will send regular events to its audioprocess handler. In ...
Matrix multiplication can be done in two equivalent ways with the dot function. One way is to use the dot member function of numpy.ndarray. >>> import numpy as np >>> A = np.ones((4,4)) >>> A array([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1.,...
The dot function can also be used to compute vector dot products between two one-dimensional numpy arrays. >>> v = np.array([1,2]) >>> w = np.array([1,2]) >>> v.dot(w) 5 >>> np.dot(w,v) 5 >>> np.dot(v,w) 5
The numpy dot function has an optional parameter out=None. This parameter allows you to specify an array to write the result to. This array must be exactly the same shape and type as the array that would have been returned, or an exception will be thrown. >>> I = np.eye(2) >>> I ...
Since functions are ordinary values, there is a convenient syntax for creating functions without names: List.map (fun x -> x * x) [1; 2; 3; 4] (* - : int list = [1; 4; 9; 16] *) This is handy, as we would otherwise have to name the function first (see let) to be able to use it: let square x...
class Plane { enum Emergency: ErrorType { case NoFuel case EngineFailure(reason: String) case DamagedWing } var fuelInKilograms: Int //... init and other methods not shown func fly() throws { // ... if fuelInKilograms ...
const int a = 0; /* This variable is "unmodifiable", the compiler should throw an error when this variable is changed */ int b = 0; /* This variable is modifiable */ b += 10; /* Changes the value of 'b' */ a += 10; /* Throws a compiler error */ The const qualif...
If while working you realize you're on wrong branch and you haven't created any commits yet, you can easily move your work to correct branch using stashing: git stash git checkout correct-branch git stash pop Remember git stash pop will apply the last stash and delete it from the stash list. T...
process.argv is an array containing the command line arguments. The first element will be node, the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments. Code Example: Output sum of all command line arguments index.js var sum = 0...
Pointer assignments do not copy strings You can use the = operator to copy integers, but you cannot use the = operator to copy strings in C. Strings in C are represented as arrays of characters with a terminating null-character, so using the = operator will only save the address (pointer) of a str...
Here we make a simple echo websocket using asyncio. We define coroutines for connecting to a server and sending/receiving messages. The communcations of the websocket are run in a main coroutine, which is run by an event loop. This example is modified from a prior post. import asyncio import ai...
Install cx_Freeze from here Unzip the folder and run these commands from that directory: python setup.py build sudo python setup.py install Create a new directory for your python script and create a "setup.py" file in the same directory with the following content: application_title ...
PHP only allows single inheritance. In other words, a class can only extend one other class. But what if you need to include something that doesn't belong in the parent class? Prior to PHP 5.4 you would have to get creative, but in 5.4 Traits were introduced. Traits allow you to basically "copy...
A singleton is a pattern that restricts the instantiation of a class to one instance/object. Using a decorator, we can define a class as a singleton by forcing the class to either return an existing instance of the class or create a new instance (if it doesn't exist). def singleton(cls): i...
Using vanilla mathematics: var from:Point = new Point(100, 50); var to:Point = new Point(80, 95); var angle:Number = Math.atan2(to.y - from.y, to.x - from.x); Using a new vector representing the difference between the first two: var difference:Point = to.subtract(from); var angle:Number ...
Using vanilla mathematics: var from:Point = new Point(300, 10); var to:Point = new Point(75, 40); var a:Number = to.x - from.x; var b:Number = to.y - from.y; var distance:Number = Math.sqrt(a * a + b * b); Using inbuilt functionality of Point: var distance:Number = to.subtract(from).len...
var degrees:Number = radians * 180 / Math.PI;
var radians:Number = degrees / 180 * Math.PI;

Page 418 of 1336