Tutorial by Examples: arg

Accounts on crates.io are created by logging in with GitHub; you cannot sign up with any other method. To connect your GitHub account to crates.io, click the 'Login with GitHub' button in the top menu bar and authorise crates.io to access your account. This will then log you in to crates.io, assumi...
A question that occasionally on StackOverflow is whether it is appropriate to use assert to validate arguments supplied to a method, or even inputs provided by the user. The simple answer is that it is not appropriate. Better alternatives include: Throwing an IllegalArgumentException using cust...
For example, we have two environments: CI - Staging and want to add some customizations for each environment. Here I will try to customize server URL, app name. First, we create two targets for 2 environments by duplicating the main target: For each target, we will define a custom macro. Here I ...
If a target matches multiple pattern rules, make will use the one whose prerequisites exist or can be built. For example: %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ %.o: %.s $(AS) $(ASFLAGS) $< -o $@ Will compile foo.c to foo.o or assemble foo.s to foo.o, depending on which one of foo...
Pattern rules can have multiple targets but, unlike normal rules, the recipe is responsible for making all the targets. For example: debug/%.o release/%.o: %.c $(CC) $(CFLAGS_DEBUG) -c $< -o debug/$*.o $(CC) $(CFLAGS_RELEASE) -c $< -o release/$*.o Is a valid rule, which will buil...
In many application it is necessary to compute the function of two or more arguments. Traditionally, we use for-loops. For example, if we need to calculate the f = exp(-x^2-y^2) (do not use this if you need fast simulations): % code1 x = -1.2:0.2:1.4; y = -2:0.25:3; for nx=1:lenght(x) for n...
Though Go supports ++ and -- operators and the behaviour is found to be almost similar to c/c++, variables with such operators cannot be passed as argument to function. package main import ( "fmt" ) func abcd(a int, b int) { fmt.Println(a," &...
You can access the command line arguments passed to your program using the std::env::args() function. This returns an Args iterator which you can loop over or collect into a Vec. Iterating Through Arguments use std::env; fn main() { for argument in env::args() { if argument == &qu...
SASS's optional arguments let you use a parameter only if you specify its value; otherwise, it will be ignored. Let's take an example of the following mixin: @mixin galerie-thumbnail ($img-height:14em, $img-width: null) { width: $img-width; height: $img-height; outline: 1px solid li...
type Dog = Dog String dogName1 dog = case dog of Dog name -> name dogName2 (Dog name) -> name dogName1 and dogName2 are equivalent. Note that this only works for ADTs that have a single constructor. type alias Pet = { name: String , weight: Float ...
using NLog; using NLog.Config; using NLog.Targets; namespace MyNamespace { [Target("MyFirst")] public sealed class MyFirstTarget: TargetWithLayout //or inherit from Target { public MyFirstTarget() { //set defaults ...
If you're creating an image, decoding an image, or resizing an image to fit the large notification image area, you can get the correct pixel dimensions like so: Resources resources = context.getResources(); int width = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width)...
To find the largest items in a collection, heapq module has a function called nlargest, we pass it two arguments, the first one is the number of items that we want to retrieve, the second one is the collection name: import heapq numbers = [1, 4, 2, 100, 20, 50, 32, 200, 150, 8] print(heapq.nl...
Some programs need so store arguments for future calling of some function. This example shows how to call any function with arguments stored in std::tuple #include <iostream> #include <functional> #include <tuple> #include <iostream> // simple function to be called d...
For this demonstration we will use service broker construction created in another part of this documentation. Mentioned part is called 3. Create basic service broker construction on database (single database communication). First we need to create a procedure that is able to read and process data f...
import argparse import sys def check(): print("status") return 0 parser = argparse.ArgumentParser(prog="sub", add_help=False) subparser = parser.add_subparsers(dest="cmd") subparser.add_parser('status', help='show status') subparser.add_parser('lis...
Extended version of http://www.riptutorial.com/python/example/25282/argparse--default-help-formatter- that fixed help output. import argparse import sys class CustomHelpFormatter(argparse.HelpFormatter): def _format_action(self, action): if type(action) == argparse._SubParsersActi...
PHP lacks a build-in function to encrypt and decrypt large files. openssl_encrypt can be used to encrypt strings, but loading a huge file into memory is a bad idea. So we have to write a userland function doing that. This example uses the symmetric AES-128-CBC algorithm to encrypt smaller chunks of...
The subprocess method that allows running commands needs the command in form of a list (at least using shell_mode=True). The rules to create the list are not always straightforward to follow, especially with complex commands. Fortunately, there is a very helpful tool that allows doing that: shlex. ...
Sometimes we don't want to load the entire XML file in order to get the information we need. In these instances, being able to incrementally load the relevant sections and then delete them when we are finished is useful. With the iterparse function you can edit the element tree that is stored while ...

Page 10 of 13