Tutorial by Examples

Extension Method can work on null references, but you can use ?. to null-check anyway. public class Person { public string Name {get; set;} } public static class PersonExtensions { public static int GetNameLength(this Person person) { return person == null ? -1 : pers...
To list all available schemes for the project in your current directory xcodebuild -list Optionally you can pass a path to a project or workspace file xcodebuild -list -workspace ./MyApp.xcworkspace xcodebuild -list -project ./MyApp.xcodeproj Example output Information about project "...
Given a hello.groovy file with content: #!/usr/bin/env groovy println "Hello world" Can be executed from the command line if given execution permission as $ ./hello.groovy
public void MoveToStateAndExecuteActions(Item item, ID workflowStateId) { Sitecore.Workflows.IWorkflowProvider workflowProvider = Item.Database.WorkflowProvider; Sitecore.Workflows.IWorkflow workflow = workflowProvider.GetWorkflow(item); // if item is in any workflow if (workf...
Thanks to this great post If we want to mimic the Sitecore UI behavior and execute the command which will change the workflow state, we need to use WorkflowProvider to get an instance of the workflow assigned to the given item and call Execute method with a chosen command ID. This will fire all the...
Detailed instructions on getting webdriver set up or installed.
An HTTP POST request is sent to a URL of the format: "https://api.twilio.com/2xxx-xx-xx/Accounts/[AccountSid]/Messages.json The example below uses a alphanumeric string as the sender. At the time of writing a sender ID can only be added through a service request Twlio. Example Request: To=&q...
using System; public class Program { public static void Main() { var date = new DateTime(2016,12,31); Console.WriteLine(date.ToString()); //Outputs: 12/31/2016 12:00:00 AM Console.WriteLine(date.ToShortDateString()); //Out...
To get the current date you use the DateTime.Today property. This returns a DateTime object with today's date. When this is then converted .ToString() it is done so in your system's locality by default. For example: Console.WriteLine(DateTime.Today); Writes today's date, in your local format to...
from __future__ import print_function import multiprocessing def countdown(count): while count > 0: print("Count value", count) count -= 1 return if __name__ == "__main__": p1 = multiprocessing.Process(target=countdown, args=(10,)) ...
To get Array from any object, use Kernel#Array. The following is an example: Array('something') #=> ["something"] Array([2, 1, 5]) #=> [2, 1, 5] Array(1) #=> [1] Array(2..4) #=> [2, 3, 4] Array([]) #=> [] Array(nil) #=> [] For...
To calculate moving average of salary of the employers based on their role: val cumSum = sampleData.withColumn("cumulativeSum", sum(sampleData("Salary")) .over( Window.partitionBy("Role").orderBy("Salary"))) orderBy() sorts salary column an...
IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.
std::ifstream src("source_filename", std::ios::binary); std::ofstream dst("dest_filename", std::ios::binary); dst << src.rdbuf(); C++17 With C++17 the standard way to copy a file is including the <filesystem> header and using copy_file: std::fileystem::copy...
The first thing you need to do is create a connection to the database using the connect method. After that, you will need a cursor that will operate with that connection. Use the execute method of the cursor to interact with the database, and every once in a while, commit the changes using the comm...
Sometimes you may want to have local changes in a file you don't want to commit or publish. Ideally local settings should be concentrated in a separate file that can be placed into .gitignore, but sometimes as a short-term solution it can be helpful to have something local in a checked-in file. You...
.gitignore and .git/info/exclude work only for untracked files. To set ignore flag on a tracked file, use the command update-index: git update-index --skip-worktree myfile.c To revert this, use: git update-index --no-skip-worktree myfile.c You can add this snippet to your global git config ...
namespace CodeContractsDemo { using System; using System.Collections.Generic; using System.Diagnostics.Contracts; public class PaymentProcessor { private List<Payment> _payments = new List<Payment>(); public void Add(Payment payment) ...
public double GetPaymentsTotal(string name) { Contract.Ensures(Contract.Result<double>() >= 0); double total = 0.0; foreach (var payment in this._payments) { if (string.Equals(payment.Name, name)) { total += payment.Amount; } } ...
namespace CodeContractsDemo { using System; using System.Diagnostics.Contracts; public class Point { public int X { get; set; } public int Y { get; set; } public Point() { } public Point(int x, int y) { ...

Page 573 of 1336