Tutorial by Examples: c

Environments in R can be explicitly call and named. Variables can be explicitly assigned and call to or from those environments. A commonly created environment is one which encloses package:base or a subenvironment within package:base. e1 <- new.env(parent = baseenv()) e2 <- new.env(parent ...
The on.exit() function is handy for variable clean up if global variables must be assigned. Some parameters, especially those for graphics, can only be set globally. This small function is common when creating more specialized plots. new_plot <- function(...) { old_pars <- par(m...
Functions and objects in different packages may have the same name. The package loaded later will 'mask' the earlier package and a warning message will be printed. When calling the function by name, the function from the most recently loaded package will be run. The earlier function can be accessed ...
Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript is a new C# script engine. var code = "(1 + 2).ToString()"; var run = await CSharpScript.RunAsync(code, ScriptOptions.Default); var result = (string)run.ReturnValue; Console.WriteLine(result); //output 3 You can compile and run an...
Microsoft.CSharp.CSharpCodeProvider can be used to compile C# classes. var code = @" public class Abc { public string Get() { return ""abc""; } } "; var options = new CompilerParameters(); options.GenerateExecutable = false; options.GenerateInMe...
A package is made up of multiple Python files (or modules), and can even include libraries written in C or C++. Instead of being a single file, it is an entire folder structure which might look like this: Folder package __init__.py dog.py hi.py __init__.py from package.dog import woof fro...
This example shows how Stopwatch can be used to benchmark a block of code. using System; using System.Diagnostics; public class Benchmark : IDisposable { private Stopwatch sw; public Benchmark() { sw = Stopwatch.StartNew(); } public voi...
In order to check whether a value is NaN, isnull() or notnull() functions can be used. In [1]: import numpy as np In [2]: import pandas as pd In [3]: ser = pd.Series([1, 2, np.nan, 4]) In [4]: pd.isnull(ser) Out[4]: 0 False 1 False 2 True 3 False dtype: bool Note that n...
The following command imports CSV files into a MySQL table with the same columns while respecting CSV quoting and escaping rules. load data infile '/tmp/file.csv' into table my_table fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\n' ignore 1...
Create custom class for calling multipart/form-data HttpURLConnection request MultipartUtility.java public class MultipartUtility { private final String boundary; private static final String LINE_FEED = "\r\n"; private HttpURLConnection httpConn; priva...
The awk language does not directly support variables local to functions. It is however easy emulate them by adding extra arguments to functions. It is traditional to prefix these variables by a _ to indicate that they are not actual parameters. We illustrate this technique with the definition of a...
The slice() method returns a copy of a portion of an array. It takes two parameters, arr.slice([begin[, end]]) : begin Zero-based index which is the beginning of extraction. end Zero-based index which is the end of extraction, slicing up to this index but it's not included. If the end is a neg...
// Returns the nth number in the Fibonacci sequence function fibonacci(n) { if (n === 1 || n === 0) { return 1; } else { return fibonacci(n - 1) + fibonacci(n - 2); } }
// Checks a string to see if it is a palindrome bool function IsPalindrome(string input) { if (input.size() <= 1) { return true; } else if (input[0] == input[input.size() - 1]) { return IsPalindrome(input.substr(1,input.size() - 2)); } else { r...
Custom events usually need custom event arguments containing information about the event. For example MouseEventArgs which is used by mouse events like MouseDown or MouseUp events, contains information about Location or Buttons which used to generate the event. When creating new events, to create a...
A cancelable event can be raised by a class when it is about to perform an action that can be canceled, such as the FormClosing event of a Form. To create such event: Create a new event arg deriving from CancelEventArgs and add additional properties for event data. Create an event using EventH...
If you have a list, and you want to use the elements of that list as the arguments to a function, what you want is apply: > (apply string-append (list "hello" " " "and hi" " " "are both words")) "hello and hi are both words" > (app...
; We make single line comments by writing out text after a semicolon
#| We make block comments like this |#
Functions in Racket can be created with the lambda form. The form takes a list of arguments and a body. (lambda (x y) (* x y)) In the example above, the function takes in two arguments and returns the result of multiplying them. > ((lambda (x y) (* x y)) 4 4) 16 > ((lambda (x y) (* x y)...

Page 252 of 826