Tutorial by Examples: f

Using using System.Text.RegularExpressions; Code static void Main(string[] args) { string input = "Carrot Banana Apple Cherry Clementine Grape"; // Find words that start with uppercase 'C' string pattern = @"\bC\w*\b"; MatchCollection matches = Regex.M...
Converting a time to a string is a pretty common thing to do in Ruby. strftime is the method one would use to convert time to a string. Here are some examples: Time.now.strftime("%Y-%m-d %H:%M:S") #=> "2016-07-27 08:45:42" This can be simplified even further Time.now.str...
By default, the caret ^ metacharacter matches the position before the first character in the string. Given the string "charsequence" applied against the following patterns: /^char/ & /^sequence/, the engine will try to match as follows: /^char/ ^ - charsequence c - charsequ...
You can set a setUp and tearDown function. A setUp function prepares your environment to tests. A tearDown function does a rollback. This is a good option when you can't modify your database and you need to create an object that simulate an object brought of database or need to init a configu...
context.fill() Causes the inside of the Path to be filled according to the current context.fillStyle and the filled Path is visually drawn onto the canvas. Prior to executing context.fill (or context.stroke) the Path exists in memory and is not yet visually drawn on the canvas. Example code usi...
This function executes an AJAX request using the HEAD method allowing us to check whether a file exists in the directory given as an argument. It also enables us to launch a callback for each case (success, failure). function fileExists(dir, successCallback, errorCallback) { var xhttp = new XM...
The Python interpreter compiles code to bytecode before executing it on the Python's virtual machine (see also What is python bytecode?. Here's how to view the bytecode of a Python function import dis def fib(n): if n <= 2: return 1 return fib(n-1) + fib(n-2) # Display the disas...
CPython allows access to the code object for a function object. The __code__object contains the raw bytecode (co_code) of the function as well as other information such as constants and variable names. def fib(n): if n <= 2: return 1 return fib(n-1) + fib(n-2) dir(fib.__code__) de...
This example goes over how to set up CoreNLP from the GitHub repo. The GitHub code has newer features than the official release, but may be unstable. This example will take you through downloading, building, and running a simple command-line invocation of CoreNLP. Prerequisites: Java 8 or newer....
Given this setup code: var dict = new Dictionary<int, string>() { { 1, "First" }, { 2, "Second" }, { 3, "Third" } }; Use the Remove method to remove a key and its associated value. bool wasRemoved = dict.Remove(2); Executing this code remo...
A common use case for a for loop is to iterate over a predefined range or collection, and do the same task for all its elements. For instance, here we combine a for loop with a conditional if-elseif-else statement: for i in 1:100 if i % 15 == 0 println("FizzBuzz") elsei...
In some situations, one might want to return from a function before finishing an entire loop. The return statement can be used for this. function primefactor(n) for i in 2:n if n % i == 0 return i end end @assert false # unreachable end Usage: jul...
The most common conditional in Julia is the if...else expression. For instance, below we implement the Euclidean algorithm for computing the greatest common divisor, using a conditional to handle the base case: mygcd(a, b) = if a == 0 abs(b) else mygcd(b % a, a) end The if...else for...
name = readline() if startswith(name, "A") println("Your name begins with A.") else println("Your name does not begin with A.") end Any expression, such as the if...else expression, can be put in statement position. This ignores its value but still execu...
Like any other expression, the return value of an if...else expression can be ignored (and hence discarded). This is generally only useful when the body of the expression has side effects, such as writing to a file, mutating variables, or printing to the screen. Furthermore, the else branch of an i...
d = Dates.dayofweek(now()) if d == 7 println("It is Sunday!") elseif d == 6 println("It is Saturday!") elseif d == 5 println("Almost the weekend!") else println("Not the weekend yet...") end Any number of elseif branches may be used...
shift(x) = ifelse(x > 10, x + 1, x - 1) Usage: julia> shift(10) 9 julia> shift(11) 12 julia> shift(-1) -2 The ifelse function will evaluate both branches, even the one that is not selected. This can be useful either when the branches have side effects that must be evaluat...
Here is a class (Dog) creating its own dependency (Food): class Dog { public Dog() { var food = new Food(); this.eat(food); } } Here is the same class being injected with its dependency using constructor injection: class Dog { public Dog(Food food) { ...
If you want to change an attribute of a control such as a textbox or label from another thread than the GUI thread that created the control, you will have to invoke it or else you might get an error message stating: "Cross-thread operation not valid: Control 'control_name' accessed from a th...
using System; using System.IO; public class Program { public static void Main() { string filePath = "somePath"; if(File.Exists(filePath)) { Console.WriteLine("Exists"); } else ...

Page 195 of 457