Specially useful for has_and_belongs_to_many relation, you can manually create a join table using the create_table method.
Suppose you have two models Tags and Proyects, and you'd like to associate them using a has_and_belongs_to_many relation. You need a join table to associate instances of both c...
Occasionally you may want to use the same tuple type in multiple places throughout your code. This can quickly get messy, especially if your tuple is complex:
// Define a circle tuple by its center point and radius
let unitCircle: (center: (x: CGFloat, y: CGFloat), radius: CGFloat) = ((0.0, 0.0), ...
The DATEDIF function returns the difference between two date values, based on the interval specified. It is provided for compatibility with Lotus 1-2-3. The DATEDIF function cannot be found on the function list and autocomplete and screen tips are unavailable. Note: It is pronounced "date diff&...
In most examples, the class naming convention is used to define an Aurelia Custom Element. However, Aurelia also provides a decorator that can be used to decorate a class. The class is again treated as a custom element by Aurelia then.
The value supplied to the decorator becomes the name of the cus...
Usually data sent in a POST request is structured key/value pairs with a MIME type of application/x-www-form-urlencoded. However many applications such as web services require raw data, often in XML or JSON format, to be sent instead. This data can be read using one of two methods.
php://input is a...
You can declare multiple constants within the same const block:
const (
Alpha = "alpha"
Beta = "beta"
Gamma = "gamma"
)
And automatically increment constants with the iota keyword:
const (
Zero = iota // Zero == 0
One // One == 1...
Invoking a function as a method of an object the value of this will be that object.
var obj = {
name: "Foo",
print: function () {
console.log(this.name)
}
}
We can now invoke print as a method of obj. this will be obj
obj.print();
This will thus log:
Foo...
Invoking a function as an anonymous function, this will be the global object (self in the browser).
function func() {
return this;
}
func() === window; // true
5
In ECMAScript 5's strict mode, this will be undefined if the function is invoked anonymously.
(function () {
"use...
When a function is invoked as a constructor with the new keyword this takes the value of the object being constructed
function Obj(name) {
this.name = name;
}
var obj = new Obj("Foo");
console.log(obj);
This will log
{ name: "Foo" }
6
When using arrow functions this takes the value from the enclosing execution context's this (that is, this in arrow functions has lexical scope rather than the usual dynamic scope). In global code (code that doesn't belong to any function) it would be the global object. And it keeps that way, eve...
The apply and call methods in every function allow it to provide a custom value for this.
function print() {
console.log(this.toPrint);
}
print.apply({ toPrint: "Foo" }); // >> "Foo"
print.call({ toPrint: "Foo" }); // >> "Foo"
You mig...
The bind method of every function allows you to create new version of that function with the context strictly bound to a specific object. It is specially useful to force a function to be called as a method of an object.
var obj = { foo: 'bar' };
function foo() {
return this.foo;
}
fooOb...
To create a custom template we first need to create php file in a theme directory. You can name it almost any way you want. For this example we will create example.php
One and only thing we need to define inside our example.php, to be recognized by WordPress as a template, is template name. We do t...
Let's extend our template from above and include content from header.php and footer.php
Including header:
We will include header right after Template name comment
There are two common ways to do this. Both are right and work same, it's just about your style and how code looks
First way:
<?ph...
We will further extend our template and include title of the page and a content
<?php
/*
Template Name: Example
*/
get_header();
the_title();
the_content();
get_footer();
And if you want you can wrap them with HTML elements like this
<?php
/*
Template Name: Example
*...
Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value).
var a = document.querySelector("a"),
url = a.href;
Other attributes, including data-attributes can be accessed as follows:
var a = document.querySelector("a"),
...
3.0
let string = "My fantastic string"
var index = string.startIndex
while index != string.endIndex {
print(string[index])
index = index.successor()
}
Note: endIndex is after the end of the string (i.e. string[string.endIndex] is an error, but string[string.startIndex] i...
[1, 2, [[3, 4], [5]], 6].flatten # => [1, 2, 3, 4, 5, 6]
If you have a multi-dimensional array and you need to make it a simple (i.e. one-dimensional) array, you can use the #flatten method.