This example assumes you know how to test a Flask app using pytest
Below is an API that takes a JSON input with integer values a and b e.g. {"a": 1, "b": 2}, adds them up and returns sum a + b in a JSON response e.g. {"sum": 3}.
# hello_add.py
from flask import Flask...
Generics are placeholders for types, allowing you to write flexible code that can be applied across multiple types. The advantage of using generics over Any is that they still allow the compiler to enforce strong type-safety.
A generic placeholder is defined within angle brackets <>.
Generic...
cURL is a tool for transferring data with URL syntax. It support HTTP, FTP, SCP and many others(curl >= 7.19.4). Remember, you need to install and enable the cURL extension to use it.
// a little script check is the cURL extension loaded or not
if(!extension_loaded("curl")) {
die...
Broadcast variables are read only shared objects which can be created with SparkContext.broadcast method:
val broadcastVariable = sc.broadcast(Array(1, 2, 3))
and read using value method:
val someRDD = sc.parallelize(Array(1, 2, 3, 4))
someRDD.map(
i => broadcastVariable.value.apply(...
Accumulators are write-only variables which can be created with SparkContext.accumulator:
val accumulator = sc.accumulator(0, name = "My accumulator") // name is optional
modified with +=:
val someRDD = sc.parallelize(Array(1, 2, 3, 4))
someRDD.foreach(element => accumulator += el...
fs.access() determines whether a path exists and what permissions a user has to the file or directory at that path. fs.access doesn't return a result rather, if it doesn't return an error, the path exists and the user has the desired permissions.
The permission modes are available as a property on ...
Due to Node's asynchronous nature, creating or using a directory by first:
checking for its existence with fs.stat(), then
creating or using it depending of the results of the existence check,
can lead to a race condition if the folder is created between the time of the check and the time of ...
In Android, a Toast is a simple UI element that can be used to give contextual feedback to a user.
To display a simple Toast message, we can do the following.
// Declare the parameters to use for the Toast
Context context = getApplicationContext();
// in an Activity, you may also use "th...
If you don't want to use the default Toast view, you can provide your own using the setView(View) method on a Toast object.
First, create the XML layout you would like to use in your Toast.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="...
cursor: value;
Examples:
ValueDescriptionnoneNo cursor is rendered for the elementautoDefault. The browser sets a cursorhelpThe cursor indicates that help is availablewaitThe cursor indicates that the program is busymoveThe cursor indicates something is to be movedpointerThe cursor is a pointe...
The nodemon package makes it possible to automatically reload your program when you modify any file in the source code.
Installing nodemon globally
npm install -g nodemon (or npm i -g nodemon)
Installing nodemon locally
In case you don't want to install it globally
npm install --save-dev nodemo...
A macro can produce different outputs against different input patterns:
/// The `sum` macro may be invoked in two ways:
///
/// sum!(iterator)
/// sum!(1234, iterator)
///
macro_rules! sum {
($iter:expr) => { // This branch handles the `sum!(iterator)` case
$iter.f...
In $e:expr, the expr is called the fragment specifier. It tells the parser what kind of tokens the parameter $e is expecting. Rust provides a variety of fragment specifiers to, allowing the input to be very flexible.
SpecifierDescriptionExamplesidentIdentifierx, foopathQualified namestd::collection...
Exporting a macro to allow other modules to use it:
#[macro_export]
// ^~~~~~~~~~~~~~~ Think of it as `pub` for macros.
macro_rules! my_macro { (..) => {..} }
Using macros from other crates or modules:
#[macro_use] extern crate lazy_static;
// ^~~~~~~~~~~~ Must add this in ord...
docker inspect supports Go Templates via the --format option. This allows for better integration in scripts, without resorting to pipes/sed/grep traditional tools.
Print a container internal IP:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7786807d8084
This is useful for direct ne...
Fortran 2003 introduced intrinsic modules which provide access to special named constants, derived types and module procedures. There are now five standard intrinsic modules:
ISO_C_Binding; supporting C interoperability;
ISO_Fortran_env; detailing the Fortran environment;
IEEE_Exceptions, IEEE_...
INSERT INTO will append to the table or partition, keeping the existing data intact.
INSERT INTO table yourTargetTable SELECT * FROM yourSourceTable;
If a table is partitioned then we can insert into that particular partition in static fashion as shown below.
INSERT INTO TABLE yourTarge...