Tutorial by Examples: c

It should be noted that Fetch does not support progress callbacks. See: https://github.com/github/fetch/issues/89. The alternative is to use XMLHttpRequest https://developer.mozilla.org/en-US/docs/Web/Events/progress. fetch('https://mywebsite.com/mydata.json').then(json => console.log(json)); ...
The click binding can be used with any visible DOM element to add an event handler, that will invoke a JavaScript function, when element is clicked. <button data-bind="click: onClick">Click me</button> ko.applyBindings({ onClick: function(data, event) { // data: the...
int squareNum (int a) { return a*a; } int : return type squareNum : function name int a : parameter type and name return a*a : return a value (same type as the return type defined at the beginning)
If you have a function declared you can call it anywhere else in the code. Here is an example of calling a function: void setup(){ Serial.begin(9600); } void loop() { int i = 2; int k = squareNum(i); // k now contains 4 Serial.println(k); delay(500); } int squareNum(int a)...
Given the following definitions : public interface IMyInterface1 { string GetName(); } public interface IMyInterface2 { string GetName(); } public class MyClass : IMyInterface1, IMyInterface2 { string IMyInterface1.GetName() { return "IMyInterface1"...
This simple example provides an explanation on some functions I found extremely useful since I have started using MATLAB: cellfun, arrayfun. The idea is to take an array or cell class variable, loop through all its elements and apply a dedicated function on each element. An applied function can eith...
The use of Matlab Coder sometimes denies the use of some very common functions, if they are not compatible to C++. Relatively often there exist undocumented helper functions, which can be used as replacements. Here is a comprehensive list of supported functions.. And following a collection of alte...
In MATLAB versions prior to R2014b, using the old HG1 graphics engine, it was not obvious how to create color coded 2D line plots. With the release of the new HG2 graphics engine arose a new undocumented feature introduced by Yair Altman: n = 100; x = linspace(-10,10,n); y = x.^2; p = plot(x,y,'r...
Since Matlab R2014b it is easily possible to achieve semi-transparent markers for line and scatter plots using undocumented features introduced by Yair Altman. The basic idea is to get the hidden handle of the markers and apply a value < 1 for the last value in the EdgeColorData to achieve the d...
While it's often tempting to catch every Exception: try: very_difficult_function() except Exception: # log / try to reconnect / exit gratiously finally: print "The END" # it runs no matter what execute. Or even everything (that includes BaseException and all its c...
There are a few ways to catch multiple exceptions. The first is by creating a tuple of the exception types you wish to catch and handle in the same manner. This example will cause the code to ignore KeyError and AttributeError exceptions. try: d = {} a = d[1] b = d.non_existing_fiel...
Sometimes it is useful to create union types with only one case to implement record-like types: type Point = Point of float * float let point1 = Point(0.0, 3.0) let point2 = Point(-2.5, -4.0) These become very useful because they can be decomposed via pattern matching in the same way as tu...
If you don't know which options you should use, you may be interested in the :options command. This will open a split with all Vim options listed and with their current value displayed. There are 26 sections to display all options you can try. e.g. 4 displaying text scroll number of lines t...
Let's say we have a class MyClass with no constructor argument: class MyClass In Scala we can instantiate it using below syntax: val obj = new MyClass() Or we can simply write: val obj = new MyClass But, if not paid attention, in some cases optional parenthesis may produce some unexpecte...
Singleton Objects Scala supports static members, but not in the same manner as Java. Scala provides an alternative to this called Singleton Objects. Singleton objects are similar to a normal class, except they can not be instantiated using the new keyword. Below is a sample singleton class: object...
Array.prototype.map(): Returns a new array with the results of calling a provided function on every element in the original array. The following code example takes an array of persons and creates a new array containing persons with a 'fullName' property var personsArray = [ { id: 1, f...
In JavaScript all arguments are passed by value. When a function assigns a new value to an argument variable, that change will not be visible to the caller: var obj = {a: 2}; function myfunc(arg){ arg = {a: 5}; // Note the assignment is to the parameter variable itself } myfunc(obj); conso...
Information Inheritance allows you to derive a new class from an existing class. You do this using the INHERITING FROM addition in the CLASS subclass DEFINITION INHERITING FROM superclass. statement. The new class subclass inherits all of the components of the existing class superclass. The n...
Information The ABSTRACT and FINAL additions to the METHODS and CLASS statements allow you to define abstract and final methods or classes. An abstract method is defined in an abstract class and cannot be implemented in that class. Instead, it is implemented in a subclass of the class. Abstra...
During development, when certain code paths must be prevented from the reach of control flow, you may use assert(0) to indicate that such a condition is erroneous: switch (color) { case COLOR_RED: case COLOR_GREEN: case COLOR_BLUE: break; default: assert(0); ...

Page 182 of 826