Imagine a goroutine with a two step process, where the main thread needs to do some work between each step:
func main() {
ch := make(chan struct{})
go func() {
// Wait for main thread's signal to begin step one
<-ch
// Perform work
time.Sle...
Django comes with a number of builtin management commands, using python manage.py [command] or, when manage.py has +x (executable) rights simply ./manage.py [command] .
The following are some of the most frequently used:
Get a list of all available commands
./manage.py help
Run your Django ser...
The cmath module is similar to the math module, but defines functions appropriately for the complex plane.
First of all, complex numbers are a numeric type that is part of the Python language itself rather than being provided by a library class. Thus we don't need to import cmath for ordinary arith...
This example shows how to configure multiple environments with different Dependency Injection configuration and separate middlewares in one Startup class.
Alongside of public void Configure(IApplicationBuilder app) and public void ConfigureServices(IServiceCollection services) methods one can use C...
To run a command in a shell, in which you required buffered output (i.e. it is not a stream), use child_process.exec. For example, if you wanted to run the command cat *.js file | wc -l, with no options, that would look like this:
const exec = require('child_process').exec;
exec('cat *.js file | w...
Break and continue keywords work like they do in other languages.
while(true) {
if(condition1) {
continue // Will immediately start the next iteration, without executing the rest of the loop body
}
if(condition2) {
break // Will exit the loop completely
}
}
...
The following example is an introduction to:
Template compilation using underscore
Accessing variables in a template
Creating a view
Rendering a view
Showing a view
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
...
Observables are broadly categorised as Hot or Cold, depending on their emission behaviour. A Cold Observable is one which starts emitting upon request(subscription), whereas a Hot Observable is one that emits regardless of subscriptions.
Cold Observable
/* Demonstration of a Cold Observable */
Ob...
A presentation of a select; usually similar to a textbox where users can type ahead to select an option, or type to enter arbitrary text as a new item in the list.
<input type="text" role="combobox" aria-expanded="false">
Typically, you would use JavaScript to...
A supporting section of the document, designed to be complementary to the main content at a similar level in the DOM hierarchy, but remains meaningful when separated from the main content.
<div role="complementary">
<h2>More Articles</h2>
<ul>
<!-- ...
A large perceivable region that contains information about the parent document.
<p role="contentinfo">
Author: Albert Einstein<br>
Published: August 15, 1940
</p>
In general, it is considered good practice to throw by value (rather than by pointer), but catch by (const) reference.
try {
// throw new std::runtime_error("Error!"); // Don't do this!
// This creates an exception object
// on the heap and would require you to catch the
...
DBContract.java
//Define the tables and columns of your local database
public final class DBContract {
/*Content Authority its a name for the content provider, is convenient to use the package app name to be unique on the device */
public static final String CONTENT_AUTHORITY =...
In C#, types can define custom Conversion Operators, which allow values to be converted to and from other types using either explicit or implicit casts. For example, consider a class that is meant to represent a JavaScript expression:
public class JsExpression
{
private readonly string expres...
Suppose you have many changes in one or more files but from each file you only want to commit some of the changes, you can select the desired changes using:
git add -p
or
git add -p [file]
Each of your changes will be displayed individually, and for each change you will be prompted to choose...
A simple context tree (containing some common values that might be request scoped and included in a context) built from Go code like the following:
// Pseudo-Go
ctx := context.WithValue(
context.WithDeadline(
context.WithValue(context.Background(), sidKey, sid),
time.Now().A...
When a React component is created, a number of functions are called:
If you are using React.createClass (ES5), 5 user defined functions are called
If you are using class Component extends React.Component (ES6), 3 user defined functions are called
getDefaultProps() (ES5 only)
This is the firs...