Tutorial by Examples: arg

Often beginning MATLAB developers will use MATLAB's editor to write and edit code, in particular custom functions with inputs and outputs. There is a Run button at the top that is available in recent versions of MATLAB: Once the developer finishes with the code, they are often tempted to push th...
Let's say we want to change main loop, only for specific taxonomy, or post type. Targeting only main loop on book post type archive page. add_action( 'pre_get_posts', 'my_callback_function' ); function my_callback_function( $query ) { if( !$query->is_main_query() || is_admin() ) return;...
(defn print-some-items [[a b :as xs]] (println a) (println b) (println xs)) (print-some-items [2 3]) This example prints the output 2 3 [2 3] The argument is destructured and the items 2 and 3 are assigned to the symbols a and b. The original argument, the entire vector [2 ...
This basic example counts at different rates on two threads that we name sync (main) and async (new thread). The main thread counts to 15 at 1Hz (1s) while the second counts to 10 at 0.5Hz (2s). Because the main thread finishes earlier, we use pthread_join to make it wait async to finish. #include ...
There are two common ways to encode a POST request body: URL encoding (application/x-www-form-urlencoded) and form data (multipart/form-data). Much of the code is similar, but the way you construct the body data is different. Sending a request using URL encoding Be it you have a server for your s...
Function arguments can be passed "By Reference", allowing the function to modify the variable used outside the function: function pluralize(&$word) { if (substr($word, -1) == 'y') { $word = substr($word, 0, -1) . 'ies'; } else { $word .= 's'; } } $w...
If we need to parse a large file, e.g. a CSV more than 10 Mbytes containing millions of rows, some use file or file_get_contents functions and end up with hitting memory_limit setting with Allowed memory size of XXXXX bytes exhausted error. Consider the following source (top-1m.csv has exactly...
We can wrap a class decorator with another function to allow customization: function addMetadata(metadata: any) { return function log(target: any) { // Add metadata target.__customMetadata = metadata; // Return target return target; ...
To validate arguments to methods called on a mock, use the ArgumentCaptor class. This will allow you to extract the arguments into your test method and perform assertions on them. This example tests a method which updates the name of a user with a given ID. The method loads the user, updates the na...
Ideally, Prolog predicates can be used in all directions. For many pure predicates, this is also actually the case. However, some predicates only work in particular modes, which means instantiation patterns of their arguments. By convention, the most common argument order for such predicates is: ...
Prior to C++17, when writing a template non-type parameter, you had to specify its type first. So a common pattern became writing something like: template <class T, T N> struct integral_constant { using type = T; static constexpr T value = N; }; using five = integral_constant&l...
Mockito provides a Matcher<T> interface along with an abstract ArgumentMatcher<T> class to verify arguments. It uses a different approach to the same use-case than the ArgumentCaptor. Additionally the ArgumentMatcher can be used in mocking too. Both use-cases make use of the Mockito.argT...
For functions that need to take a collection of objects, slices are usually a good choice: fn work_on_bytes(slice: &[u8]) {} Because Vec<T> and arrays [T; N] implement Deref<Target=[T]>, they can be easily coerced to a slice: let vec = Vec::new(); work_on_bytes(&vec); le...
Some procedures have optional arguments. Optional arguments always come after required arguments, but the procedure can be called without them. For example, if the function, ProcedureName were to have two required arguments (argument1, argument2), and one optional argument, optArgument3, it could b...
public string GetCustomerNamesCsv() { List<CustomerData> customerDataRecords = GetCustomerData(); // Returns a large number of records, say, 10000+ StringBuilder customerNamesCsv = new StringBuilder(); foreach (CustomerData record in customerDataRecords) { custom...
It is possible to retarget an event in Polymer ie you can change event details like path thus hiding the actual details of an event/element from user. For e.g if a div inside event-retargeting element is firing the event but developer does not want the user to know that he can retarget the event to...
Lets assume we have this class and we would like to test doSmth method. In this case we want to see if parameter "val" is passed to foo. Object foo is mocked. public class Bar { private final Foo foo; public Bar(final Foo foo) { this.foo = foo; } public ...
You can combine named arguments with optional parameters. Let see this method: public sealed class SmsUtil { public static bool SendMessage(string from, string to, string message, int retryCount = 5, object attachment = null) { // Some code } } When you want to call t...
You can place named arguments in any order you want. Sample Method: public static string Sample(string left, string right) { return string.Join("-",left,right); } Call Sample: Console.WriteLine (Sample(left:"A",right:"B")); Console.WriteLine (Sample(right...
There are some cases in mixins where there can be single or multiple arguments while using it. Let's take a case of border-radius where there can be single argument like border-radius:4px; or multiple arguments like border-radius:4px 3px 2px 1px;. Traditional with Keyword Arguments mixing will be l...

Page 7 of 13