Tutorial by Examples: c

Constants can be defined inside classes using a const keyword. class Foo { const BAR_TYPE = "bar"; // reference from inside the class using self:: public function myMethod() { return self::BAR_TYPE; } } // reference from outside the class using <Class...
This function lets you iterate over the Cartesian product of a list of iterables. For example, for x, y in itertools.product(xrange(10), xrange(10)): print x, y is equivalent to for x in xrange(10): for y in xrange(10): print x, y Like all python functions that accept a v...
Lambda functions in C++ are syntactic sugar that provide a very concise syntax for writing functors. As such, equivalent functionality can be obtained in C++03 (albeit much more verbose) by converting the lambda function into a functor: // Some dummy types: struct T1 {int dummy;}; struct T2 {int ...
Introduction: This simple function generates infinite series of numbers. For example... for number in itertools.count(): if number > 20: break print(number) Note that we must break or it prints forever! Output: 0 1 2 3 4 5 6 7 8 9 10 Arguments: count() ta...
There are a couple of ways to delete a column in a DataFrame. import numpy as np import pandas as pd np.random.seed(0) pd.DataFrame(np.random.randn(5, 6), columns=list('ABCDEF')) print(df) # Output: # A B C D E F # 0 -0.895467 0.386902...
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...
Returns a Boolean indicating if the class conform the protocol: [MyClass conformsToProtocol:@protocol(MyProtocol)];
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 ...
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 call itself, like a function recursion: macro_rules! sum { ($base:expr) => { $base }; ($a:expr, $($rest:expr),+) => { $a + sum!($($rest),+) }; } Let's go though the expansion of sum!(1, 2, 3): sum!(1, 2, 3) // ^ ^~~~ // $a $rest => 1 + sum!(2, 3)...
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...
(All of these are unstable, and thus can only be used from a nightly compiler.) log_syntax!() #![feature(log_syntax)] macro_rules! logged_sum { ($base:expr) => { { log_syntax!(base = $base); $base } }; ($a:expr, $($rest:expr),+) => { { log_syntax!(a = $...
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...

Page 131 of 826