Tutorial by Examples: e

class SomeClass { public function __invoke($param1, $param2) { // put your code here } } $instance = new SomeClass(); $instance('First', 'Second'); // call the __invoke() method An object with an __invoke method can be used exactly as any other function. The __invoke meth...
Mapping Applying a function to all elements of an array : array_map('strtoupper', $array); Be aware that this is the only method of the list where the callback comes first. Reducing (or folding) Reducing an array to a single value : $sum = array_reduce($numbers, function ($carry, $number) { ...
The following function can be used to get some basic information about the current browser and return it in JSON format. function getBrowserInfo() { var json = "[{", /* The array containing the browser info */ info = [ navigator.userA...
After your service worker is registered, the browser will try to install & later activate the service worker. Install event listener this.addEventListener('install', function(event) { console.log('installed'); }); Caching One can use this install event returned to cache the assets ne...
MySQL offers a number of different numeric types. These can be broken down into GroupTypesInteger TypesINTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINTFixed Point TypesDECIMAL, NUMERICFloating Point TypesFLOAT, DOUBLEBit Value TypeBIT
Minimal unsigned value is always 0. TypeStorage(Bytes)Minimum Value(Signed)Maximum Value(Signed)Maximum Value(Unsigned)TINYINT1-27-12827-112728-1255SMALLINT2-215-32,768215-132,767216-165,535MEDIUMINT3-223-8,388,608223-18,388,607224-116,777,215INT4-231-2,147,483,648231-12,147,483,647232-14,294,967,2...
MySQL's DECIMAL and NUMERIC types store exact numeric data values. It is recommended to use these types to preserve exact precision, such as for money. Decimal These values are stored in binary format. In a column declaration, the precision and scale should be specified Precision represents the n...
FLOAT and DOUBLE represent approximate data types. TypeStoragePrecisionRangeFLOAT4 bytes23 significant bits / ~7 decimal digits10^+/-38DOUBLE8 bytes53 significant bits / ~16 decimal digits10^+/-308 REAL is a synonym for FLOAT. DOUBLE PRECISION is a synonym for DOUBLE. Although MySQL also permits...
The BIT type is useful for storing bit-field values. BIT(M) allows storage of up to M-bit values where M is in the range of 1 to 64 You can also specify values with bit value notation. b'111' -> 7 b'10000000' -> 128 Sometimes it is handy to use 'shift' to construct a single-bit valu...
WebSocket provides a duplex/bidirectional communication protocol over a single TCP connection. the client opens a connection to a server that is listening for a WebSocket request a client connects to a server using a URI. A server may listen to requests from multiple clients. Server Endpoint...
It's best for readability (and your sanity) to avoid escaping the escapes. That's where raw strings literals come in. (Note that some languages allow delimiters, which are preferred over strings usually. But that's another section.) They usually work the same way as this answer describes: [A] ba...
Character escaping is what allows certain characters (reserved by the regex engine for manipulating searches) to be literally searched for and found in the input string. Escaping depends on context, therefore this example does not cover string or delimiter escaping. Backslashes Saying that backsla...
Many languages allow regex to be enclosed or delimited between a couple of specific characters, usually the forward slash /. Delimiters have an impact on escaping: if the delimiter is / and the regex needs to look for / literals, then the forward slash must be escaped before it can be a literal (\/...
The easiest and quickest way to encode a Haskell data type to JSON with Aeson is using generics. {-# LANGUAGE DeriveGeneric #-} import GHC.Generics import Data.Text import Data.Aeson import Data.ByteString.Lazy First let us create a data type Person: data Person = Person { firstName :...
Detailed instructions on excel-formula(s). There are many formulas that you can choose from. They are divided up into 7 different categories and are on the FORMULAS tab in Excel. The categories are: Financial Logical Text Date & Time Lookup & Reference Math & trig More Function...
You should not save props into state. It is considered an anti-pattern. For example: export default class MyComponent extends React.Component { constructor() { super(); this.state = { url: '' } this.onChange = this.onChange.bind(this); ...
Sometimes you doesn't want to simply replace or remove the string. Sometimes you want to extract and process matches. Here an example of how you manipulate matches. What is a match ? When a compatible substring is found for the entire regex in the string, the exec command produce a match. A match i...
Some regex engines (such as .NET) can handle context-free expressions, and will work it out. But that's not the case for most standard engines. And even if they do, you'll end up having a complex hard-to-read expression, whereas using a parsing library could make the job easier. How to find all p...
Because Regular Expressions can do a lot, it is tempting to use them for the simplest operations. But using a regex engine has a cost in memory and processor usage: you need to compile the expression, store the automaton in memory, initialize it and then feed it with the string to run it. And there...
If you want to extract something from a webpage (or any representation/programming language), a regex is the wrong tool for the task. You should instead use your language's libraries to achieve the task. If you want to read HTML, or XML, or JSON, just use the library that parses it properly and ser...

Page 542 of 1191