Tutorial by Examples: df

Expression-bodied function members allow the use of lambda expressions as member bodies. For simple members, it can result in cleaner and more readable code. Expression-bodied functions can be used for properties, indexers, methods, and operators. Properties public decimal TotalPrice => Base...
It is possible to use await expression to apply await operator to Tasks or Task(Of TResult) in the catch and finally blocks in C#6. It was not possible to use the await expression in the catch and finally blocks in earlier versions due to compiler limitations. C#6 makes awaiting async tasks a lot e...
public delegate int ModifyInt(int input); ModifyInt multiplyByTwo = x => x * 2; The above Lambda expression syntax is equivalent to the following verbose code: public delegate int ModifyInt(int input); ModifyInt multiplyByTwo = delegate(int x){ return x * 2; };
Executors accept a java.lang.Runnable which contains (potentially computationally or otherwise long-running or heavy) code to be run in another Thread. Usage would be: Executor exec = anExecutor; exec.execute(new Runnable() { @Override public void run() { //offloaded work, no need t...
Start by defining a Foo function that we'll use as a constructor. function Foo (){} By editing Foo.prototype, we can define properties and methods that will be shared by all instances of Foo. Foo.prototype.bar = function() { return 'I am bar'; }; We can then create an instance using the ...
The map function is the simplest one among Python built-ins used for functional programming. map() applies a specified function to each element in an iterable: names = ['Fred', 'Wilma', 'Barney'] Python 3.x3.0 map(len, names) # map in Python 3.x is a class; its instances are iterable # Out: &...
Alternatively, you can use the Interactive Ruby Shell (IRB) to immediately execute the Ruby statements you previously wrote in the Ruby file. Start an IRB session by typing: $ irb Then enter the following command: puts "Hello World" This results in the following console output (in...
Decorators normally strip function metadata as they aren't the same. This can cause problems when using meta-programming to dynamically access function metadata. Metadata also includes function's docstrings and its name. functools.wraps makes the decorated function look like the original function b...
Sometimes you don't want to have your function accessible/stored as a variable. You can create an Immediately Invoked Function Expression (IIFE for short). These are essentially self-executing anonymous functions. They have access to the surrounding scope, but the function itself and any internal va...
import random randint() Returns a random integer between x and y (inclusive): random.randint(x, y) For example getting a random number between 1 and 8: random.randint(1, 8) # Out: 8 randrange() random.randrange has the same syntax as range and unlike random.randint, the last value is no...
git diff --staged This will show the changes between the previous commit and the currently staged files. NOTE: You can also use the following commands to accomplish the same thing: git diff --cached Which is just a synonym for --staged or git status -v Which will trigger the verbose sett...
A practical use case of a generator is to iterate through values of an infinite series. Here's an example of finding the first ten terms of the Fibonacci Sequence. def fib(a=0, b=1): """Generator that yields Fibonacci numbers. `a` and `b` are the seed values""" ...
Python provides string interpolation and formatting functionality through the str.format function, introduced in version 2.6 and f-strings introduced in version 3.6. Given the following variables: i = 10 f = 1.5 s = "foo" l = ['a', 1, 2] d = {'a': 1, 2: 'foo'} The following statem...
var a = Math.random(); Sample value of a: 0.21322848065742162 Math.random() returns a random number between 0 (inclusive) and 1 (exclusive) function getRandom() { return Math.random(); } To use Math.random() to get a number from an arbitrary range (not [0,1)) use this function to get a...
git rm filename To delete the file from git without removing it from disk, use the --cached flag git rm --cached filename
Extensions can contain functions and computed/constant get variables. They are in the format extension ExtensionOf { //new functions and get-variables } To reference the instance of the extended object, self can be used, just as it could be used To create an extension of String that adds ...
Struct fields whose names begin with an uppercase letter are exported. All other names are unexported. type Account struct { UserID int // exported accessToken string // unexported } Unexported fields can only be accessed by code within the same package. As such, if you are ev...
curl -X POST https://api.dropboxapi.com/2/sharing/add_folder_member \ --header "Authorization: Bearer <ACCESS_TOKEN>" \ --header "Content-Type: application/json" \ --data "{\"shared_folder_id\": \"<SHARED_FOLDER_ID\",\"members...
let toInvite = [Sharing.AddMember(member: Sharing.MemberSelector.Email("<EMAIL_ADDRESS_TO_INVITE>"))] Dropbox.authorizedClient!.sharing.addFolderMember(sharedFolderId: "<SHARED_FOLDER_ID>", members: toInvite).response { response, error in if (response != nil...
Dropbox.authorizedClient!.files.listFolder(path: "").response { response, error in print("*** List folder ***") if let result = response { print("Folder contents:") for entry in result.entries { print(entry.name) if ...

Page 1 of 21