Facade is structural design pattern. It hides the complexities of large system and provides a simple interface to client.
Client uses only Facade and it's not worried about inter dependencies of sub-systems.
Definition from Gang of Four book:
Provide a unified interface to a set of interfaces i...
Round a decimal number to an integer value
For exact numeric values (e.g. DECIMAL): If the first decimal place of a number is 5 or higher, this function will round a number to the next integer away from zero. If that decimal place is 4 or lower, this function will round to the next integer value cl...
Generate a random number
To generate a pseudorandom floating point number between 0 and 1, use the RAND() function
Suppose you have the following query
SELECT i, RAND() FROM t;
This will return something like this
iRAND()10.619143887068220.9384516830914230.83482678498591
Random Number in a r...
Return the absolute value of a number
SELECT ABS(2); -> 2
SELECT ABS(-46); -> 46
The sign of a number compares it to 0.
SignResultExample-1n < 0SELECT SIGN(42); -> 10n = 0SELECT SIGN(0); -> 01n > 0SELECT SIGN(-3); -> -1
SELECT SIGN(-423421); -> -1
Mixins are a sort of class that is used to "mix in" extra properties and methods into a class. This is usually fine because many times the mixin classes don't override each other's, or the base class' methods. But if you do override methods or properties in your mixins this can lead to une...
To install and load the current stable version of ggplot2 for your R installation use:
# install from CRAN
install.packages("ggplot2")
To install the development version from github use
# install.packages("devtools")
devtools::install_github("hadley/ggplot2")
...
public class ConnectSocketExample {
private int HTTP_PORT = 80;
/**
* example method to create unconnected socket
* then connect to it
* at end return connected socket
*
* @param httpHostName - endpoint host name fot socket connection
* @throws IOEx...
/**
* we reuse a class written in example:
* http://stackoverflow.com/documentation/sockets/2876/introduction-to-sockets#t=201607262114505531351
* pleas to familiar with it first to continue with this one
**/
public class WriteToSocketExample extends ConnectSocketExample {
private ...
/**
* Explain briefly what method does here
* @param x Explain briefly what should be x and how this affects the method.
* @param y Explain briefly what should be y and how this affects the method.
* @return Explain what is returned from execution.
*/
def method(x: Int, y: String): O...
import java.util.Scanner;
Scanner s = new Scanner(System.in);
int number = s.nextInt();
If you want to read an int from the command line, just use this snippet.
First of all, you have to create a Scanner object, that listens to System.in, which is by default the Command Line, when you start ...
You can place an SKCameraNode into an SKScene to define which part of the scene is shown in the SKView. Think of the SKScene as a 2D world with a camera floating above it: the SKView will show what the camera 'sees'.
E.g. the camera could be attached to the main character's sprite to follow the act...
Chaining assignments as part of a var declaration will create global variables unintentionally.
For example:
(function foo() {
var a = b = 0;
})()
console.log('a: ' + a);
console.log('b: ' + b);
Will result in:
Uncaught ReferenceError: a is not defined
'b: 0'
In the above examp...
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...
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
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...
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 :...
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...