Tutorial by Examples: am

A function can be defined with parameters using the param block: function Write-Greeting { param( [Parameter(Mandatory,Position=0)] [String]$name, [Parameter(Mandatory,Position=1)] [Int]$age ) "Hello $name, you are $age years old." } ...
Parameters to a function can be marked as mandatory function Get-Greeting{ param ( [Parameter(Mandatory=$true)]$name ) "Hello World $name" } If the function is invoked without a value, the command line will prompt for the value: $greeting = Get-Greeting ...
Descriptive names and structure in your code help make comments unnecessary Dim ductWidth As Double Dim ductHeight As Double Dim ductArea As Double ductArea = ductWidth * ductHeight is better than Dim a, w, h a = w * h This is especially helpful when you are copying data from one ...
const auto input = "Some people, when confronted with a problem, think \"I know, I'll use regular expressions.\""s; smatch sm; cout << input << endl; // If input ends in a quotation that contains a word that begins with "reg" and another word begining...
This code takes in various brace styles and converts them to One True Brace Style: const auto input = "if (KnR)\n\tfoo();\nif (spaces) {\n foo();\n}\nif (allman)\n{\n\tfoo();\n}\nif (horstmann)\n{\tfoo();\n}\nif (pico)\n{\tfoo(); }\nif (whitesmiths)\n\t{\n\tfoo();\n\t}\n"s; cout &lt...
A std::regex_token_iterator provides a tremendous tool for extracting elements of a Comma Separated Value file. Aside from the advantages of iteration, this iterator is also able to capture escaped commas where other methods struggle: const auto input = "please split,this,csv, ,line,\\,\n&quot...
When processing of captures has to be done iteratively a regex_iterator is a good choice. Dereferencing a regex_iterator returns a match_result. This is great for conditional captures or captures which have interdependence. Let's say that we want to tokenize some C++ code. Given: enum TOKENS { ...
Subsetting a data frame into a smaller data frame can be accomplished the same as subsetting a list. > df3 <- data.frame(x = 1:3, y = c("a", "b", "c"), stringsAsFactors = FALSE) > df3 ## x y ## 1 1 a ## 2 2 b ## 3 3 c > df3[1] # Subset a varia...
When writing a class with generics in java, it is possible to ensure that the type parameter is an enum. Since all enums extend the Enum class, the following syntax may be used. public class Holder<T extends Enum<T>> { public final T value; public Holder(T init) { t...
/// <summary> /// Returns the data for the specified ID and timestamp. /// </summary> /// <param name="id">The ID for which to get data. </param> /// <param name="time">The DateTime for which to get data. </param> /// <returns>A Data...
<!DOCTYPE html> <html> <head> <meta charset='utf-8' /> <title></title> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> <!-- find the latest library and style versions here: https://www.mapbox.com/m...
While reading content from a file is already asynchronous using the fs.readFile() method, sometimes we want to get the data in a Stream versus in a simple callback. This allows us to pipe this data to other locations or to process it as it comes in versus all at once at the end. const fs = require(...
App.xaml.cs file (App.xaml file is default, so skipped) using Xamrin.Forms namespace NavigationApp { public partial class App : Application { public static INavigation GlobalNavigation { get; private set; } public App() { InitializeComponent()...
Variables of character type or of a derived type with length parameter may have the length parameter either assumed or deferred. The character variable name character(len=len) name is of length len throughout execution. Conversely the length specifier may be either character(len=*) ... ! Ass...
import pandas as pd import numpy as np np.random.seed(123) x = np.random.standard_normal(4) y = range(4) df = pd.DataFrame({'X':x, 'Y':y}) >>> df X Y 0 -1.085631 0 1 0.997345 1 2 0.282978 2 3 -1.506295 3
You can create a DataFrame from a list of simple tuples, and can even choose the specific elements of the tuples you want to use. Here we will create a DataFrame using all of the data in each tuple except for the last element. import pandas as pd data = [ ('p1', 't1', 1, 2), ('p1', 't2', 3, 4)...
The dynamic keyword is used with dynamically typed objects. Objects declared as dynamic forego compile-time static checks, and are instead evaluated at runtime. using System; using System.Dynamic; dynamic info = new ExpandoObject(); info.Id = 123; info.Another = 456; Console.WriteLine(info...
This example will guide you through setting up a back end serving an a Hello World HTML page. Installing Requirements Order matters for this step! sudo apt-get install apache2 Setting up the HTML Apache files live in /var/www/html/. Lets quickly get there. Make sure you're in your root ...
Checking if session cookies have been created Session name is the name of the cookie used to store sessions. You can use this to detect if cookies for a session have been created for the user: if(isset($_COOKIE[session_name()])) { session_start(); } Note that this method is generally not ...
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 ...

Page 18 of 129