Tutorial by Examples

Starting with Asp.net 4.5 web controls can take advantage from strongly-typed binding to get IntelliSense support and compiletime errors. Create a class, which holds your model: public class Album { public int Id { get; set; } public string Name { get; set; } public string Artist {...
Let's say we have model Travel with many related fields: class Travel(models.Model): tags = models.ManyToManyField( Tag, related_name='travels', ) route_places = models.ManyToManyField( RoutePlace, related_name='travels', ) coordinate = models.F...
Converting an NSDate object to string is just 3 steps. 1. Create an NSDateFormatter object Swift let dateFormatter = NSDateFormatter() Swift 3 let dateFormatter = DateFormatter() Objective-C NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 2. Set the date format in whic...
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...
You can use Gradle to auto-increment your package version each time you build it. To do so create a version.properties file in the same directory as your build.gradle with the following contents: VERSION_MAJOR=0 VERSION_MINOR=1 VERSION_BUILD=1 (Changing the values for major and minor as you s...
class Skill(models.Model): name = models.CharField(max_length=50) description = models.TextField() class Developer(models.Model): name = models.CharField(max_length=50) skills = models.ManyToManyField(Skill, through='DeveloperSkill') class DeveloperSkill(models.Model): ...
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"...
int val = 0; // variable used to store the value // coming from the sensor void setup() { Serial.begin(9600); //Begin serializer to print out value // Note: Analogue pins are // automatically set as inputs } void loop() { val = analogRead(0); // read the va...
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...

Page 295 of 1336