DOM stands for Document Object Model. It is an object-oriented representation of structured documents like XML and HTML.
Setting the textContent property of an Element is one way to output text on a web page.
For example, consider the following HTML tag:
<p id="paragraph"></p&g...
Python is a widely used high-level programming language for general-purpose programming, created by Guido van Rossum and first released in 1991. Python features a dynamic type system and automatic memory management and supports multiple programming paradigms, including object-oriented, imperative, f...
Variables can be accessed via dynamic variable names. The name of a variable can be stored in another variable, allowing it to be accessed dynamically. Such variables are known as variable variables.
To turn a variable into a variable variable, you put an extra $ put in front of your variable.
$va...
print_r() - Outputting Arrays and Objects for debugging
print_r will output a human readable format of an array or object.
You may have a variable that is an array or object. Trying to output it with an echo will throw the error:
Notice: Array to string conversion. You can instead use the print_r...
The dict() constructor can be used to create dictionaries from keyword arguments, or from a single iterable of key-value pairs, or from a single dictionary and keyword arguments.
dict(a=1, b=2, c=3) # {'a': 1, 'b': 2, 'c': 3}
dict([('d', 4), ('e', 5), ('f', 6)]) # {'d': 4, 'e': ...
Enum cases can contain one or more payloads (associated values):
enum Action {
case jump
case kick
case move(distance: Float) // The "move" case has an associated distance
}
The payload must be provided when instantiating the enum value:
performAction(.jump)
performA...
Decorators normally strip function metadata as they aren't the same. This can cause problems when using meta-programming to dynamically access function metadata. Metadata also includes function's docstrings and its name.
functools.wraps makes the decorated function look like the original function b...
Sometimes you don't want to have your function accessible/stored as a variable. You can create an Immediately Invoked Function Expression (IIFE for short). These are essentially self-executing anonymous functions. They have access to the surrounding scope, but the function itself and any internal va...
Protocols may define associated type requirements using the associatedtype keyword:
protocol Container {
associatedtype Element
var count: Int { get }
subscript(index: Int) -> Element { get set }
}
Protocols with associated type requirements can only be used as generic constraints:...
Setting a specific Seed will create a fixed random-number series:
random.seed(5) # Create a fixed state
print(random.randrange(0, 10)) # Get a random integer between 0 and 9
# Out: 9
print(random.randrange(0, 10))
# Out: 4
Resetting the seed will create the same &qu...
Create a file hello.html with the following content:
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
</head>
<body>
<div>
<p id="hello">Some random text</p>
</div>
<script src=...
In the event that geolocation fails, your callback function will receive a PositionError object. The object will include an attribute named code that will have a value of 1, 2, or 3. Each of these numbers signifies a different kind of error; the getErrorCode() function below takes the PositionError....
git diff --staged
This will show the changes between the previous commit and the currently staged files.
NOTE: You can also use the following commands to accomplish the same thing:
git diff --cached
Which is just a synonym for --staged or
git status -v
Which will trigger the verbose sett...
str.split(sep=None, maxsplit=-1)
str.split takes a string and returns a list of substrings of the original string. The behavior differs depending on whether the sep argument is provided or omitted.
If sep isn't provided, or is None, then the splitting takes place wherever there is whitespace. Howe...
One of the most commonly used events is waiting for the document to have loaded, including both script files and images. The load event on document is used for this.
document.addEventListener('load', function() {
console.log("Everything has now loaded!");
});
Sometimes you try to ...
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/...
Create a new HTML file and paste the following content:
<!DOCTYPE html>
<html ng-app>
<head>
<title>Hello, Angular</title>
<script src="https://code.angularjs.org/1.5.8/angular.min.js"></script>
</head>
<body ng-init="name=...
Creating a database in MySQL
CREATE DATABASE mydb;
Return value:
Query OK, 1 row affected (0.05 sec)
Using the created database mydb
USE mydb;
Return value:
Database Changed
Creating a table in MySQL
CREATE TABLE mytable
(
id int unsigned NOT NULL auto_increme...