Tutorial by Examples: bi

We can use the Service Container as a Registry by binding an instance of an object in it and get it back when we'll need it: // Create an instance. $john = new User('John'); // Bind it to the service container. App::instance('the-user', $john); // ...somewhere and/or in another class... ...
We can bind a class as a Singleton: public function register() { App::singleton('my-database', function() { return new Database(); }); } This way, the first time an instance of 'my-database' will be requested to the service container, a new instance will be created. Al...
A namespace binding (special xmlns or xmlns:... attribute) is in scope for all the descendants of the enclosing element, including this element. <?xml version="1.0"?> <root> <my:element xmlns:my="http://www.example.com/ns1"> <!-- here, the prefix my...
Addition + and subtraction - operations can be used to combine delegate instances. The delegate contains a list of the assigned delegates. using System; using System.Reflection; using System.Reflection.Emit; namespace DelegatesExample { class MainClass { private delegate void MyD...
A bi-directional value converter utilizes two methods in your Value Converter class: toView and fromView these methods are aptly named to signify which direction the data is flowing. In our example we will be creating a prepend Value Converter which will make sure that an amount entered in our app ...
A simple bit-field can be used to describe things that may have a specific number of bits involved. struct encoderPosition { unsigned int encoderCounts : 23; unsigned int encoderTurns : 4; unsigned int _reserved : 5; }; In this example we consider an encoder with 23 bits of sin...
The 0b prefix can be used to represent Binary literals. Binary literals allow constructing numbers from zeroes and ones, which makes seeing which bits are set in the binary representation of a number much easier. This can be useful for working with binary flags. The following are equivalent ways o...
Dynamic binding, also referred as method overriding is an example of run time polymorphism that occurs when multiple classes contain different implementations of the same method, but the object that the method will be called on is unknown until run time. This is useful if a certain condition dicta...
The @var keyword can be used to describe the type and usage of: a class property a local or global variable a class or global constant class Example { /** @var string This is something that stays the same */ const UNCHANGING = "Untouchable"; /** @var string $some_s...
In Kotlin you could write code like: val x: Path = Paths.get("dirName").apply { if (Files.notExists(this)) throw IllegalStateException("The important file does not exist") } But the use of apply is not that clear as to your intent. Sometimes it is clearer to create a ...
Consider this simple example: import QtQuick 2.7 import QtQuick.Controls 2.0 ApplicationWindow { visible: true width: 400 height: 640 Rectangle{ id: rect anchors.centerIn: parent height: 100 width: parent.width color: "blue...
There are three visibility types that you can apply to methods (class/object functions) and properties (class/object variables) within a class, which provide access control for the method or property to which they are applied. You can read extensively about these in the PHP Documentation for OOP Vi...
Bitwise operators can be used to perform bit level operation on variables. Below is a list of all six bitwise operators supported in C: SymbolOperator&bitwise AND|bitwise inclusive OR^bitwise exclusive OR (XOR)~bitwise not (one's complement)<<logical left shift>>logical right shift...
If you want to import a module that doesn't already exist as a built-in module in the Python Standard Library nor as a side-package, you can do this by adding the path to the directory where your module is found to sys.path. This may be useful where multiple python environments exist on a host. im...
Creating a Custom Element with bindable properties is a snap. If you want to create an element that accepts one or more values which the plugin can use, the @bindable decorator and syntax is what you are looking for. Below, we are creating a custom element that accepts an array of fruits and displa...
In the following, we are creating an example of an Aurelia Custom Element which will allow you to display Youtube videos via their video ID. An Aurelia Custom Element can be defined in two different ways: the first one is by creating a viewmodel and accompanying view, the second one is by just cre...
Two-way Data-Binding supports the following attributes: ElementPropertiesAbsListViewandroid:selectedItemPositionCalendarViewandroid:dateCompoundButtonandroid:checkedDatePickerandroid:yearandroid:monthandroid:dayEditTextandroid:textNumberPickerandroid:valueRadioGroupandroid:checkedButtonRatingBarand...
A hexadecimal number is a value in base-16. There are 16 digits, 0-9 and the letters A-F (case does not matter). A-F represent 10-16. An octal number is a value in base-8, and uses the digits 0-7. A binary number is a value in base-2, and uses the digits 0 and 1. All of these numbers result in ...
Python has only limited support for parsing ISO 8601 timestamps. For strptime you need to know exactly what format it is in. As a complication the stringification of a datetime is an ISO 8601 timestamp, with space as a separator and 6 digit fraction: str(datetime.datetime(2016, 7, 22, 9, 25, 59, 55...
var wsHost = "http://my-sites-url.com/path/to/echo-web-socket-handler"; var ws = new WebSocket(wsHost); var buffer = new ArrayBuffer(5); // 5 byte buffer var bufferView = new DataView(buffer); bufferView.setFloat32(0, Math.PI); bufferView.setUint8(4, 127); ws.binaryType = 'arrayb...

Page 5 of 29