Tutorial by Examples: c

jQuery code is often wrapped in jQuery(function($) { ... }); so that it only runs after the DOM has finished loading. <script type="text/javascript"> jQuery(function($) { // this will set the div's text to "Hello". $("#myDiv").text("Hello"...
When a user subscribes to a channel, you may want to set state for that newly subscribed user. While there is a subscribe with state API, there are some scenarios where this is not the most optimal/reliable technique (like during a disconnect/reconnect situation - the state will be lost and not rein...
A cookie is set using the setcookie() function. Since cookies are part of the HTTP header, you must set any cookies before sending any output to the browser. Example: setcookie("user", "Tom", time() + 86400, "/"); // check syntax for function params Description: ...
Retrieve and Output a Cookie Named user The value of a cookie can be retrieved using the global variable $_COOKIE. example if we have a cookie named user we can retrieve it like this echo $_COOKIE['user'];
The value of a cookie can be modified by resetting the cookie setcookie("user", "John", time() + 86400, "/"); // assuming there is a "user" cookie already Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the...
Use the isset() function upon the superglobal $_COOKIE variable to check if a cookie is set. Example: // PHP <7.0 if (isset($_COOKIE['user'])) { // true, cookie is set echo 'User is ' . $_COOKIE['user']; else { // false, cookie is not set echo 'User is not logged in'; } ...
An element can be cloned by invoking the cloneNode method on it. If the first parameter passed to cloneNode is true, the children of the original will also be cloned. var original = document.getElementsByTagName("li")[0]; var clone = original.cloneNode(true);
CREATE TABLE Employees ( Id int NOT NULL, PRIMARY KEY (Id), ... ); This will create the Employees table with 'Id' as its primary key. The primary key can be used to uniquely identify the rows of a table. Only one primary key is allowed per table. A key can also be composed by one...
Many databases allow to make the primary key value automatically increment when a new key is added. This ensures that every key is different. MySQL CREATE TABLE Employees ( Id int NOT NULL AUTO_INCREMENT, PRIMARY KEY (Id) ); PostgreSQL CREATE TABLE Employees ( Id SERIAL PRIMARY...
A class is a user-defined type. A class is introduced with the class, struct or union keyword. In colloquial usage, the term "class" usually refers only to non-union classes. A class is a collection of class members, which can be: member variables (also called "fields"), mem...
There are three keywords that act as access specifiers. These limit the access to class members following the specifier, until another specifier changes the access level again: KeywordDescriptionpublicEveryone has accessprotectedOnly the class itself, derived classes and friends have accessprivate...
Classes/structs can have inheritance relations. If a class/struct B inherits from a class/struct A, this means that B has as a parent A. We say that B is a derived class/struct from A, and A is the base class/struct. struct A { public: int p1; protected: int p2; private: int p3;...
When using inheritance, you can specify the virtual keyword: struct A{}; struct B: public virtual A{}; When class B has virtual base A it means that A will reside in most derived class of inheritance tree, and thus that most derived class is also responsible for initializing that virtual base: ...
Aside from single inheritance: class A {}; class B : public A {}; You can also have multiple inheritance: class A {}; class B {}; class C : public A, public B {}; C will now have inherit from A and B at the same time. Note: this can lead to ambiguity if the same names are used in multipl...
Function overloading is having multiple functions declared in the same scope with the exact same name exist in the same place (known as scope) differing only in their signature, meaning the arguments they accept. Suppose you are writing a series of functions for generalized printing capabilities, b...
A std::vector can be initialized in several ways while declaring it: C++11 std::vector<int> v{ 1, 2, 3 }; // v becomes {1, 2, 3} // Different from std::vector<int> v(3, 6) std::vector<int> v{ 3, 6 }; // v becomes {3, 6} // Different from std::vector<int> v{3, ...
You can iterate over a std::vector in several ways. For each of the following sections, v is defined as follows: std::vector<int> v; Iterating in the Forward Direction C++11 // Range based for for(const auto& value: v) { std::cout << value << "\n"; } /...
There are two primary ways of accessing elements in a std::vector index-based access iterators Index-based access: This can be done either with the subscript operator [], or the member function at(). Both return a reference to the element at the respective position in the std::vector (unles...
There are several ways to use a std::vector as a C array (for example, for compatibility with C libraries). This is possible because the elements in a vector are stored contiguously. C++11 std::vector<int> v{ 1, 2, 3 }; int* p = v.data(); In contrast to solutions based on previous C++ st...
The jQuery function (usually aliased as $) can be used both to select elements and to create new elements. var myLink = $('<a href="http://stackexchange.com"></a>'); You can optionally pass a second argument with element attributes: var myLink = $('<a>', { 'href': 'h...

Page 39 of 826