Tutorial by Examples: al

Return values can be assigned to a local variable. An empty return statement can then be used to return their current values. This is known as "naked" return. Naked return statements should be used only in short functions as they harm readability in longer functions: func Inverse(v float3...
Column aliases are used mainly to shorten code and make column names more readable. Code becomes shorter as long table names and unnecessary identification of columns (e.g., there may be 2 IDs in the table, but only one is used in the statement) can be avoided. Along with table aliases this allows ...
A simple literal function, printing Hello! to stdout: package main import "fmt" func main() { func(){ fmt.Println("Hello!") }() } play it on playground A literal function, printing the str argument to stdout: package main import "fmt&quot...
NaN ("Not a Number") is a special value defined by the IEEE Standard for Floating-Point Arithmetic, which is used when a non-numeric value is provided but a number is expected (1 * "two"), or when a calculation doesn't have a valid number result (Math.sqrt(-1)). Any equality or ...
There are several PHP functions that accept user-defined callback functions as a parameter, such as: call_user_func(), usort() and array_map(). Depending on where the user-defined callback function was defined there are different ways to pass them: Procedural style: function square($number) { ...
// Animal.php class Animal { public function eats($food) { echo "Yum, $food!"; } } // zoo.php require 'Animal.php'; $animal = new Animal; $animal->eats('slop'); // aquarium.php require 'Animal.php'; $animal = new Animal; $animal->eats('shrimp'); H...
// autoload.php spl_autoload_register(function ($class) { require_once "$class.php"; }); // Animal.php class Animal { public function eats($food) { echo "Yum, $food!"; } } // zoo.php require 'autoload.php'; $animal = new Animal; $animal->e...
6 ES6's Object.assign() function can be used to copy all of the enumerable properties from an existing Object instance to a new one. const existing = { a: 1, b: 2, c: 3 }; const clone = Object.assign({}, existing); This includes Symbol properties in addition to String ones. Object rest/sp...
Here's a standalone random number generator that doesn't rely on rand() or similar library functions. Why would you want such a thing? Maybe you don't trust your platform's builtin random number generator, or maybe you want a reproducible source of randomness independent of any particular library ...
GHC's OverloadedLists extension allows you to construct list-like data structures with the list literal syntax. This allows you to Data.Map like this: > :set -XOverloadedLists > import qualified Data.Map as M > M.lookup "foo" [("foo", 1), ("bar", 2)] Just ...
This downloads just a piece of a file, using Range Retrieval Requests, from the Dropbox API at the remote path /Homework/math/Prime_Numbers.txt to the local path Prime_Numbers.txt.partial in the current folder: curl -X GET https://content.dropboxapi.com/2/files/download \ --header "Auth...
A JavaScript value can be converted to a JSON string using the JSON.stringify function. JSON.stringify(value[, replacer[, space]]) value The value to convert to a JSON string. /* Boolean */ JSON.stringify(true) // 'true' /* Number */ JSON.stringify(12) // '12...
A replacer function can be used to filter or transform values being serialized. const userRecords = [ {name: "Joe", points: 14.9, level: 31.5}, {name: "Jane", points: 35.5, level: 74.4}, {name: "Jacob", points: 18.5, level: 41.2}, {name: "Jessie",...
You can use a custom toJSON method and reviver function to transmit instances of your own class in JSON. If an object has a toJSON method, its result will be serialized instead of the object itself. 6 function Car(color, speed) { this.color = color; this.speed = speed; } Car.prototype.to...
A rebase switches the meaning of "ours" and "theirs": git checkout topic git rebase master # rebase topic branch on top of master branch Whatever HEAD's pointing to is "ours" The first thing a rebase does is resetting the HEAD to master; before cherry-picking...
The following is an example that displays 5 one-dimensional random walks of 200 steps: y = cumsum(rand(200,5) - 0.5); plot(y) legend('1', '2', '3', '4', '5') title('random walks') In the above code, y is a matrix of 5 columns, each of length 200. Since x is omitted, it defaults to the row n...
The localStorage object provides persistent (but not permanent - see limits below) key-value storage of strings. Any changes are immediately visible in all other windows/frames from the same origin. The stored values persistent indefinitely unless the user clears saved data or configures an expirati...
Using the AdvancedRTFEditorKit library you can serialize a DefaultStyledDocument to an RTF string. try { DefaultStyledDocument writeDoc = new DefaultStyledDocument(); writeDoc.insertString(0, "Test string", null); AdvancedRTFEditorKit kit = new AdvancedRTFEditorKit(); ...
Functions can return values by specifying the type after the list of parameters. func findHypotenuse(a: Double, b: Double) -> Double { return sqrt((a * a) + (b * b)) } let c = findHypotenuse(3, b: 5) //c = 5.830951894845301 Functions can also return multiple values using tuples. f...
For Alerts since iOS 8, you would use a UIAlertController but for versions before, you would have used a UIAlertView, which is now deprecated. 8.0 var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create(otherTitle, UIAlertActionStyl...

Page 10 of 269