Self types can be used in traits and classes to define constraints on the concrete classes it is mixed to. It is also possible to use a different identifier for the this using this syntax (useful when outer object has to be referenced from an inner object).
Assume you want to store some objects. Fo...
A for loop iterates from the starting value to the ending value inclusive.
program SimpleForLoop;
{$APPTYPE CONSOLE}
var
i : Integer;
begin
for i := 1 to 10 do
WriteLn(i);
end.
Output:
1
2
3
4
5
6
7
8
9
10
SilverStripe has reasonably good support for submitting form data using AJAX requests. Below is example code of how to set up a basic Form that accepts submissions by both AJAX and traditional default browser behaviour (as is good practice).
Adding the form to our controller
First we need to defin...
The simplest way to get an event handler called on a key press is to connect the handler to the key-press-event signal. In this example, we register for the event for the whole window, but you can also register for individual widgets too.
The most important part is the connection of the handler to ...
This example will call the windows calculator. It's important to notice that the exit code will vary accordingly to the program/script that is being called.
package process.example;
import java.io.IOException;
public class App {
public static void main(String[] args) {
try {
...
This proxy simply appends the string " went through proxy" to every string property set on the target object.
let object = {};
let handler = {
set(target, prop, value){ // Note that ES6 object syntax is used
if('string' === typeof value){
target[prop] = valu...
Create a new console application with one line in the Main method: Console.WriteLine("Hello World")
Remember the path to the .csproj file and replace it in the example.
Create a new Console Application and install the Microsoft.CodeAnalysis NuGet package and try the following code:
cons...
Create a new console application with one line in the Main method: Console.WriteLine("Hello World")
Remember the path to the .vbproj file and replace it in the example.
Create a new Console Application and install the Microsoft.CodeAnalysis NuGet package and try the following code:
Cons...
Install symfony correctly as guided above.
Start symfony server if you are not installed in www directory.
Ensure http://localhost:8000 is working if symfony server is used.
Now it is ready to play with simplest example.
Add following code in a new file /src/AppBundle/Controller/MyController.p...
Do not overcomplicate simple tasks. Most of the time you will need only:
algebraic datatypes
structural recursion
monad-like api (map, flatMap, fold)
There is plenty of complicated stuff in Scala, such as:
Cake pattern or Reader Monad for Dependency Injection.
Passing arbitrary values as...
If all you need is to wrap the value into a promise, you don't need to use the long syntax like here:
//OVERLY VERBOSE
var defer;
defer = $q.defer();
defer.resolve(['one', 'two']);
return defer.promise;
In this case you can just write:
//BETTER
return $q.when(['one', 'two']);
$q.when ...
The following function finds the maximal element in an array:
int find_max(const int *array, size_t len) {
int max = INT_MIN;
for (size_t i = 0; i < len; i++) {
if (max < array[i]) {
max = array[i];
}
}
return max;
}
The input size is the...
Use the package percolate:synced-cron
Define a job:
SyncedCron.add({
name: 'Find new matches for a saved user filter and send alerts',
schedule: function(parser) {
// parser is a later.parse object
return parser.text('every 10 minutes');
},
job: function() {
user.alerts...
Decorator is one of structural design patterns. It is used to add, remove or change behaviour of object. This document will teach you how to use Decorator DP properly.
Let me explain the idea of it to you on a simple example. Imagine you're now in Starbobs, famous coffee company. You can place an o...
In order to determine some simple statistics of a value in a column of a table, you can use an aggregate function.
If your individuals table is:
NameAgeAllie17Amanda14Alana20
You could write this statement to get the minimum, maximum and average value:
SELECT min(age), max(age), avg(age)
FROM i...
During mousemove you get flooded with 30 mouse events per second. You might not be able to redraw your drawings at 30 times per second. Even if you can, you're probably wasting computing power by drawing when the browser is not ready to draw (wasted == across display refresh cycles).
Therefore it m...
In simple terms:
UNION joins 2 result sets while removing duplicates from the result set
UNION ALL joins 2 result sets without attempting to remove duplicates
One mistake many people make is to use a UNION when they do not need to have the duplicates removed. The additional performance cost...