Tutorial by Examples: an

There are multiple ways to append values onto an array var exampleArray = [1,2,3,4,5] exampleArray.append(6) //exampleArray = [1, 2, 3, 4, 5, 6] var sixOnwards = [7,8,9,10] exampleArray += sixOnwards //exampleArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and remove values from an array exampleAr...
Since PHP 5.0, PDO has been available as a database access layer. It is database agnostic, and so the following connection example code should work for any of its supported databases simply by changing the DSN. // First, create the database handle //Using MySQL (connection via local socket): $d...
The differences between null and undefined null and undefined share abstract equality == but not strict equality ===, null == undefined // true null === undefined // false They represent slightly different things: undefined represents the absence of a value, such as before an identifier/...
A quick way to make a copy of an array (as opposed to assigning a variable with another reference to the original array) is: arr[:] Let's examine the syntax. [:] means that start, end, and slice are all omitted. They default to 0, len(arr), and 1, respectively, meaning that subarray that we are ...
You can use slices to very easily reverse a str, list, or tuple (or basically any collection object that implements slicing with the step parameter). Here is an example of reversing a string, although this applies equally to the other types listed above: s = 'reverse me!' s[::-1] # '!em esrever...
Jsoup can be be used to easily extract all links from a webpage. In this case, we can use Jsoup to extract only specific links we want, here, ones in a h3 header on a page. We can also get the text of the links. Document doc = Jsoup.connect("http://stackoverflow.com").userAgent("Mozi...
CSS transforms are based on the size of the elements so if you don't know how tall or wide your element is, you can position it absolutely 50% from the top and left of a relative container and translate it by 50% left and upwards to center it vertically and horizontally. Keep in mind that with this...
Anchors can be used to jump to specific tags on an HTML page. The <a> tag can point to any element that has an id attribute. To learn more about IDs, visit the documentation about Classes and IDs. Anchors are mostly used to jump to a subsection of a page and are used in conjunction with header...
Python provides string interpolation and formatting functionality through the str.format function, introduced in version 2.6 and f-strings introduced in version 3.6. Given the following variables: i = 10 f = 1.5 s = "foo" l = ['a', 1, 2] d = {'a': 1, 2: 'foo'} The following statem...
Signed integers can be of these types (the int after short, or long is optional): signed char c = 127; /* required to be 1 byte, see remarks for further information. */ signed short int si = 32767; /* required to be at least 16 bits. */ signed int i = 32767; /* required to be at least 16 bits */ ...
The C language has three mandatory real floating point types, float, double, and long double. float f = 0.314f; /* suffix f or F denotes type float */ double d = 0.314; /* no suffix denotes double */ long double ld = 0.314l; /* suffix l or L denotes long double */ /* the differen...
Use new Date() to generate a new Date object containing the current date and time. Note that Date() called without arguments is equivalent to new Date(Date.now()). Once you have a date object, you can apply any of the several available methods to extract its properties (e.g. getFullYear() to get t...
It is possible to emulate container types, which support accessing values by key or index. Consider this naive implementation of a sparse list, which stores only its non-zero elements to conserve memory. class sparselist(object): def __init__(self, size): self.size = size se...
The general syntax for declaring a one-dimensional array is type arrName[size]; where type could be any built-in type or user-defined types such as structures, arrName is a user-defined identifier, and size is an integer constant. Declaring an array (an array of 10 int variables in this case) i...
Git will usually open an editor (like vim or emacs) when you run git commit. Pass the -m option to specify a message from the command line: git commit -m "Commit message here" Your commit message can go over multiple lines: git commit -m "Commit 'subject line' message here Mor...
var a = Math.random(); Sample value of a: 0.21322848065742162 Math.random() returns a random number between 0 (inclusive) and 1 (exclusive) function getRandom() { return Math.random(); } To use Math.random() to get a number from an arbitrary range (not [0,1)) use this function to get a...
Extensions can contain functions and computed/constant get variables. They are in the format extension ExtensionOf { //new functions and get-variables } To reference the instance of the extended object, self can be used, just as it could be used To create an extension of String that adds ...
reduce will not terminate the iteration before the iterable has been completly iterated over so it can be used to create a non short-circuit any() or all() function: import operator # non short-circuit "all" reduce(operator.and_, [False, True, True, True]) # = False # non short-circu...
Publish and Subscribe for Node.JS Install PubNub NPM Package. npm install [email protected] Example Publish Subscribe with Node.JS var channel = "hello_world"; var pubnub = require("pubnub")({ publish_key : "your_pub_key" , subscribe_key : "your_sub_ke...
When it comes to adding/removing channels to/from your channel groups, you need to have must have the manage permission for those channel groups. But you should never grant clients the permission to manage the channel groups that they will subscribe to. If they did, then they could add any channel t...

Page 10 of 307