class MyClass {
function my_init_method() {
// do something here
}
}
$obj = new MyClass();
add_action( 'init', array( $obj, 'my_init_method' ) );
Using a method of an object to hook a set of instructions. With the init hook, the set of instructions will be executed right...
if (a > b) {
trace("You win!");
} else if (a == b) {
trace("It's a draw!");
} else {
trace("You lose!");
}
// Assigning the evaluated expression to a variable
var message = if (a > b) {
"You win!";
} else if (a == b) {
&...
n % 2 == 0 ? trace("n is even!") : trace("n is odd!");
// Assigning the evaluated expression to a variable
var message = n % 2 == 0 ? "n is even!" : "n is odd!";
trace(message);
Reference
"If", Haxe manual
A loop is a control flow structure to definitely or indefinitely run a set of statement written only once in code, until a certain condition is met or the process is terminated.
Condition loops
These loops are repeated based on the state of their conditions.
For loops
For loops are usually run...
If different users need different datetime format then you may need to parse your incoming date string to actual date according to the format. In this case this snippet may help you.
public class DateTimeBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext control...
In this example you'll learn how to share a file with other apps. We'll use a pdf file in this example although the code works with every other format as well.
The roadmap:
Specify the directories in which the files you want to share are placed
To share files we'll use a FileProvider, a class all...
Pulls the code from a certain specified file into another file where the call was made.
E.g.
inside example.php
<h1>Hello World!</h1>
Inside page.php
// header code
get_template_part('example');
// rest of page code
Output:
// header code
<h1>Hello World</h1>
/...
Any middleware registered as routeMiddleware in app/Http/Kernel.php can be assigned to a route.
There are a few different ways to assign middleware, but they all do the same.
Route::get('/admin', 'AdminController@index')->middleware('auth', 'admin');
Route::get('admin/profile', ['using' => ...
When the command-line syntax for an application is simple, it is reasonable to do the command argument processing entirely in custom code.
In this example, we will present a series of simple case studies. In each case, the code will produce error messages if the arguments are unacceptable, and the...
This example shows how to use the Firebase Cloud Messaging(FCM) platform.
FCM is a successor of Google Cloud Messaging(GCM). It does not require C2D_MESSAGE permissions from the app users.
Steps to integrate FCM are as follows.
Create sample hello world project in Android Studio
Your Android...
Professionally made web applications don't expose the internal details of the server environment to the user. When you place an order at your retailer, you don't see (or have to type) https://mydealer.com:8443/Dealerapp/entryPage.html, but just mydealer.com, although the app server needs all the det...
Angular 1 is at heart a DOM compiler. We can pass it HTML, either as a template or just as a regular web page, and then have it compile an app.
We can tell Angular to treat a region of the page as an expression using the {{ }} handlebars style syntax. Anything between the curly braces will be compi...
A behavior based animation allows you to specify that when a property changes the change should be animated over time.
ProgressBar {
id: progressBar
from: 0
to: 100
Behavior on value {
NumberAnimation {
duration: 250
}
}
}
In this example ...
int[string] aa = ["x": 5, "y": 6];
// The value can be set by its key:
aa["x"] = 7;
assert(aa["x"] == 7);
// if the key does not exist will be added
aa["z"] = 8;
assert(aa["z"] == 8);
Let's assume an associative array aa:
int[string] aa = ["x": 5, "y": 6];
Items can be removed by using .remove(), if key exits will be removed and remove returns true:
assert(aa.remove("x"));
if the given key does not exist remove does nothing and returns false:...
The StretchViewport is a Viewporttype, which supports a virtual screen size.
This allowes you to define a fixed (resolution independent) width and height.
The StretchViewport, as the name suggests, stretches the virtual screen, if the virtual aspect ratio does not match the real aspect ratio. The ...
Scala's implementation of type classes is rather verbose. One way to reduce the verbosity is to introduce so-called "Operation Classes". These classes will automatically wrap a variable/value when they are imported to extend functionality.
To illustrate this, let us first create a simple ...